如何获得本地化的 Cancel、Done 等? [英] How to get localized Cancel, Done and etc?

查看:15
本文介绍了如何获得本地化的 Cancel、Done 等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIBarButtonItem 有 Cancel、Done 等标识符.它们以文本形式显示给用户.如果用户更改语言,例如取消按钮将被自动翻译.作为开发人员,您不需要为此按钮提供本地化字符串.这意味着 Cancel、Done 和其他字符串已经本地化并与 OS 一起提供.

UIBarButtonItem have identifiers like Cancel, Done and some others. They are shown as text to user. If user changes language then for example Cancel button will be translated automatically. And as developer you do not need to provide localization string for this buttons. It means that Cancel, Done and other strings already localized and comes together with OS.

这是一种以编程方式获取此字符串的方法吗?

Is here a way to get this strings programmatically?

我不想在本地化文件中添加额外的字符串.如果可以访问那就太好了.

I do not want to add additional strings to localization files. And if it is possible to access then it would be very good.

推荐答案

这是我创建的一个小宏,用于获取 System UIKit 字符串:

Here's a little macro I created to get the System UIKit Strings:

#define UIKitLocalizedString(key) [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] localizedStringForKey:key value:@"" table:nil]

像这样使用它:

UIKitLocalizedString(@"Search");
UIKitLocalizedString(@"Done");
UIKitLocalizedString(@"Cancel");
...

这篇关于如何获得本地化的 Cancel、Done 等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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