如何将本地化的 .strings 文件添加回 Xcode?

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

How to add localized .strings files back to Xcode?

iphonexcodecocoa-touchlocalization

提问by memmons

I have a .strings file that is localized in a number of languages. I'd like to add it to my Xcode project. How do you get Xcode to correctly reference the files? I've tried

我有一个以多种语言本地化的 .strings 文件。我想将它添加到我的 Xcode 项目中。你如何让 Xcode 正确引用文件?我试过了

  • dragging the english version of the .strings file (found in English.lproj) to Xcode and hoping it would automatically pick up the other localized versions of the file -- it doesn't.
  • dragging all 5 localized versions of the .strings file (found in English.lproj, es.lproj, etc.) assuming Xcode would create a single file reference with the various localized versions -- it crashes.
  • dragging each of the .lproj folders to Xcode hoping it would figure out that the file in each of the folders is all the same file, but localized -- nope
  • dragging the English version of the localized .strings file to Xcode, then add a localization that already exists -- Xcode warns that it will overwrite the file, but doesn't give the option to use the existing file.
  • 将 .strings 文件的英文版本(在 English.lproj 中找到)拖到 Xcode 中,并希望它会自动获取该文件的其他本地化版本——它没有。
  • 拖动 .strings 文件的所有 5 个本地化版本(在 English.lproj、es.lproj 等中找到),假设 Xcode 将创建具有各种本地化版本的单个文件引用 - 它会崩溃。
  • 将每个 .lproj 文件夹拖到 Xcode 中,希望它能找出每个文件夹中的文件都是相同的文件,但已本地化 - 不
  • 将本地化的 .strings 文件的英文版本拖到 Xcode,然后添加一个已经存在的本地化 - Xcode 警告它将覆盖该文件,但不提供使用现有文件的选项。

UPDATE:Submitted a bug report to Apple: #10181468.

更新:向 Apple 提交了错误报告:#10181468。

回答by Max Desiatov

The simplest way as of Xcode 4.6 is to drag localization file (.strings file, not the folder it's located inside of) from Finder to the Xcode project tree. Be accurate and drag to the top of .strings group, not to the bottom or inside of the group as the latter makes Xcode crash.

从 Xcode 4.6 开始,最简单的方法是将本地化文件(.strings 文件,而不是它所在的文件夹)从 Finder 拖到 Xcode 项目树中。准确并拖到 .strings 组的顶部,而不是拖到组的底部或内部,因为后者会使 Xcode 崩溃。

回答by Johnmph

Add the original file (only the file, not the .lproj folder) then make it localizable, add all languages you want, xcode will create .lproj folders and duplicate your original file for each language.

添加原始文件(仅文件,而不是 .lproj 文件夹)然后使其可本地化,添加您想要的所有语言,xcode 将创建 .lproj 文件夹并为每种语言复制您的原始文件。

After you can overwrite each file duplicated by your already translated file (either the file if it have the same name or content).

在您可以覆盖已翻译文件(如果文件具有相同名称或内容的文件)复制的每个文件之后。

Don't forget to set the format of the original file to UTF-16 when you add it.

添加时不要忘记将原始文件的格式设置为UTF-16。