开发者

Multi language lable changes in the .xib file.

开发者 https://www.devze.com 2023-03-05 02:59 出处:网络
I have to develop the application into Four(4) languages (English, French, Italic,开发者_JAVA技巧 Spanish).

I have to develop the application into Four(4) languages (English, French, Italic,开发者_JAVA技巧 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号