0

Our Customer got reports on the App-Store that something is wrong with the language selection of the app.

I've tried to find a solution for this myself but I just couldn't read out the settings that the user has set on the settings page correctly.

Information:

  • We can't solve it with NSBundle because it would exceed the budget of the customer...
  • App supports 3 base languages (German, French and English) (Swiss German, Swiss French, English UK English US etc are all transformed into de, fr or en)
  • App contains 3 language files (de.lproj, fr.lproj and en.lproj)
  • App defines supported languages in a constant array + fallback language (en) is at first position
  • Language has to be set because otherwise iOS would decide to show english for swiss german or english for swiss french for example

Problem:

    1. We select English in the settings and then start the app --> App is in English --> OK
    1. We then change language in the settings to German and then start the app --> App is in English --> Not OK
    1. Reinstalling the app puts us to point 1. again (with selected language)

What does the App do?

    1. Read [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] (preferred languages)
    1. Read [[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleLanguageCode] (to get the regional format)
    1. Transform de-CH fr-CH en-US en-UK etc. to de/fr/en
    1. If SupportedLanguages contains autoupdatingCurrentLocale
      • [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"]; with autoupdatingCurrentLocale at first position
      • ELSE: [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"]; with fallback language (en) at first position
    1. [[NSUserDefaults standardUserDefaults] synchronize];

[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] doesn't change anymore when the user changes the language in the settings.

How do I solve this correctly? Any ideas?

Kara
  • 6,115
  • 16
  • 50
  • 57
byemute
  • 643
  • 7
  • 15

1 Answers1

0

Found the solution for myself by googling a bit more.

After we've done the language juggling and setting it in the NSUserDefaults (as shown above) we'd like to "reset" the AppleLanguages object in the NSUserDefaults standardUserDefaults.

This is achieved with the following command:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"]

Where to put this command?

In your delegates didFinishLaunchingWithOptions.

It's safe to remove at this point because all the bundle initialisation has been completed (in the main method). The AppleLanguages object is being restored and then reflects the system settings again.

Thanks to: iPhone App Localization - English problems?

Community
  • 1
  • 1
byemute
  • 643
  • 7
  • 15