开发者

Localize UIDatePicker "Today" label

How can I localize label "today" in date and time mode of UIDatePic开发者_如何学Cker?

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".


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.


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜