Multi language lable changes in the .xib file.

删除回忆录丶 提交于 2019-12-10 22:14:16

问题


I have to develop the application into Four(4) languages (English, French, Italic, Spanish).

So, for that I want to know is there any way to display different language data using only one(1) .xib file in the top bar.

Example:

I have the Setting.xib (.xib file) in which there are four labels in the view part and in the top bar of that Nib file I want to change the label names according to the set language using One & Only one Nib file.

So, please give me the appropriate solution.

Which will take less time for the loading.


回答1:


First of all, I don't understand why you can't simply use NSLocalizedString when setting the label text, it does exactly what you want, loading the appropriate version of the text, according to the device's language.

Anyway, I think you could find something useful here.

I actually did something similar, with six languages and only a single Nib but in my case I could have had the language changed inside the app, so I needed to be able to forcefully tell it to load me the localized version of a string from the specific bundle.

Here's the exact code that should help you in case your problem is more like mine and a simple NSLocalizedString is not enough:

NSString* path= [[NSBundle mainBundle] pathForResource:[[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0] ofType:@"lproj"];

NSBundle* languageBundle = [NSBundle bundleWithPath:path];

someLabel.text = [languageBundle localizedStringForKey:@"textKey" value:@"" table:nil];

Since you will probably have more than one label, it would be a good idea to have the path stored as a class property and set in viewDidLoad, so you will be able to access it from any method/function inside that class.



来源:https://stackoverflow.com/questions/5974680/multi-language-lable-changes-in-the-xib-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!