views:

65

answers:

4

Hi everyone, I'm developing an Iphone app that has to support different languages.

I saw that the language has to be set within my app and not within iphone settings. So, do I have to force the language instead to take the current one? I didn't find examples over the internet. All examples need the current language of the application. I would like that the user choose his language when the application starts, then I will set a cookie and (in a way that iI don't know) the app refers automatically to my .lproj folders with different languages. thanks in advance ;)

+1  A: 

Your question isn't really very clear. There is nothing saying that "the language has to be set within my app and not within iphone settings" — it is in fact quite the opposite!

Cocoa has a pretty neat localization system that is quite easy to use (grumbles something about rotten localization workflows). Here's the full skinny on it — basically, have files in lproj folders, then use the NSBundle resource APIs to locate them (NIB loading and other subsystems use it automatically, so you don't even have to do work there!).

millenomi
+1  A: 

This is not possible using the default localization mechanisms in iOS. By default, the system chooses the .lproj folder according to the user's system language and does the localization automatically if you have localized NIBs and use NSLocalizedString() etc..

If you really want to change that behavior and "override" the system language, you have to implement your own version of NSLocalizedString that manually accesses the strings file in the .lproj folder you want. Be aware though that NIBs don't use your custom NSLocalizedString function. So either don't use NIBs at all or do the localizing of the NIBs in code instead of using different NIBs.

Ortwin Gentz
A: 

[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"it",@"en", nil] forKey:@"AppleLanguages"];

then if the iPhone language is set to english, my iPhone app will works always with "it". the first of the array.

Sergio Andreotti
A: 

IIRC, you want NSLocalizedStringFromTable.

You create a .strings file for each language: eg "EN.strings", "JP.strings", etc...

These files will be loadable from the default bundle with the table parameter to NSLocalizedStringFromTable.

When the user picks a language, you switch which table (.strings file) to load the strings from.

One problem tho is that iOS strings will still be localized to the user's settings, or to whatever you have your app localized to in the Info.plist. So you might end up with a mix of languages.

Oliver Moffat