xcode 基本本地化 + Storyboard + .strings -> 无本地化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15094086/
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 02:51:26  来源:igfitidea点击:

Base localization + Storyboard + .strings -> no localization

iosobjective-cxcodelocalization

提问by

Xcode 4.6, target iOS 6, SDK iOS 6.1

Xcode 4.6,目标 iOS 6,SDK iOS 6.1

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.
  • Added a French localization, which cloned InfoPlist.strings (English) and MainStoryboard.storyboard (Base) into fr.lproj.
  • Changed a couple of strings (titles of segments in a UISegmentedControl) in the French MainStoryboard.storyboard.
  • In the Simulator, set the language to French.
  • Ran the app from Xcode.
  • 添加了基本本地化,将 MainStoryboard.storyboard 从 en.lproj 转移到 Base.lproj。
  • 添加了法语本地化,将 InfoPlist.strings(英语)和 MainStoryboard.storyboard(基础)克隆到 fr.lproj。
  • 在法语 MainStoryboard.storyboard 中更改了几个字符串(UISegmentedControl 中的段标题)。
  • 在模拟器中,将语言设置为法语。
  • 从 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.
  • In the File inspector, under Localization, changed the French localization from "Interface Builder Cocoa Touch Storyboard" to "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.
  • 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.
  • Deleted the existing (working) copy of the app from the simulator.
  • Ran the app.
  • 在 Xcode 项目导航器中选择基础 MainStoryboard.storyboard。
  • 在文件检查器的本地化下,将法语本地化从“Interface Builder Cocoa Touch Storyboard”更改为“Localizable Strings”。
  • 接受 Xcode 的警告,即法语故事板将被丢弃,以支持出现在助手编辑器中的 .strings 文件。
  • 进行了相同的两次编辑;毫无疑问,它们是错误的字符串,因为它们都被注释为 IBUISegmentedControl...segmentTitles;并且标签文本不会出现在 .strings 文件中的其他任何地方。
  • 从模拟器中删除了应用程序的现有(工作)副本。
  • 运行应用程序。

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

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

Converting to Autolayout had no effect. Deleting the app from the simulator had no effect. Deleting the Derived Products directory had no effect. A Stack Overflow suggested using ibtool to generate the .strings file instead of Xcode; the two generated files are identical.

转换为自动布局没有效果。从模拟器中删除应用程序没有任何效果。删除派生产品目录没有效果。Stack Overflow 建议使用 ibtool 生成 .strings 文件而不是 Xcode;两个生成的文件是相同的。

This isn't satisfactory. 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 文件的故事板本地化?

采纳答案by Chiara Gandolfi

I hope you have already solved. I had the same problem (with translation in Italian) and I solved it this way:

我希望你已经解决了。我遇到了同样的问题(用意大利语翻译),我是这样解决的:

1) File Localizable.string in it.lproj

1) it.lproj 中的文件 Localizable.string

2) use NSLocalizedString (@ "TEST", @ "comment") method where it needs

2) 在需要的地方使用 NSLocalizedString (@"TEST", @"comment") 方法

3) add Localizable.string in Build Phases-> Copy Bundle Resource The last step is not neccesary in iOS 5.1.

3) 在 Build Phases-> Copy Bundle Resource 中添加 Localizable.string 在 iOS 5.1 中不需要最后一步。

I solved thanks to the response of Cocoanetics in [question]:Base internationalization and multiple storyboard not working right

感谢 Cocoanetics 在 [问题] 中的回应,我解决了:基本国际化和多故事板无法正常工作

回答by claymation

Enable the English localization checkbox, using the Localization Strings setting:

启用英语本地化复选框,使用本地化字符串设置:

Localization settings

本地化设置

Clean your build folder (???K) and rebuild.

清理您的构建文件夹 (???K) 并重建。

回答by Richard Shin

To add onto claymation's answer about doing a clean build, it also helps to delete the app from the iOS Simulator.

要添加到 claymation 关于进行干净构建的答案,它还有助于从 iOS 模拟器中删除该应用程序。

It may be related to what John Hess's answer describes.

这可能与John Hess 的回答所描述的有关

回答by raeldor

Had to convert my strings file into a storyboard then back into a strings file to get this to work. Ridiculous. Apple could learn a thing or two from Microsoft about creating more reliable developer tools.

必须将我的字符串文件转换为故事板,然后再转换回字符串文件才能使其正常工作。荒谬的。Apple 可以从 Microsoft 那里学到一两件事,以创建更可靠的开发人员工具。