iphone - 如何本地化 iPhone 应用程序的号码?

标签 iphone localization

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

//伪代码

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

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

As this page explains ,不同语言之间有两件事可能有所不同:

  • The form how plural forms are built differs. This is a problem with languages which have many irregularities. German, for instance, is a drastic case. Though English and German are part of the same language family (Germanic), the almost regular forming of plural noun forms (appending an ‘s’) is hardly found in German.
  • The number of plural forms differ. This is somewhat surprising for those who only have experiences with Romanic and Germanic languages since here the number is the same (there are two).

我应该如何在代码中处理这个问题?

最佳答案

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

如果你的翻译来找你并说,为了支持 Martian,你需要对偶数和奇数进行单独的拼写,那么你可以调整你的代码,例如:

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/Localized.strings:

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

mars.lproj/Localized.strings:

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

很抱歉,如果这听起来不太理想,但人类语言是困惑且不规则的,因此尝试为所有语言找到一个优雅、统一、通用的解决方案是浪费时间。没有一个。

关于iphone - 如何本地化 iPhone 应用程序的号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1632169/

相关文章:

iPhone 导航栏图像

php - PHP 的语言本地化

iphone - Xcode 找不到我的静态库!

java - 如何使用 Java 编程将一种语言翻译成另一种语言

c# - 本地化 asp.net 下拉列表

c# - 资源中的 DisplayName 属性?

iphone - 在 objective-c (iPhone) 中抽象出字符串

iphone - 查看 Controller : Ladnscape to Portrait

iphone - 如何修复启用 ARC 的 iPhone 项目中的内存泄漏?

iphone - cocoa - 我发现了 NSDecimalNumber 的一个错误