Xcode:使用指定的本地化运行项目

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

Xcode: Run project with specified localization

objective-cxcodecocoalocalizationxib

提问by Oneiros


My Cocoa project is localized in Italian (my language) and English language.
If I run it, i see everything in Italian (of course, my OS is italian!).
How can I run it to test the English localization without changing the OS language?


我的 Cocoa 项目已本地化为意大利语(我的语言)和英语。
如果我运行它,我会看到意大利语的所有内容(当然,我的操作系统是意大利语!)。
如何在不更改操作系统语言的情况下运行它来测试英语本地化?

回答by sidyll

In the old times, Leopard and before, the get info window in Finder would let you choose the available languages. So it was a matter of deselecting the language that you don't want to use and it would "default" to the other.

在过去,Leopard 和之前,Finder 中的获取信息窗口可让您选择可用的语言。所以这是一个取消选择你不想使用的语言的问题,它会“默认”为另一种语言。

These days you can use an utility like this one. I'd love to know what it does behind the scenes though.

这些日子里,你可以使用一个工具像这一个。我很想知道它在幕后做了什么。



I finally found a nice solution in the cocoa-dev mailing list archives. Apparently, you can change the default domain within the arguments passed to your executable, and this causes the global preference to be overwritten. It can be achieved with the -AppleLanguagesflag, pass a list of the languages in the preferred order:

我终于在cocoa-dev mailing list archives 中找到了一个不错的解决方案。显然,您可以在传递给可执行文件的参数中更改默认域,这会导致全局首选项被覆盖。它可以通过-AppleLanguages标志实现,按首选顺序传递语言列表:

~/apath/AppName.app/Contents/MacOS/AppName -AppleLanguages "(Italian, English)"

Run this from your terminal and it should give a different precedence for the language. Notice you can also specify a single element list "(Italian)"—makes more sense for testing purposes.

从终端运行它,它应该为语言提供不同的优先级。请注意,您还可以指定单个元素列表——"(Italian)"这对于测试目的更有意义。

To do it within Xcode and avoid the terminal, go to the menu Product > Edit Scheme…. Then, in your run configuration switch to the Argumentstab and create a new one to be passed on launch. Add -AppleLanguages "(Japanese)"text to it. Something similar to this:

要在 Xcode 中执行此操作并避免使用终端,请转到菜单Product > Edit Scheme...。然后,在您的运行配置中切换到Arguments选项卡并创建一个在启动时传递的新选项。-AppleLanguages "(Japanese)"为其添加 文本。类似的东西:

Xcode Screen Shot

Xcode 屏幕截图

回答by Jeremy

Assuming you have a file that holds all the strings, swap the names of the files. Or, if you've got a it.lproj and en.lproj group in your project, just move your InfoPlist.strings (or whatever you named it) into the other group and vice versa.

假设您有一个包含所有字符串的文件,请交换文件名。或者,如果您的项目中有 it.lproj 和 en.lproj 组,只需将您的 InfoPlist.strings(或您命名的任何内容)移动到另一个组中,反之亦然。