iOS:多语言应用程序
我有一个问题:
我应该做一个多语言应用程序,我想知道一种快速管理图形元素的方法。 方法是这样的:
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
if ([countryCode isEqualToString:@"US"]){
//something to do
}
在这个例子中,我可以在每个视图控制器中设置图形元素,但是没有一个快速的解决方案来完成所有操作吗?在 plsit 文件中的示例?
I have a questions:
I should to do a multilanguage app and I would to know a method to manage graphics elements quickly.
A method is this:
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
if ([countryCode isEqualToString:@"US"]){
//something to do
}
in this example I can set graphics elements in every viewcontroller, but there isn't a quickly solution to do all? at example in plsit file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,我想你可以。
请参阅本教程:
http://www.raywenderlich.com/2876/how -本地化 iPhone 应用程序教程
有一段说你可以为不同的语言设置不同的文件夹。
如果现在可以工作,至少您可以拥有一个单例类,您只需检查一次“countryCode”,将其设置在那里并在“if”语句中引用它。
我希望这有帮助。
Yes, I think you can.
See this tutorial:
http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial
There is a paragraph where it says you can have different folders for different languages.
If that dos now work, at least you can have a singleton class where you check the "countryCode" just once, set it there and refer to it in your "if" statements.
I hope this helps.
如果您使用 XCode 4,只需创建一个 .strings 文件,然后在文件检查器中单击“+”按钮,然后选择要添加的语言。在每个文件中,您将有(键,值)对。例如(“firstViewTitle”=“First View”;)。 .m 文件中只需将 NSLocalizedString 分配给 UI 对象的标题。运行之前尝试清洁目标。希望我能清楚地表达自己
If you are using XCode 4 just create a .strings file then in the file inspector you just hit the " +" button then you choose the language to add. In each file you will have (key, value) pairs.For example ( "firstViewTitle" = "First View"; ). the in the .m file just assign an NSLocalizedString to the title of the UI object. Befor running try to clean the target. Hope i made my self clear
您可以本地化应用程序中所需的每个项目。
例如,一旦您在 Xcode 中导入了资源(例如图像),只需在导航器(左侧)中选择资源,然后在助手(右侧)中搜索“本地化”组并单击“+”按钮。第一次它将创建一个新文件夹并将资源移动到该文件夹(默认为“English”)。稍后您可以添加任意数量的语言,Xcode 将为每种语言创建一个专用文件夹,然后您将能够在本地更改每种语言的资源。例如,如果您有一个“图像按钮”,其中包含要本地化的文本,那么创建所有这些文件夹后,您将能够在本地更改每个文件夹的图像文件。唯一的要求:当然要保持相同的名字。然后,iOS 将能够根据当前设备/模拟器本地化设置获取正确的文件。
请注意,有时如果您更改内容,捆绑包将无法正确编译,为了避免调试时出现麻烦,最简单的解决方案是清理构建并从设备/模拟器中删除并重新安装应用程序。
You can localize every item you want in an app.
E.g. once you have imported a resource (e.g. image) inside Xcode, just select the resource in the Navigator (left side) and then in the Assistant (right side) search for the "Localization" group and click the "+" button. The first time it will create a new folder and will move the resource to that folder (default is "English"). Later you can add as many languages as you want, for each language a dedicated folder will be created by Xcode and then you will be able to change your resource locally for each language. E.g. if you have an "image button" with a text you want to localize, once you have created all these folders you will be able to change the image file locally for each. Only requirement: keep the same name of course. Then iOS will be able to fetch the right file based on the current device/simulator localization setting.
Be aware that sometime if you change stuff the bundle is not compiled correctly and to avoid headaches while debugging the easiest solution is to clean the build and remove and re-install the app from the device/simulator.