向现有 Xcode 项目本地化添加新语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2834470/
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
Add new language to existing Xcode project localization
提问by leolobato
I'm working on an existing Xcode 3.2.2 Universal iPhone OS project which is already localized for 4 languages (EN, IT, DE and FR). We are now adding a new language (JA) into this project.
我正在开发一个现有的 Xcode 3.2.2 Universal iPhone OS 项目,该项目已经针对 4 种语言(EN、IT、DE 和 FR)进行了本地化。我们现在正在向这个项目中添加一种新语言 (JA)。
Each existing .lproj
folder (en.lproj
, it.lproj
, de.lproj
and fr.lproj
) has almost 60 files - including PNGs, HTMLs and the Localizable.strings file. Each one of those files appear as localized groups inside Groups & Files in Xcode. They're spread all over the tree.
每个现有的.lproj
文件夹(en.lproj
,it.lproj
,de.lproj
和fr.lproj
)有近60文件-包括PNG图像,HTMLS和Localizable.strings文件。这些文件中的每一个都在 Xcode 的 Groups & Files 中显示为本地化组。它们遍布整棵树。
If I right-click one of those groups (say, Localizable.strings
) inside Xcode, Get Info, click on "Add Localization" and type "ja
" - as the Xcode docs suggest, nothing happens. From what I read in this newgroup, it's possibly because of the way those folders are named. If they were named like English.lproj
and Italian.lproj
, this was supposed to work.
如果我Localizable.strings
在 Xcode 中右键单击这些组之一(例如),获取信息,单击“添加本地化”并键入“ ja
” - 正如 Xcode 文档所建议的那样,没有任何反应。从我在这个 newgroup 中读到的,这可能是因为这些文件夹的命名方式。如果它们被命名为English.lproj
and Italian.lproj
,这应该可以工作。
So, for me to actually import a new language localized file into the existing group, I have to:
因此,要真正将新语言本地化文件导入现有组,我必须:
- Right-click the localized group file.
- Choose "Add Existing File".
- Select the corresponding file inside the
ja.lproj
folder.
- 右键单击本地化的组文件。
- 选择“添加现有文件”。
- 选择文件
ja.lproj
夹内对应的文件。
I'm about to get a new ja.lproj
folder with those 60 localized files and would love to import them in the project in a way that doesn't involve searching for every single file in Groups & Trees and performing those steps... for every one of those 60 files.
我即将获得一个ja.lproj
包含这 60 个本地化文件的新文件夹,并希望以一种不涉及搜索 Groups & Trees 中的每个文件并执行这些步骤的方式将它们导入项目中......对每个文件在这 60 个文件中。
Is that possible? Is there a right (or better) way to import a new language into this Xcode project?
那可能吗?是否有正确(或更好)的方法将新语言导入到这个 Xcode 项目中?
回答by zoran
I found one simple solution. After you right click any multi lingual resource file and choose |Add|Existing Files...| you can select at once all files you wish to add. After you choose the encoding, xCode will automatically add all files under the resources they should be in. I hope this will work for you.
我找到了一个简单的解决方案。右键单击任何多语言资源文件并选择|添加|现有文件...| 后。您可以一次选择要添加的所有文件。选择编码后,xCode 会自动将所有文件添加到它们应该位于的资源下。我希望这对你有用。
回答by OhadM
In Xcode 7+ it's pretty simple:
在 Xcode 7+ 中,它非常简单:
- Choose your localizable.strings file and tap on "Localize...":
- 选择您的 localizable.strings 文件并点击“Localize...”:
Next window will ask you if you want the current localizable.strings file should be the default language, in my case English should be the default so I chose 'Base'
Choose your project from the navigation bar, choose your project again, switch to 'Info' and tap the '+' button below the Localizations title:
下一个窗口将询问您是否希望当前的 localizable.strings 文件应该是默认语言,在我的情况下,英语应该是默认语言,所以我选择了“Base”
从导航栏中选择您的项目,再次选择您的项目,切换到“信息”并点击“本地化”标题下方的“+”按钮:
- All you have to do now is to choose the langauge you want to translate and mark ONLY the Localizable.strings file:
- 您现在要做的就是选择要翻译的语言并仅标记 Localizable.strings 文件:
- Now it will be added to the Localizble.strings file and the actual string that will be shown to the user will be according to his OS language (As long as you have NSLocalizedString all over your app):
- 现在它将被添加到 Localizble.strings 文件中,并且将显示给用户的实际字符串将根据他的操作系统语言(只要你的应用程序中都有 NSLocalizedString ):
回答by Charmgene
This is what I found works:
这是我发现的作品:
- click add localization;
- replace all the files in the new .lproj folder with localized files;
- delete the localization, and choose "keeping files";
- done.
- 点击添加本地化;
- 用本地化文件替换新 .lproj 文件夹中的所有文件;
- 删除本地化,选择“保留文件”;
- 完毕。
回答by mipadi
The mailing list post basically sums up the issue: Xcode expects to find language bundles with names like "English.lproj", "Italian.lproj", etc. If you change those names, Xcode looses the ability to treat them as language bundles, and then you have to add files using the method you described. There's nothing wrong with how you're adding them to the project, that's just how Xcode works.
邮件列表帖子基本上总结了这个问题:Xcode 希望找到名称为“English.lproj”、“Italian.lproj”等的语言包。如果您更改这些名称,Xcode 将失去将它们视为语言包的能力,然后您必须使用您描述的方法添加文件。您将它们添加到项目中的方式并没有错,这就是 Xcode 的工作方式。