如何在 Xcode 4 中更改 Localizable.strings 文件的文本编码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7079930/
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
How to change text encoding of Localizable.strings file in Xcode 4?
提问by Sabobin
I am learning how to localize the strings in my project and I am using Xcode 4.
我正在学习如何本地化我的项目中的字符串,我正在使用 Xcode 4。
I have generated the base Localizable.strings file, and I want to import this file, changing its encoding from utf-16 to Unicode utf-16 so that the text in the file is readable within xCode. If I strate import this file, when I select it within xcode, the text shows up as gibberish.
我已经生成了基本的 Localizable.strings 文件,我想导入这个文件,将其编码从 utf-16 更改为 Unicode utf-16,以便文件中的文本在 xCode 中可读。如果我导入这个文件,当我在 xcode 中选择它时,文本显示为乱码。
In Xcode 3 when you drag the Localizable.strings into your project, the dialog box which appears gives you the option to change the text encoding, but this is not the case in Xcode 4.
在 Xcode 3 中,当您将 Localizable.strings 拖到项目中时,出现的对话框会为您提供更改文本编码的选项,但在 Xcode 4 中并非如此。
Does anyone know a way around this?
有谁知道解决这个问题的方法?
回答by Edmar Miyake
Maybe this can help you Objective C/Xcode 4: Encoding Problem with Localizable.strings files
也许这可以帮助你Objective C/Xcode 4: Encoding Problem with Localizable.strings files
These kind of errors can happen if you copy and paste content within Xcode or from external files in your localization files. The consequence is that the encoding of the file changes to for example Western (Mac OS Roman). The Localizable.strings file should be in UTF-16 though.
如果您在 Xcode 中或从本地化文件中的外部文件复制和粘贴内容,可能会发生此类错误。结果是文件的编码更改为例如西方(Mac OS Roman)。不过,Localizable.strings 文件应该是 UTF-16。
Solution
解决方案
1. Like in the picture below, navigate in Xcode to the Localizable.strings location and open it so that you can see all the languages you are supporting.
1. 如下图所示,在 Xcode 中导航到 Localizable.strings 位置并打开它,以便您可以看到您支持的所有语言。
Left-click on the language file the causes the build error.
Make sure your Utilities View is showing in Xcode. Activate on the button at mark 1 in Picture below.
左键单击导致构建错误的语言文件。
确保您的实用程序视图显示在 Xcode 中。激活下图中标记 1 处的按钮。
In the Utilities View select the File Inspector. (Small Logo that looks like Page)
Under Text Settings change the encoding to UTF-16(Marked as 2 in the picture above). The Drop-Down might be grayed out but you can click on it anyways. Click on "Convert" on the Popup.
在实用程序视图中选择文件检查器。(看起来像 Page 的小标志)
在 Text Settings 下,将编码更改为 UTF-16(在上图中标记为 2)。下拉菜单可能会变灰,但您仍然可以单击它。单击弹出窗口中的“转换”。
That's it your project should now compile again.
就是这样,您的项目现在应该再次编译。
回答by Brandon O'Rourke
The "Text Settings" for my Localizable.strings files don't have the option of changing the encoding like XCode 3. However, I found if I simply restart Xcode 4, it reinterprets it correctly (UTF-16).
我的 Localizable.strings 文件的“文本设置”没有像 XCode 3 那样更改编码的选项。但是,我发现如果我只是重新启动 Xcode 4,它会正确地重新解释它 (UTF-16)。
回答by hoist1999
After changing the encoding, and re-executing the genstrings
command to regenerate the localize string, things should work.
更改编码并重新执行genstrings
命令以重新生成本地化字符串后,事情应该可以正常工作了。
回答by Rafael Bugajewski
Sometimes Xcode displays the warning, even if the file contents are UTF-16, but the file is somehow interpreted as UTF-8. iconv usually says that it can't convert the file in this case. Converting the file in Xcode to UTF-8 and then converting it back again to UTF-16, like Edmar suggested, solves this problem. The warnings are gone.
有时 Xcode 会显示警告,即使文件内容是 UTF-16,但文件以某种方式被解释为 UTF-8。iconv 通常说在这种情况下它不能转换文件。将 Xcode 中的文件转换为 UTF-8,然后再将其转换回 UTF-16,就像 Edmar 建议的那样,解决了这个问题。警告消失了。
To make sure that nothing got broken during the conversion, recheck the whole strings file.
为确保在转换过程中没有任何损坏,请重新检查整个字符串文件。
回答by Richard
View -> Utilities -> Show File Inspector
Change Text Encoding in the file inspector utility view.
查看 -> 实用程序 -> 显示文件检查器
在文件检查器实用程序视图中更改文本编码。