如何本地化iPhone应用程序的数字? [英] How to localize numbers for iPhone app?

查看:119
本文介绍了如何本地化iPhone应用程序的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iPhone应用程序中,我需要显示对象计数然后本地化,因为英语区分单数和复数,我执行以下操作

In my iPhone app, I need to display object counts which I then localize, since English makes the distinction of singular and plural, I do the following

//伪代码


if (objectList.count == 1)
{
   NSLog(@"%@", NSLocalizedString(@"1 object", @"display one objects");
}
else
{
  NSLog(@"%@", NSLocalizedString(@"%d objects", @"display multiple objects");
}

这适用于英语,但在许多其他语言中复数形式的名词不是简单地通过添加's'来构造的。

This works for English but in many other languages the plural form of a noun is not simply constructed by adding an ‘s’.

正如本页解释,语言之间有两种不同的东西:

As this page explains, there are two things which can differ between languages:



  • 复数形式的构建形式有所不同。这是
    语言的一个问题,它有很多
    的违规行为。德语,例如,
    是一个例子个案。虽然英语和
    德语是同一种语言
    family(日耳曼语)的一部分,但几乎常规
    形成复数名词形式
    (附加's')几乎找不到
    德语。

  • 复数形式的数量不同。对于那些只有罗马语
    和日耳曼语言经验的
    来说,这有点令人惊讶,因为这里
    的数字是相同的(有两个)。

我应该如何处理我的代码?

How should I deal with this in my code?

推荐答案

NSLocalizedString将从应用程序包中的字符串表中读取。因此,您需要支持的语言列表在编译时是已知的。而不是担心如何为每种可能的语言编写代码,只需支持你支持的语言。

NSLocalizedString is going to be reading from a string table in your app bundle. Therefore, the list of languages you need to support is known at compile time. Rather than worry about how to code for every possible language, just support the ones you are supporting.

如果你的翻译来找你并说,为了支持火星人,你需要单独拼写偶数和奇数,你可以调整你的代码,如下所示:

If your translator comes to you and says that, to support Martian, you need a separate spelling for even and odd numbers, you can adjust your code then, to something like:

if (objectList.count == 1) {
    NSLocalizedString(@"ObjectCount1", @"display one");
} else if (objectList.count % 2 == 0) {
    NSLocalizedString(@"ObjectCountEven", @"display even");
} else if (objectList.count % 2 == 0) {
    NSLocalizedString(@"ObjectCountOdd", @"display odd");
}

en.lproj / Localizable.strings:

en.lproj/Localizable.strings:

ObjectCount1 = "1 object";
ObjectCountEven = "%d objects";
ObjectCountOdd = "%d objects"; // same as ObjectCountEven

mars.lproj / Localizable.strings:

mars.lproj/Localizable.strings:

ObjectCount1 = "1 object-o";
ObjectCountEven = "%d object-e";
ObjectCountOdd = "%d object-o"; // same as ObjectCount1

很抱歉,如果这听起来不太理想,但人类语言杂乱无序,因此,试图为他们所有人找到一个优雅,统一,通用的解决方案是浪费时间。没有一个。

Sorry if this sounds less than ideal, but human languages are messy and irregular, so it's a waste of time to try to find an elegant, unified, common solution for them all. There isn't one.

这篇关于如何本地化iPhone应用程序的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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