Reputation: 551
I am writing an app which should support a language which is not in the list of available (40?) languages on the device, but the region format is. I want to localize the name of days as well as "yesterday...". The problem is, that days (Monday,...) are fetched using NSLocale
and therefore work on any device, but words like "yesterday" have to be localised to a language amongst the 40 or so. Even though XCode lets me localize for the wanted region, the device uses the standard language, in my case Danish.
The result is (like in the Call app) that "yesterday" shows up in English (since I can't localize for the specific region, say kamba-Kenya), but day names are translated just fine. Is there any way around this except hard-coding?
Upvotes: 0
Views: 287
Reputation: 1965
I doubt it that you have to hard-code any of these data for iOS supported locales. It would take some extra effort to be able to avoid hard-coding it for any locales at all.
iOS heavily utilizes locale-sensitive data from CLDR and your locale is supported, you don't have to localize these strings since translations for these relative date names (which is the category in CLDR terminology covering words such as "Today", "Yesterday", and "Tomorrow") are planned to be part of locale data. An example showing this data for German compared to English:
<fields>
...
<field type='day'>
<displayName>Day</displayName>
<relative type='-1'>Yesterday</relative>
<relative type='0'>Today</relative>
<relative type='1'>Tomorrow</relative>
</field>
...
</fields>
<fields>
...
<field type='day'>
<displayName>Tag</displayName>
<relative type='-2'>Vorgestern</relative>
<relative type='-1'>Gestern</relative>
<relative type='0'>Heute</relative>
<relative type='1'>Morgen</relative>
<relative type='2'>Übermorgen</relative>
</field>
...
</fields>
Also, I found out that NSDateFormatter
has two attributes called setDoesRelativeDateFormatting
and doesRelativeDateFormatting
which most probably give you what you need for those supported locales. I'm not an iOS developer so I can't say with certainty.
Although the data for ka-KE
is available in CLDR, but since this locale is not yet supported by iOS, you have to go through hoops to make it work; e.g. build ICU for iOS which was covered in detail in this answer or using the static build available here.
Upvotes: 2