0

I am working on localization of my app for the English and Arabic support. I have followed all localization steps and supported my app for English and Arabic languages.

But I am facing problem in setting application's default language as English when user downloads and opens the app first time.

For example, Arabic user's device language is Arabic but when he downloads and open the app, first time app should be in English only. Later on he will select whether to change language or not. (As I have given option to change the language)

I have tired following code in main.m file

int main(int argc, char * argv[]) {

       @autoreleasepool {

            [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
            [[NSUserDefaults standardUserDefaults] synchronize]; // to make the change immediate
             return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
    }

This UserDefault can change the app language but app needs to be restarted the app, then it will work fine. Issue is only for the first time launch.

I have searched so many links but nothing works.

Please help me to sort out my issue.

Rohan
  • 2,939
  • 5
  • 36
  • 65
Maulik shah
  • 1,664
  • 1
  • 19
  • 45
  • 1
    did you try in `didFinishLaunchingWithOptions` method of `appDelegate.m` file ? – Nirav Kotecha Mar 29 '19 at 08:59
  • yes tried it...but not work.. when i restart then it's worked – Maulik shah Mar 29 '19 at 09:02
  • The solution you posted is kind of hack what has never been covered by API contract and nothing ensures if it works or will continue working in future. Proper approach is to take a corresponding language bundle then provide application with language-specific assets in runtime. – The Dreams Wind Mar 29 '19 at 09:31
  • https://stackoverflow.com/questions/9939885/manual-language-selection-in-an-ios-app-iphone-and-ipad – Sachin Vas Mar 29 '19 at 11:26
  • I have used https://github.com/marmelroy/Localize-Swift it has setCurrentLanguage method – Prashant Tukadiya Mar 29 '19 at 12:51

0 Answers0