Slavenko Miljic
Slavenko Miljic

Reputation: 3856

Change app language programmatically with storyboards

I need to create an iPhone app that will be a fairly simple application with a couple of forms that send some data to a web application. The first time user opens the app he should be presented with a language selection screen.

I've built the app using storyboards and everything works as it should, the language selection views pops up for the first time, the selected language is saved in standardUserDefaults etc.

Now what is the best way of implementing a second language (French) since this is the first time I've been dealing with localized applications. After some searching I figured out how to add a new language/localization to a storyboard and everything works as intended when the correct language has been selected in phone settings. Now what I need to do is to call correct storyboard when the user clicks on a country flag in app settings.

When the user clicks on a flag his selection is written in standardUserDefaults. And after that I'm trying to change to the correct storyboard.

Some code that that I've found that looks that it might be helpful is:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *rootVC = [storyboard instantiateInitialViewController];

The code doesn't work since I don't know how to call the French storyboard.

Any simpler way?

Upvotes: 0

Views: 569

Answers (1)

Why don't you use the native language support. Simply set your labelFields, for example

labelField.text = NSLocalizedString(@"key", nil);

You will have a Localized.strings file with this

"key" = "translated key";

The app automatically will pick the language the device is configured for.

Upvotes: 2

Related Questions