可可本地化 [英] Localization in Cocoa

查看:102
本文介绍了可可本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要本地化我的应用程序,我还需要翻译人员可以轻松访问他需要翻译的文件.我看到接口文件(.xib和其中的字符串)被分成了多种语言.

I need to localize my application, and I need also that the translator will have easy access to the files he needs to translate. I see that interface files (the .xibs and the strings inside them) are divided into languages.

解决方案是手动重写所有.xib吗?如果应用程序中以编程方式显示了一些字符串,该怎么办?也许我需要一个类似全局参数的东西来告诉应用程序设置了哪种语言.无论如何,我认为Mac应用程序会根据系统语言自动显示正确的.xib.

The solution would be manually rewriting all the .xibs? And what if some strings are programmatically shown in the application? Maybe I need something like a global parameter that tells the application which language is set. Anyway, I think that Mac applications automatically show the right .xib depending on the system language.

使用可翻译界面进行编程时是否有最好的"事情?

Is there a "best" thing to do when programming with translatable interfaces?

推荐答案

我认为您需要的是本地化.

What I think you need is Localization.

在代码中使用字符串的地方

Where you use strings in your code:

  • 创建一个新的Localizable.strings文件(文件->新文件-> iOS->资源->字符串文件)

  • Create a new Localizable.strings file (File -> New File -> iOS -> Resources -> Strings file)

选择此文件并显示文件检查器(Command + Option + 1)

Select this file and Show the file inspector (Command + Option + 1)

单击本地化下的添加按钮,然后添加默认语言(我希望使用英语)和您想要的其他语言.

Click the add button under localization and add a default language (I expect English) and the other languages you want.

您会发现Localizable.strings文件旁边有一个小箭头,如果单击它,您会看到已添加的语言.

You'll notice that you have a little arrow next to your Localizable.strings file, if you click it, you can see the languages that you've added.

对于要翻译的每个短语,请使用以下语法:

For each phrase you want to translate, use the following syntax:

"key" = "value";
"hello" = "bonjour";

"key" = "value";
"hello" = "bonjour";

在您要使用翻译的代码中,使用NSLocalizedString(@"hello", @"hello");(第二个参数是注释,在这里使用什么值都没有关系)

In your code where you want to use the translation, use NSLocalizedString(@"hello", @"hello"); (The second parameter is a comment, it doesn't matter what value you use here)

涉及笔尖时,您需要手动更改字符串并重新排列每个笔尖中的文本字段等.

When it comes to nibs, you'll need to manually change the strings and re-arrange the text fields etc in each nib.

希望这会有所帮助!

这篇关于可可本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆