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.
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".
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];
}
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)
}
}
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:
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.
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.
© 2022 - 2024 — McMap. All rights reserved.