xcode 本地化IOS按钮标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14668299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Localize IOS button label
提问by Tom
I use localization strings to localize UI elements. Everything works, except localizing title of a button.
我使用本地化字符串来本地化 UI 元素。一切正常,除了本地化按钮的标题。
"21.title" = "It should be the localized text"; //does not work
"21.title" = "应该是本地化的文本"; //不起作用
I think it would be caused by state of button (...forState:UIControlStateNormal...), title can be set by view state. How can I defie it in the localization file?
我认为它是由按钮的状态引起的(...forState:UIControlStateNormal...),标题可以由视图状态设置。如何在本地化文件中定义它?
How can I define button title in localization string? What is the trick?
如何在本地化字符串中定义按钮标题?诀窍是什么?
NOTE: I know how to do it from source code, my question is about how to do it by localization string file. So: i know how to use localization strings to localize UI, except buttons.
注意:我知道如何从源代码中做到这一点,我的问题是如何通过本地化字符串文件来做到这一点。所以:我知道如何使用本地化字符串来本地化 UI,除了按钮。
采纳答案by Dave
In Interface Builder, you can set 4 strings, one for each of the states in the "State Config" dropdown.
在 Interface Builder 中,您可以设置 4 个字符串,一个用于“State Config”下拉列表中的每个状态。
OR, alternatively, in 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'll add the localization strings into your Localizable.strings
file. As long as you copy that into your app, you'll get the substitution; and of course you can support multiple languages. Localization Tutorialand Localize in IB
编辑:明确地说,您将本地化字符串添加到您的Localizable.strings
文件中。只要你把它复制到你的应用程序中,你就会得到替换;当然,您可以支持多种语言。 IB 中的本地化教程和本地化
回答by Volker Mohr
"21.title" = "It should be the localized text"; //does not work
should read
应该读
"21.normalTitle" = "It should be the localized text"; //does work
instead.
反而。
回答by Jim Holland
In my case, I had sent the files out to be translated. When they came back there was a subtle error
就我而言,我已将文件发送出去进行翻译。当他们回来时有一个微妙的错误
"0ZD-ku-bT7.title" = “Fechar";
Notice that they have used TWO different double quotes! This breaks the file in subtle way that does not fail in the compiler.
请注意,他们使用了两个不同的双引号!这以不会在编译器中失败的微妙方式破坏文件。
The correct code must be
正确的代码必须是
"0ZD-ku-bT7.title" = "Fechar";