Localizable.strings 在 iOS 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11194911/
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
Localizable.strings not working in iOS
提问by jbssm
I'm having this really mind breaking problem.
我遇到了这个非常令人头痛的问题。
I created a Localizable.strings file in XCode and then 2 languages in it.
我在 XCode 中创建了一个 Localizable.strings 文件,然后在其中创建了 2 种语言。
I filled up these files with the language translations, did a build/clean and then a fresh build, but there is no way the Localization strings show up in my project. If I try something like:
我用语言翻译填充了这些文件,进行了构建/清理,然后进行了全新构建,但是本地化字符串无法显示在我的项目中。如果我尝试类似的事情:
self.title = NSLocalizedString(@"HEAD", nil);
only "HEAD" instead of the translation shows up in the device simulator.
设备模拟器中只显示“HEAD”而不是翻译。
This is my project hierarchy:
这是我的项目层次结构:
And this are the content of the English localization file:
这是英文本地化文件的内容:
Any ideas?
有任何想法吗?
回答by jbssm
I found the answer myself.
我自己找到了答案。
Besides cleaning and building the project again and all that I described above. You must also delete the app in the iPhone simulator and then build it again!After that it works perfectly.
除了清理和重新构建项目以及我上面描述的所有内容。您还必须删除 iPhone 模拟器中的应用程序,然后重新构建它!之后它完美地工作。
Talk about making it simple Apple...
谈论让苹果变得简单...
回答by Javier Calatrava Llavería
Be sure that:
请确保:
- The file is called: "Localizable.strings".
- "Localizable.strings" belongs to the target you are dealing with.
- 该文件名为:“Localizable.strings”。
- “Localizable.strings”属于您正在处理的目标。
回答by samwize
A few checks:
一些检查:
- Make sure the filename is exactly
Localizable.strings
and is included in the target - Every string is ended with
;
- Every string is double quoted with
"
- Comments begins with
//
(NOT#
)
- 确保文件名准确
Localizable.strings
并包含在目标中 - 每个字符串都以
;
- 每个字符串都用双引号引起来
"
- 注释以
//
(NOT#
)开头
回答by irmu
Make sure you have Localizable.strings under Build Phases, Copy Bundle Resources.
确保在 Build Phases、Copy Bundle Resources 下有 Localizable.strings。
回答by Adobels
Check the file name if the first letter is Uppercase Localizable.strings
检查文件名是否首字母为大写 Localizable.strings
回答by yonix
@jbssm's solution works, but a better way (making sure the resource will keep updating without cleaning and deleting each time) will be to add a custom script build phase that changes the access time of the Localizable.bundle.
@jbssm 的解决方案有效,但更好的方法(确保资源将不断更新而无需每次清理和删除)是添加自定义脚本构建阶段,以更改 Localizable.bundle 的访问时间。
As described in https://stackoverflow.com/a/19274844/414037
回答by Hrushikesh Betai
I found 1 answer myself.
我自己找到了 1 个答案。
Make sure that all the values have end point with ; Otherwise,its not work..
确保所有值都以 ; 结尾。否则,它不起作用..
回答by Aron
Besides all the tips mentioned elsewhere in this thread, Localizable.strings
also has to be located in the project root folder in certain cases.
除了本线程中其他地方提到的所有提示外,Localizable.strings
在某些情况下还必须位于项目根文件夹中。
回答by Chuck Boris
回答by slobodans
I want to warn on one more possible problem related to UIButton, who can look like localization is not working.
我想就另一个与 UIButton 相关的可能问题发出警告,该问题看起来像是本地化不起作用。
In order to set text on UIButton use:
为了在 UIButton 上设置文本,请使用:
setTitle(_ title: String?, for state: UIControl.State)
Instead of:
代替:
button.titleLabel?.text