【问题标题】:NSDateFormatter ignores the AppleLanguages in NSUserDefaultsNSDateFormatter 忽略 NSUserDefaults 中的 AppleLanguages
【发布时间】:2011-08-03 09:36:32
【问题描述】:

我的应用程序已翻译成多种语言,但现在我想将语言强制为荷兰语。我确实通过将standardUserDefaults中的AppleLanguages键设置为荷兰语来强制语言为荷兰语。这适用于本地化字符串和 xib 文件。

但是 NSDateFormatter 似乎完全忽略了这个值。它只是使用 iPhone 的 en_US 语言环境来格式化日期,即使我自己在 NSDateFormatter 对象上设置了语言环境:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *dutch = [[NSLocale alloc] initWithLocaleIdentifier:@"nl_NL"];
[dateFormatter setLocale:dutch];
[dutch release];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
dateLabel.text = [dateFormatter stringFromDate:[BabyInfo getDate]];
[dateFormatter release];

有人知道如何解决这个问题吗?


更新: 因此,似乎所有日期的东西(如 NSDateFormatter 和 NSDatePicker)都没有使用语言区域设置来确定要显示的日期类型,而是查看位置区域设置。不过,我不知道如何告诉格式化程序和选择器我希望他们用荷兰语显示日期。所以仍然欢迎任何帮助,但至少我现在明白问题所在了。

【问题讨论】:

    标签: iphone objective-c localization


    【解决方案1】:

    也许这个答案来得太晚了,但请检查一下:

    http://www.alexcurylo.com/blog/2011/02/16/tip-nsdateformatter-localization/

    这将强制格式化程序/选择器使用首选语言的区域设置,而无需更改您的 iPhone/iPad 设置。

    【讨论】:

      【解决方案2】:

      要将所选语言用于您的日期格式化程序,请使用:

      [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale preferredLanguages] objectAtIndex:0]]];
      

      【讨论】:

        猜你喜欢
        • 2014-09-10
        • 1970-01-01
        • 1970-01-01
        • 2011-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多