为非标准语言环境本地化应用程序 [英] Localizing apps for non-standard locales

查看:131
本文介绍了为非标准语言环境本地化应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,该应用程序应支持一种语言,该语言不在设备上可用的(40?)语言列表中,但区域格式是.我要本地化天的名称以及昨天...".问题是,几天(Monday,...)是使用NSLocale获取的,因此可以在任何设备上使用,但是"yesterday"之类的单词必须本地化为40种左右的语言.即使XCode允许我针对所需区域进行本地化,该设备仍使用标准语言(在我的情况下为丹麦语).

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.

结果是(像在呼叫"应用程序中一样),昨天"以英语显示(因为我无法本地化特定区域,例如kamba-Kenya),但是日期名称可以很好地翻译.除了硬编码,还有其他方法吗?

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?

推荐答案

我怀疑您是否必须为iOS支持的语言环境对这些数据中的任何一个进行硬编码.要完全避免对任何语言环境进行硬编码,都需要付出一些额外的努力.

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大量使用来自 CLDR 的语言环境敏感数据,并且支持您的语言环境,您不必将这些字符串本地化,因为这些相对日期名称(CLDR术语中的类别,涵盖诸如"Today","Yesterday"和"Tomorrow"之类的单词)的翻译为示例,该数据显示了德语与英语相比的德语数据:

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>

此外,我发现NSDateFormatter具有两个名为

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.

尽管ka-KE数据在CLDR中可用,但是由于iOS尚不支持此语言环境,因此您必须经过箍才能使其起作用;例如为iOS构建 ICU ,有关详细信息,请参见此答案或使用

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.

这篇关于为非标准语言环境本地化应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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