UIDatePicker - 问题本地化 [英] UIDatePicker - Problem Localizing

查看:323
本文介绍了UIDatePicker - 问题本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中创建了一个UIDatePicker,我也支持多种语言。我的UIDatePicker是在Interface Builder中创建的,我已经创建了一个单独的本地化XIB,所以我可以自定义我的UIDatePicker。



在IB中设置Locale 。尝试使用Locale和NSCalender以编程方式更改我的DatePicker也不会通过以下代码执行任何操作:

  NSLocale * locale = [[NSLocale alloc ] initWithLocaleIdentifier:@es_ES]; 
datePicker.locale = locale;
datePicker.calender = [locale objectForKey:NSLocaleCalender];

这会导致英语选择器。



这里是真的很奇怪的事情。 今天的词翻译。如附加的屏幕截图所示。 (OK)我不允许张贴图片,但假设一个日期和时间选择器,其中May为英语,Today为Ajourd'hui。



解决方案

在进一步调查后,这实际上不是由iPhone的语言设置处理的UIDatePicker自动本地化基于区域格式设置,而不是语言。这是奇怪的,因为日期是本地化,所以你会认为选择器的本地化



无论如何,要在模拟器中模拟本地化的DatePicker:



<
  • 选择国际
  • $ b $
  • 重新启动您的应用程式,并查看新的UI选择器!


  • I've created a UIDatePicker in my app and I also have support for several languages. My UIDatePicker is created in Interface Builder, and I have created a seperate localization XIB so I can customize my UIDatePicker.

    Setting the "Locale" option in IB appears to do nothing. Attempting to change my DatePicker programatically with Locale and NSCalender also do nothing via the following code:

    NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:@"es_ES"];
    datePicker.locale = locale;
    datePicker.calender = [locale objectForKey:NSLocaleCalender];
    

    This results in an english picker.

    Here's the really weird thing though. The word for "Today" is translated. As seen in the attached screenshot. (OK I'm not allowed to post images. But imagine a Date & Time picker with "May" in English and "Today" written "Ajourd'hui".

    Based on what I've read, adding the UIDatePicker programatically doesn't seem to help much.

    解决方案

    After further investigation, this is actually not handled by the language setting of the iPhone. The UIDatePicker is automatically localized based on the "Region Format" setting and not the language. This is odd because the dates are localized, so you would think the localization of the picker would be linked to the iDevice's language not the Region Format.

    Anyway, to simulate the localized DatePicker in the Simulator:

    1. Exit your app, go to Settings.
    2. Select General
    3. Select International
    4. Select the bottom option, Region Format.
    5. Change to the desired region.
    6. Relaunch your app and see the new UI Picker!

    这篇关于UIDatePicker - 问题本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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