Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change iphone app language with buttons and without restart of the app

I want to change the language of my app. At the moment I am doing it at the following way. I have two buttons which are change the languages in NSUserDefaults. But before this affects my app I need to restart it.

Here is my code.

- (IBAction)changeDutch:(id)sender {
    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"nl", @"en", nil] forKey:@"AppleLanguages"];

}
- (IBAction)changeEnglish:(id)sender {
    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en", @"nl", nil] forKey:@"AppleLanguages"];
}

This works fine. But I don't want every time to restart my app. Can anyone tell me how to do that?

Kind regards!

like image 290
Sarah Geebelen Avatar asked Feb 18 '23 05:02

Sarah Geebelen


2 Answers

Check out HMLocalization: https://github.com/HeshamMegid/HMLocalization

It's a replacement for the default localisation framework. It has a demo showing how to change language without having to restart the app.

like image 140
Hesham Avatar answered May 01 '23 00:05

Hesham


There is a method to change app language without restart mentioned this tutorial post I've tried it in an app and it works mostly but still if you are using system items like More tab in tabbar, Edit button on MoreNavigationController and Cancel button on UISearchBar and so on, there text can't be changed for selected language without restarting app. If there is no such item that is controlled by iOS instead of your app, this is a perfect solution for you.

like image 20
Atif Azad Avatar answered Apr 30 '23 23:04

Atif Azad