简体   繁体   English

在iPhone应用程序上设置语言

[英]Setting language on iPhone application

I am working on an application which I am planning to release both in English and Spanish languages. 我正在开发一个计划以英语和西班牙语发布的应用程序。 With this I mean, I would like it to have two separate apps in the App Store, one being displayed with English title, and the other one with Spanish title (and each with contents in their respective language). 我的意思是说,我希望它在App Store中有两个独立的应用程序,一个显示为英文标题,另一个显示为西班牙语标题(每个都有各自语言的内容)。

This means that the language in the app would be static, that is, that actually the app would not be internationalized, in the sense that the app would not display the language according to the user's locale settings, but according to either English or Spanish depending on the app bought. 这意味着该应用程序中的语言将是静态的,也就是说,实际上该应用程序将不会被国际化,这意味着该应用程序将不会根据用户的语言环境设置显示语言,而是根据英语或西班牙语显示在购买的应用上。

I initially thought of using a constants file with constants strings of all the labels, button titles, etc. and having an identical separate project for each language, and changing this constants file on each project, but of course, this involves some hassle regarding maintenance. 我最初考虑使用带有所有标签,按钮标题等常量字符串的常量文件,并且为每种语言使用相同的单独项目,然后在每个项目上更改此常量文件,但是当然,这涉及维护方面的麻烦。

The other approach I am thinking of, is actually performing the whole internationalization process (NSLocale, localization files, etc), and somewhat at the app startup skip the user's locale, and set either language programmatically (here, I would only need to know is how to skip such default i18n process to set a specific language. In this case, I would see the advantage of having only one local project, and the possibilty of setting the language on each build, for a different language app. 我正在考虑的另一种方法实际上是执行整个国际化过程(NSLocale,本地化文件等),并在应用程序启动时略过用户的语言环境,并以编程方式设置两种语言(在这里,我只需要知道如何跳过这种默认的i18n流程来设置特定语言在这种情况下,我将看到只拥有一个本地项目的优势,并且可以为不同的语言应用程序在每个版本上设置语言。

Could you please provide advice regarding which approach or best practice to follow?? 您能否提供有关遵循哪种方法或最佳做法的建议? Does this make sense, or is there another approach that I should follow instead in order to have the two separate, fixed language apps? 这是否有意义,还是我应该遵循另一种方法来拥有两个单独的固定语言应用程序?

Thank you very much in advance! 提前非常感谢您!

Best regards 最好的祝福

Duplicate: Best way to make an iPhone application multi-lingual 复制: 使iPhone应用程序实现多语言的最佳方法

Short version: include a language file for each language. 简短版:包括每种语言的语言文件。 Apple'll take care of the rest - when the user changes their iPhone's language, your app will switch too (assuming a translation is available). 苹果公司将负责其余的工作-当用户更改其iPhone的语言时,您的应用也会切换(假设有翻译可用)。

if you really want to have two separate apps in the App Store, you could do something like 如果您真的想在App Store中拥有两个独立的应用程序,则可以执行以下操作

Making multiple versions of an iPhone application 制作多个版本的iPhone应用程序

to have them both be built from a single Xcode project and make maintenance as easy as possible. 使它们都可以从单个Xcode项目构建,并使维护尽可能容易。

why not just have a single app version that includes both languages and automatically chooses the user's preferred language? 为什么不只有一个包含两种语言并自动选择用户首选语言的应用程序版本? if your goal is that bilingual people should pay you separately for two copies, then you'll need two separate apps like you suggest, I guess. 我想,如果您的目标是双语者应该分别为您支付两份副本,那么您将需要两个单独的应用程序,就像您建议的那样。

Localize your application for English and Spanish and put the following lines of code in main.m before the call to UIApplicationMain: 将您的应用程序本地化为英语和西班牙语,并在调用UIApplicationMain之前将以下代码行放在main.m中:

NSArray *languages = [NSArray arrayWithObject:@"es"];
[[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"];
[languages release];

where the language code is either "es" or en". This will put the preferred language (es or en in your case) in the application's preferences (in the property list file ../your app's UUID/Library/Preferences/yourcompany's Internetadress.your app's name.plist) and override the language set in Settings. 语言代码是“ es”或“ en”。这会将首选语言(在您的情况下为es或en)放入应用程序的首选项(在属性列表文件中。./您的应用程序的UUID / Library / Preferences /您公司的Internetadress .your应用程序的name.plist)并覆盖在“设置”中设置的语言。

This makes the app use the localized strings and use the localized XIBs. 这使应用程序使用本地化的字符串并使用本地化的XIB。 However, for some reason it does not work for localizing the app's icon and bundle display name. 但是,由于某些原因,它不适用于本地化应用程序的图标和捆绑显示名称。 Adding a line for setting the locale (the key seems to be "AppleLocale") does not help. 添加用于设置语言环境的行(键似乎是“ AppleLocale”)无济于事。 The current locale remains the one set in Settings, not the one set programmatically. 当前语言环境仍然是“设置”中的一组,而不是通过编程的一组。

The line 线

[languages release]; [语言发布];

shouldn't be there. 不应该在那里。

Localizing the strings and the XIBs suffices. 本地化字符串和XIB就足够了。 Duplicate the target following http://www.iphonedevsdk.com/forum/iphone-sdk-development/8036-lite-game-duplicate-xcode-project.html and set Icon file and Bundle display name in the copy's plist file. http://www.iphonedevsdk.com/forum/iphone-sdk-development/8036-lite-game-duplicate-xcode-project.html之后复制目标,并在副本的plist文件中设置图标文件和捆绑包显示名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM