故事板+基本本地化+ .strings文件在运行时不会本地化

时间:2022-02-10 12:13:24

(There are similar questions. Some resulted in answers that I've tried and found not to work. Others got no answers, I assume because the querents didn't supply as much detail as I'm about to.)

(也有类似的问题。有些问题得到了答案,我已经尝试过并发现不起作用。其他人没有得到答案,我认为是因为这些问题并没有像我那样提供足够多的细节。)

I started with a storyboard that worked well for my app; the strings it contains are in English. I wanted to add a French localization. I did this:

我开始使用一个适用于我的应用程序的故事板;它包含的字符串是英文的。我想添加法语本地化。我这样做了:

  • Added a base localization, which transferred MainStoryboard.storyboard from en.lproj to Base.lproj.
  • 添加了一个基本本地化,它将MainStoryboard.storyboard从en.lproj转移到Base.lproj。

  • Added a French localization, which cloned InfoPlist.strings (English) and MainStoryboard.storyboard (Base) into fr.lproj.
  • 添加了法语本地化,将InfoPlist.strings(英语)和MainStoryboard.storyboard(Base)克隆到fr.lproj中。

  • Changed a couple of strings (titles of segments in a UISegmentedControl) in the French MainStoryboard.storyboard.
  • 在法语MainStoryboard.storyboard中更改了几个字符串(UISegmentedControl中段的标题)。

  • In the Simulator, set the language to French.
  • 在模拟器中,将语言设置为法语。

  • Ran the app from Xcode.
  • 从Xcode跑出应用程序。

Result: This worked; my changed strings showed up in the running application.

结果:这有效;我更改的字符串出现在正在运行的应用程序中

But I want to be all fancy. I want to do the French localization using a .strings file. (It's not just a matter of being fancy; the French localization will be turned over to nontechnical translators, who can't be expected to master Interface Builder.) So:

但我想成为所有人。我想使用.strings文件进行法语本地化。 (这不仅仅是一种幻想;法语本地化将转交给非技术翻译人员,他们不能指望他们掌握Interface Builder。)所以:

  • Selected the base MainStoryboard.storyboard in the Xcode Project navigator.
  • 在Xcode项目导航器中选择了基本MainStoryboard.storyboard。

  • In the File inspector, under Localization, changed the French localization from "Interface Builder Cocoa Touch Storyboard" to "Localizable Strings."
  • 在“文件”检查器中的“本地化”下,将“法语本地化”从“Interface Builder Cocoa Touch Storyboard”更改为“Localizable Strings”。

  • Accepted Xcode's warning that the French storyboard will be discarded in favor of a .strings file, which appears in the Assistant editor.
  • 接受Xcode的警告,法国故事板将被丢弃,转而使用.strings文件,该文件出现在助理编辑器中。

  • Made the same two edits; there's no question of their being the wrong strings, because they're all commented as IBUISegmentedControl...segmentTitles; and the label text doesn't appear anywhere else in the .strings file.
  • 做了两个相同的编辑;毫无疑问他们是错误的字符串,因为他们都被评为IBUISegmentedControl ... segmentTitles;并且标签文本不会出现在.strings文件中的任何其他位置。

  • Deleted the existing (working) copy of the app from the simulator.
  • 从模拟器中删除了应用程序的现有(工作)副本。

  • Ran the app.
  • 跑了应用程序。

Result: The view uses the base (originally English) localization, instead of loading the French strings.

结果:视图使用基本(原始英语)本地化,而不是加载法语字符串。

This isn't satisfactory. I've tried deleting the app from the simulator, and even deleting the derived-data folder. The bug persists.

这不太令人满意。我试过从模拟器中删除应用程序,甚至删除derived-data文件夹。这个bug仍然存在。

As I said, I can't turn a .storyboard file over to a nontechnical translator. How can I get iOS to accept the storyboard localizations from a .strings file?

正如我所说,我无法将.storyboard文件转换为非技术翻译。如何让iOS接受.strings文件中的故事板本地化?

3 个解决方案

#1


6  

I had the same problem with my UISegmentedControls. It turns out that there is a bug in iOS 6: .strings storyboard localization won't work on UISegmentedControl text and on UISearchBar placeholders. See this openradar: http://openradar.appspot.com/radar?id=2159402

我的UISegmentedControls遇到了同样的问题。事实证明,iOS 6中存在一个错误:.strings故事板本地化不适用于UISegmentedControl文本和UISearchBar占位符。请参阅此openradar:http://openradar.appspot.com/radar?id = 2159402

Have you tried localizing other elements such as UILabels? That should work.

您是否尝试过本地化其他元素,例如UILabels?这应该工作。

#2


8  

Here is how I solved it:

这是我解决它的方式:

in viewDidLoad:

[self.segmentedControl setTitle:NSLocalizedString(@"Title", @"Your localize comment") forSegmentAtIndex:0];

You can do the same for the search placeholder:

您可以对搜索占位符执行相同操作:

[self.searchBar setPlaceholder:NSLocalizedString(@"Your string placeholder", @"Your comment for localizers")];

Then just create a Localizable.strings file and it will work.

然后只需创建一个Localizable.strings文件,它就可以了。

#3


0  

For people developing for iOS 7 or higher and searching for the .strings format for a search bar, this is how you should translate the placeholder field for example:

对于为iOS 7或更高版本开发并搜索搜索栏的.strings格式的人,您应该如何翻译占位符字段,例如:

/* Class = "UISearchBar"; normalTitle = "Search for Places"; ObjectID = "F3d-Ir-fni"; */
"F3d-Ir-fni.placeholder" = "Nach Orten suchen";

#1


6  

I had the same problem with my UISegmentedControls. It turns out that there is a bug in iOS 6: .strings storyboard localization won't work on UISegmentedControl text and on UISearchBar placeholders. See this openradar: http://openradar.appspot.com/radar?id=2159402

我的UISegmentedControls遇到了同样的问题。事实证明,iOS 6中存在一个错误:.strings故事板本地化不适用于UISegmentedControl文本和UISearchBar占位符。请参阅此openradar:http://openradar.appspot.com/radar?id = 2159402

Have you tried localizing other elements such as UILabels? That should work.

您是否尝试过本地化其他元素,例如UILabels?这应该工作。

#2


8  

Here is how I solved it:

这是我解决它的方式:

in viewDidLoad:

[self.segmentedControl setTitle:NSLocalizedString(@"Title", @"Your localize comment") forSegmentAtIndex:0];

You can do the same for the search placeholder:

您可以对搜索占位符执行相同操作:

[self.searchBar setPlaceholder:NSLocalizedString(@"Your string placeholder", @"Your comment for localizers")];

Then just create a Localizable.strings file and it will work.

然后只需创建一个Localizable.strings文件,它就可以了。

#3


0  

For people developing for iOS 7 or higher and searching for the .strings format for a search bar, this is how you should translate the placeholder field for example:

对于为iOS 7或更高版本开发并搜索搜索栏的.strings格式的人,您应该如何翻译占位符字段,例如:

/* Class = "UISearchBar"; normalTitle = "Search for Places"; ObjectID = "F3d-Ir-fni"; */
"F3d-Ir-fni.placeholder" = "Nach Orten suchen";