xcode 新 UI 的 iOS 故事板本地化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20700661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:27:35  来源:igfitidea点击:

iOS storyboard localization for new UI

iosxcodelocalizationstoryboard

提问by bohan

I use Xcode 5 in a project. and the project need to localization. Xcode had help me generated Localizable.stringsit looks like

我在一个项目中使用 Xcode 5。并且项目需要本地化。Xcode 帮助我生成了Localizable.strings它看起来像

/* Class = "IBUIButton"; normalTitle = "2013-10-1"; ObjectID = "p5u-h7-pfJ"; */
"p5u-h7-pfJ.normalTitle" = "2013-10-1";

/* Class = "IBUILabel"; text = "Label"; ObjectID = "pBS-eN-YUz"; */
"pBS-eN-YUz.text" = "Label";

/* Class = "IBUITextField"; placeholder = "Input Name Here"; ObjectID = "pE4-WG-fPp"; */
"pE4-WG-fPp.placeholder" = "Input Name Here";

/* Class = "IBUILabel"; text = "Detail"; ObjectID = "qSu-Mo-baT"; */
"qSu-Mo-baT.text" = "Detail";

but how should I do if I want to add new UI in the storyboard. How can I add new key-value?

但是如果我想在故事板中添加新的 UI 该怎么办。如何添加新的键值?

回答by zbMax

In your storyboard, every single Object has an ID. In the 'Utilities' view, 'Identity Inspector' thumb, 'Document' section, there is a field 'Object ID'

在故事板中,每个对象都有一个 ID。在“实用工具”视图、“身份检查器”拇指、“文档”部分,有一个字段“对象 ID”

I've never used this, but I guess that, if you have a label with ID 141-wB-KQDand you want to set its text property, you have to put in your Localizable.strings:

我从来没有用过这个,但我想,如果你有一个带有 ID 的标签141-wB-KQD并且你想设置它的 text 属性,你必须输入你的Localizable.strings

"141-wB-KQD.text" = "the value you want";

回答by Nikolay Mamaev

  1. Make backup copies of a storyboard's .strings file for a locale that needs to be updated.

  2. Select storyboard in the Project Navigator (in the left Xcode's pane), open File Inspector (right pane) and unmark checkbox for that locale.

  3. In the 'Do you want to remove...' alert appeared, check 'Delete localized resource files from disk' checkbox and press 'Remove' button.

  4. Mark back the same checkbox; this will generate localized resource file for the locale; it will contain entries for all objects including newly added but its contents will not be localized at all.

  5. Merge this newly generated file with saved backup - this will restore all localizations you've done before.

  6. Localize new objects.

  1. 为需要更新的语言环境制作故事板的 .strings 文件的备份副本。

  2. 在 Project Navigator(在左侧 Xcode 的窗格中)中选择 storyboard,打开 File Inspector(右侧窗格)并取消选中该区域设置的复选框。

  3. 在出现“是否要删除...”警报中,选中“从磁盘删除本地化资源文件”复选框,然后按“删除”按钮。

  4. 标记回相同的复选框;这将为语言环境生成本地化的资源文件;它将包含所有对象的条目,包括新添加的对象,但其内容根本不会本地化。

  5. 将这个新生成的文件与保存的备份合并 - 这将恢复您之前完成的所有本地化。

  6. 本地化新对象。

回答by user1459524

Not sure if this is the "right" way or the best way, but here is what I do:

不确定这是“正确”的方式还是最好的方式,但这是我所做的:

1) make any localizations LAST. In other words, first try to make sure that you do NOT need any changes made to the base storyboard. This may sound like a cop out but really, it's the best way to avoid hassles.

1) 最后进行任何本地化。换句话说,首先尝试确保您不需要对基本故事板进行任何更改。这听起来像是逃避,但实际上,这是避免麻烦的最佳方式。

2) since that isn't always how things turn out, if you DO need to make changes, you can push them out to the localized files by changing them from "strings" to "storyboard" and then back. This will preserve your existing translations and work in any new stuff automatically, and as such it's better than outright deleting the localized files from the bundle.

2) 由于事情并非总是如此,如果您确实需要进行更改,您可以通过将它们从“字符串”更改为“故事板”然后再返回来将它们推送到本地化文件中。这将保留您现有的翻译并自动处理任何新内容,因此比从捆绑包中彻底删除本地化文件要好。

I noticed that this may leave some redundant strings in the localized file from time to time, and sometimes you have to delete them manually or it won't compile correctly, but if there is any better way to do this, I'd like to know myself.

我注意到这可能会不时在本地化文件中留下一些多余的字符串,有时您必须手动删除它们,否则将无法正确编译,但是如果有更好的方法可以做到这一点,我想认识我自己。

回答by Javier Cancio

If you want to localize your project views, just go to the storyboard click on the view controller, then go to File Inspector and click on Localize... you'll have one storyboard file for each language.

如果您想本地化您的项目视图,只需转到情节提要单击视图控制器,然后转到文件检查器并单击本地化...每种语言都有一个情节提要文件。