简体   繁体   English

OS X从标准系统本地化字符串中获取字符串

[英]OS X Get string from standard system localized strings

I need to use a few strings in my project like a "Cancel", "Battery", "Apply", etc. 我需要在项目中使用一些字符串,例如“取消”,“电池”,“应用”等。

It is possible to get localized strings from system localized strings? 是否可以从系统本地化字符串中获取本地化字符串?

Example: If OS language is German I need to get german-localized strings for my strings above. 示例:如果OS语言是德语,则需要为上面的字符串获取德语本地化的字符串。

Unfortunately, likely it's impossible. 不幸的是,这可能是不可能的。 You need to localize all strings yourself, besides for example "Back button" or someone like that in iOS. 您需要自己本地化所有字符串,除了“ Back button”或iOS中类似的字符串。 UIKit has some amount of localized strings, but you don't have access to it. UIKit有一些本地化的字符串,但是您无权访问。

Follow the below steps:- 请按照以下步骤操作:-

1) Go to the Project Setting->Build Settings->Localization 1)转到项目设置->构建设置->本地化

2) Click on + button and choose German and then click on Finish button 2)点击+按钮并选择德语,然后点击完成按钮

3) Create new String file name as Localizable string (cmd+N) 3)创建新的String文件名作为可本地化的字符串(cmd + N)

4) Now inside that just add the key value like that below:- 4)现在,在其中添加如下所示的键值:-

在此处输入图片说明 5) Now wherever you want to display your value just access it like that using code:- 5)现在,无论您想在何处显示您的价值,都可以使用以下代码进行访问:-

For example, you want to display in the textfield. 例如,您要显示在文本字段中。

self.txt.stringValue=[NSString stringWithFormat:NSLocalizedString(@"cancel", nil)];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM