Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to localize Back Buttons?

I am translating an app into Indonesian. The storyboard uses a navigation controller and push segues for all of its view. When I go to a view from the main menu the back button is translated correctly, but when i go to a view from there (two views away from the main menu) the back button says "Back". Thanks in advance for your help.

like image 358
67cherries Avatar asked Dec 03 '13 21:12

67cherries


3 Answers

Please check in your "App"-Info.plist the setting "Localization native development region" and change your default language to "id" for Indonesian. As noted at other sites this affects the language on iOS default buttons like "Edit" or "Done".

see How to change UITabBarController More button's title?

like image 152
DerWOK Avatar answered Nov 13 '22 20:11

DerWOK


Anyway, to change the title of the back button you have to consider that you have to address the PARENT-Controller, not the detail view controller.

Before you push the child view onto the navigation controller, maybe in the prepareForSegue-Method, do something like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@”Back” style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];
[backButton release];

}
like image 35
itinance Avatar answered Nov 13 '22 21:11

itinance


If you're manually pushing to another view controller then, an example:

@IBAction func actionOpenSettings(_ sender: UIButton) {
    if let settingsVC = self.storyboard?.instantiateViewController(withIdentifier: "SettingsViewControllerID") as? SettingsViewController {
        self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back".localized(), style: .plain, target: nil, action: nil)
        self.navigationController?.pushViewController(settingsVC, animated: true)
    }
}
like image 3
Hemang Avatar answered Nov 13 '22 21:11

Hemang