如何在iOS中使用本地化语言更改xib

时间:2015-12-19 11:24:30

标签: ios objective-c localization nslocalizedstring localizable.strings

如何在项目中使用xibs时更改应用语言。

/* Class = "UILabel"; text = "Clients"; ObjectID = "22E-Bc-4Af"; */
"22E-Bc-4Af.text" = "Klienci";

/* Class = "UILabel"; text = "Messages"; ObjectID = "5y0-E0-aXx"; */
"5y0-E0-aXx.text" = "Wiadomości";

/* Class = "UILabel"; text = "Calendar"; ObjectID = "H9g-zr-B2l"; */
"H9g-zr-B2l.text" = "Kalendarz";

/* Class = "UILabel"; text = "Settings"; ObjectID = "Hxq-Ij-R8l"; */
"Hxq-Ij-R8l.text" = "Ustawienia";

/* Class = "UILabel"; text = "Recommend"; ObjectID = "ka7-JK-tWz"; */
"ka7-JK-tWz.text" = "Poleć";

/* Class = "UILabel"; text = "Label"; ObjectID = "pYM-Zf-LI7"; */
"pYM-Zf-LI7.text" = "Label";

/* Class = "UILabel"; text = "Shop"; ObjectID = "zhW-HV-pnE"; */
"zhW-HV-pnE.text" = " Zakupy";

当我更改应用语言时,xib不会更改,只会更改.string文件中的更改。

1 个答案:

答案 0 :(得分:0)

您无法直接将foo()国际化。如果为每个组件添加category,则有可能。

样品:

xib

但是手动实现这是非常困难的工作,可能包含错误。 我建议您使用@implementation UILabel (i18n) - (void)localizeFromNib { if (self.text.length > 0) { self.text = [[NSBundle mainBundle] localizedStringForKey:self.text value:@"" table:nil]; } } @end AGi18n,它已经使每个组件国际化。