How to localize Back Buttons?
Asked Answered
H

6

19

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.

Hoboken answered 3/12, 2013 at 21:50 Comment(9)
Is it the default navigation controller Back button? If so, I believe Apple localizes it for you like the UIBarButtonSystemItems are.Adder
The Navigation controller is a the default that I got from dragging it, no changes were made.Hoboken
Try changing the native language of the iOS Simulator to Indonesian to test it out. The back button should be in IndonesianAdder
I have. It continues to not work. :/Hoboken
That is strange. What you could always do is replace the back button with a custom made back button, which you localize the title. I'm shocked it does not localizeAdder
This site suggests a way: blog.ezer0.net/2012/04/add-customized-back-button-to.htmlAdder
@for i in range awesome I found the problem. When I localized the main storyboard, some of the navigation items had back buttons that were manually set to "Back". I changed all of them, and the app is working as expected.Hoboken
67cherries - if you answered your own question, you should write up the answer and mark it as the correct one.Tumefaction
See this answer here: https://mcmap.net/q/666921/-how-to-change-uitabbarcontroller-more-button-39-s-titleLussier
H
18

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?

Hillhouse answered 3/12, 2013 at 22:59 Comment(0)
B
6

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];

}
Besant answered 28/3, 2014 at 17:23 Comment(0)
P
3

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)
    }
}
Pectoralis answered 23/10, 2018 at 5:13 Comment(0)
R
2

For Swift, use the following:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "mySegueIdentifier" {   
        let backButton = UIBarButtonItem(title: "MYLOCALISEDSTRING", style: UIBarButtonItemStyle.plain, target: nil, action: nil)
        self.navigationItem.backBarButtonItem = backButton

    }
}

This will change the default back button as follows:

enter image description here

Rant answered 20/9, 2018 at 6:21 Comment(0)
S
0

I have found that if the parent view controller's navigationItem.backBarButtonItem.title string has been set in the Storyboard file, any changes added later (in the pushed ViewController's viewWillAppear for example) will be ignored. Check to see if the parent controller in the storyboard has set text for the back button. Localizing self.navigationItem.backBarButtonItem.title in the parent controller fixed it for me.

Scevo answered 18/12, 2013 at 2:30 Comment(0)
P
-1

Im not sure exactly what the problem is, but using the AGi18n library may help. It forces .xibs to localize according to the localizable.strings file. So if your .xib contains "back", and your localizable.strings has a rule for "Back", it will be localized.

Theres a tutorial for using the library on the bottom half of this SmoothLocalize's localization tutorial.

Painting answered 10/12, 2013 at 22:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.