Localize iOS Button Shortcut

I use localization strings to localize interface elements. Everything works, except for the localization of the button name.

"21.title" = "It must be localized text"; // does not work

I think this is caused by the state of the button (... forState: UIControlStateNormal ...), the title can be set by view state. How can I define it in a localization file?

How to determine the button title in the localization string? What is the trick?

NOTE. I know how to do this from the source code, my question is how to do this using the localization string file. So: I know how to use localization strings to localize the user interface, with the exception of buttons.

+8
ios xcode localization storyboard
source share
3 answers

In Interface Builder, you can set 4 lines, one for each of the states in the "State Configuration" drop-down list.

OR, alternatively, in the code, you set the button title for each state:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setTitle:NSLocalizedString(@"21.title", @"Norm!") forState:UIControlStateNormal]; [button setTitle:NSLocalizedString(@"21.title-highlighted", @"hi btn") forState:UIControlStateHighlighted]; [button setTitle:NSLocalizedString(@"21.title-selected", @"sel btn") forState:UIControlStateSelected]; [button setTitle:NSLocalizedString(@"21.title-disabled", @"dis btn") forState:UIControlStateDisabled]; 

Edit: to be clear, you will add localization strings to your Localizable.strings file. As long as you copy this application, you will receive a replacement; and of course you can support multiple languages. Localization Tutorial and Localization in IB

+6
source share
 "21.title" = "It should be the localized text"; //does not work 

must read

 "21.normalTitle" = "It should be the localized text"; //does work 

instead.

+27
source share

In my case, I sent files for translation. When they returned there was a small mistake

 "0ZD-ku-bT7.title" = "Fechar"; 

Please note that they used TWO different double quotes! This interrupts the file in a subtle way that does not interrupt in the compiler.

The correct code should be

 "0ZD-ku-bT7.title" = "Fechar"; 
0
source share

All Articles