您可以通过编程方式访问 Cocoa Touch 中的标准本地化字符串吗?

发布于 2025-01-03 13:52:04 字数 239 浏览 4 评论 0原文

一些 iOS 控件具有 Apple 内置的本地化字符串。 “完成”、“编辑”、“返回”栏按钮项目是一些示例。有没有办法访问这些字符串?

我正在制作一个带有标准“删除”或“取消”选项的 UIActionSheet,就像您在“联系人”应用程序中删除联系人一样。

有没有办法在代码中引用这些字符串?如果没有,是否有地方至少可以获取这些字符串(例如从 Apple 应用程序的资源中提取它们)?它将节省额外的本地化工作,并确保与平台的一致性。

Some iOS controls have localised strings built in by Apple. The "Done", "Edit", "Back" bar button items are some examples. Is there a way to access these strings?

I am making a UIActionSheet with standard "Delete" or "Cancel" options, just like when you delete a contact in the Contacts app.

Is there a way to reference these strings in code? If not, is there somewhere I can at least get these strings (like extracting them from the resources of an Apple app)? It would save extra localisation work and would ensure consistency with the platform.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卸妝后依然美 2025-01-10 13:52:04

如果 iOS 就像 Mac OS 一样,每个应用程序都带有自己的 Localized.strings 文件。
在每个字符串文件中,您都有所有这些小字符串,例如“完成”、“编辑”、“取消”等。

这些是我从 Finder.app 的英文 Localized.string 文件中复制的一些字符串:

<key>AL1</key>
<string>Cancel</string>
<key>AL4</key>
<string>OK</string>
<key>AL9</key>
<string>Don’t Save</string>
<key>FF24</key>
<string>Save</string>
<key>U32</key>
<string>Yes</string>
<key>U33</key>
<string>No</string>

您明白了。每个小字符串都在每个应用程序中进行了本地化。

这个来自 iTunes.app。

/* ===== Ask User Strings ===== */
"23987.001" = "Yes";
"23987.002" = "No";
"23987.003" = "OK";
"23987.004" = "Cancel";
"23987.005" = "Ignore";
"23987.006" = "Quit";
"23987.007" = "Don’t Quit";
"23987.008" = "Apply";
"23987.009" = "Don’t Apply";
"23987.010" = "Later";
"23987.011" = "Don’t Save";
"23987.012" = "Save";
"23987.013" = "Stop";
"23987.014" = "Continue";
"23987.015" = "Delete";
"23987.016" = "Remove";
"23987.017" = "Replace";
"23987.018" = "Don’t Replace";
"23987.019" = "Do not ask me again";

看起来更有条理一些。不过,复制他们的文件可能是不允许的;-)


Apple Developer 的 Quinn (eskimo1) 的 apples devforum 中的答案关系。

某些 UI 元素会自动为您本地化。例如,UIBarButtonItem 上的图稿。 但是,没有受支持的方法来获取“OK”和“Cancel”等字符串,因为它们在 UIActionSheet 中使用。但是,对于您的本地化人员来说,它们应该很容易处理。 p>

虽然2岁了。但较新的线程具有相同的结果。没有办法得到这些字符串。

If iOS is like Mac OS each app carries their own Localizable.strings file.
And in each strings file you have all those little strings like Done, Edit, Cancel and so on.

These are some strings I copied from the English Localizable.string file from Finder.app:

<key>AL1</key>
<string>Cancel</string>
<key>AL4</key>
<string>OK</string>
<key>AL9</key>
<string>Don’t Save</string>
<key>FF24</key>
<string>Save</string>
<key>U32</key>
<string>Yes</string>
<key>U33</key>
<string>No</string>

You get the idea. Each little string is localized in each app.

This one is from iTunes.app.

/* ===== Ask User Strings ===== */
"23987.001" = "Yes";
"23987.002" = "No";
"23987.003" = "OK";
"23987.004" = "Cancel";
"23987.005" = "Ignore";
"23987.006" = "Quit";
"23987.007" = "Don’t Quit";
"23987.008" = "Apply";
"23987.009" = "Don’t Apply";
"23987.010" = "Later";
"23987.011" = "Don’t Save";
"23987.012" = "Save";
"23987.013" = "Stop";
"23987.014" = "Continue";
"23987.015" = "Delete";
"23987.016" = "Remove";
"23987.017" = "Replace";
"23987.018" = "Don’t Replace";
"23987.019" = "Do not ask me again";

Looks a little bit more structured. Copying their files is probably not allowed though ;-)


An answer in apples devforum by Quinn (eskimo1) from Apple Developer Relations.

Some UI elements are automatically localised for you. For example, the artwork on a UIBarButtonItem. However, there's no supported way to get to the strings like "OK" and "Cancel" as they are used in a UIActionSheet. They should, however, be trivial for your localiser to cope with.

2 years old though. But newer threads have the same outcome. No way to get those strings.

只想待在家 2025-01-10 13:52:04

可以使用以下代码片段从 UIKit 包中访问本地化字符串:

static NSString * UIKitLocalizedString(NSString *string)
{
    NSBundle *UIKitBundle = [NSBundle bundleForClass:[UIApplication class]];
    return UIKitBundle ? [UIKitBundle localizedStringForKey:string value:string table:nil] : string;
}

完全归功于 0xced (XCDFormInputAccessoryView 中的用法)

It's possible to access the localised strings from the UIKit bundle with this snippet:

static NSString * UIKitLocalizedString(NSString *string)
{
    NSBundle *UIKitBundle = [NSBundle bundleForClass:[UIApplication class]];
    return UIKitBundle ? [UIKitBundle localizedStringForKey:string value:string table:nil] : string;
}

Full credit goes to 0xced (Usage in XCDFormInputAccessoryView)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文