Search code examples
iosobjective-clocalizationnsnumberformatter

Change default locale of iOS app


I am creating an app in Swedish and it should only run in Swedish no matter what the device locale is. I am wondering how I set the default locale for my app to be swedish i.e. sv_SE. When I create a NSNumberFormatter I want it to localize to sv_SE by default

In the project info settings "Localization" only contains Swedish.

NSNumberFormatter *nf = [NSNumberFormatter alloc] init];
NSLog(@"Locale: %@", nf.locale.localeIdentifier);

//Returns Locale: en_US

Am I missing such an overall setting or do I have to manually localize all my objects to Swedish?


Solution

  • There is nothing automatic inside iOS app runtime that can make it run in your desired locale. Yes, you need to localize every resource, text and messages that you want to display to sv_SE.

    You can make your app aware about when the user alters a locale (e.g. by going inside iphone settings), by listening to NSCurrentLocaleDidChangeNotification notification.

    Once done, if you want additional languages too, you can use NSLocalizedString function to invoke your desired locale every time you need to display a translation. This will show translated value based on user's set locale under Language Settings.

    NSLocale documentation gives further insights.