开发者

Localize UIDatePicker "Today" label

开发者 https://www.devze.com 2023-04-12 04:58 出处:网络
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 \"Localizatio

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

精彩评论

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