本地化 UIDatePicker“今天”标签

发布于 2024-12-09 12:37:09 字数 215 浏览 0 评论 0原文

如何在UIDatePicker的日期和时间模式下本地化标签“今天”?

我需要俄语,所以我设置了 UIDatePicker 语言环境,在设备设置中设置区域和语言,在 info.plist 中设置“本地化本机开发区域”和“本地化”属性改为“ru”,但没有任何区别 - 所有月份和日期标签都是俄语,但“今天”标签仍然是“今天”。

How can I localize label "today" in date and time mode of UIDatePicker?

I need russian, so I've set UIDatePicker locale, set region and language in device settings, set "Localization native development region" and "Localizations" property in info.plist to "ru" but it did not make any difference - all month and days labels are russian, but "today" label is still "today".

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

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

发布评论

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

评论(3

梦与时光遇 2024-12-16 12:37:09

在以下代码的帮助下,日期选择器中的所有文本都已本地化,包括字符串“Today”:

//Localizing the datepicker
    NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:NSLocalizedString(@"en_US",nil)];
    datePicker.locale = locale;
    datePicker.calendar.locale = locale;

这里我使用 NSLocalizedString 将“en_US”(键)替换为适当的区域设置标识符(值)。这是在您需要添加的特定语言环境/语言的相应 Localized.strings 文件的帮助下完成的:

/*==== Locale identifier ====*/   
"en_US"="it_IT";

我在这里使用了意大利语(意大利)。

With the help of following code all the text in date picker got localized including the string "Today":

//Localizing the datepicker
    NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:NSLocalizedString(@"en_US",nil)];
    datePicker.locale = locale;
    datePicker.calendar.locale = locale;

Here I am using NSLocalizedString to replace "en_US"(key) with the appropriate locale identifier(value).This is done with the help of corresponding Localizable.strings file for that particular locale/language in which you need to add:

/*==== Locale identifier ====*/   
"en_US"="it_IT";

I have used Italian(Italy) here.

断舍离 2024-12-16 12:37:09

通过创建本地化资源 .xib 解决了问题(只需使用 datePicker 将 IB 中的本地化添加到 .xib 中,不执行任何其他操作)。

有人可以解释为什么吗?

Problem was solved by creating localized resource .xib (just add localization in IB to .xib with datePicker and do nothing else).

Can someone explain why?

幽蝶幻影 2024-12-16 12:37:09

是的,本地化有两个组成部分。第一个是 strings.lproj 文件,其中包含每种语言的键值对,第二个同样重要的是本地化的 xib 或故事板。这两个文件由 Xcode 自动链接到彼此。因此,在您的情况下,需要 ru.lproj localized.strings 文件以及本地化的俄语 Xib 文件。

Yes, there are two components to localization. the first is your strings.lproj fie which contains your Key-value pairs for each language, and the second, and equally important is the localized xibs or storyboards. These two files are automatically linked to each other by Xcode. So, an ru.lproj localizable.strings file is required as well as a Localized Russian Xib in your case.

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