.xib文件中的多语言标签更改. [英] Multi language lable changes in the .xib file.

查看:112
本文介绍了.xib文件中的多语言标签更改.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将应用程序开发为四(4)种语言(英语,法语,斜体,西班牙语).

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

因此,我想知道有什么方法可以在顶部栏中仅使用one(1).xib file来显示不同的语言数据.

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.

示例:

我在其中有Setting.xib(.xib文件) 其中有四个标签 查看部分,并在其顶部栏中 我要更改标签的笔尖文件 根据设置的语言命名 使用One&只有一个Nib文件.

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.

推荐答案

首先,我不明白为什么设置标签文本时不能简单地使用NSLocalizedString,它确实可以实现所需的功能,并加载根据设备的语言选择适当的文本版本.

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.

我实际上做了类似的事情,只有六种语言,只有一个Nib,但就我而言,我本可以在应用程序内部更改语言,所以我需要能够有力地告诉它,以将其加载到本地化版本中.特定捆绑软件中的字符串.

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.

如果您的问题更像是我的问题,而简单的NSLocalizedString还不够,那么以下是应该对您有帮助的确切代码:

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];

由于您可能会有多个标签,因此将路径存储为类属性并在viewDidLoad中进行设置是一个好主意,因此您可以从该类内的任何方法/函数访问它.

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.

这篇关于.xib文件中的多语言标签更改.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆