gpt4 book ai didi

locale - JDK Locale 类处理希伯来语 (he)、意第绪语 (yi) 和印度尼西亚语 (id) 的 ISO 语言代码

转载 作者:太空狗 更新时间:2023-10-29 22:46:09 25 4
gpt4 key购买 nike

实例化 Locale 时具有以下任一语言代码的对象:heyiid 它不会保留它们的值。

例如:

Locale locale = new Locale("he", "il");
locale.getLanguage(); // -> "iw"

是什么原因造成的,有什么办法可以解决这个问题吗?

最佳答案

Locale 类不会对您输入的内容进行任何检查,但会将某些语言代码换成它们的旧值。来自 the documentation :

ISO 639 is not a stable standard; some of the language codes it defines (specifically "iw", "ji", and "in") have changed. This constructor accepts both the old codes ("iw", "ji", and "in") and the new codes ("he", "yi", and "id"), but all other API on Locale will return only the OLD codes.

这是构造函数:

public Locale(String language, String country, String variant) {
this.language = convertOldISOCodes(language);
this.country = toUpperCase(country).intern();
this.variant = variant.intern();
}

这是神奇的方法:

private String convertOldISOCodes(String language) { 
// we accept both the old and the new ISO codes for the languages whose ISO
// codes have changed, but we always store the OLD code, for backward compatibility
language = toLowerCase(language).intern();
if (language == "he") {
return "iw";
} else if (language == "yi") {
return "ji";
} else if (language == "id") {
return "in";
} else {
return language;
}
}

它创建的对象是不可变的,因此无法解决这个问题。该类也是 final,因此您不能扩展它,也没有要实现的特定接口(interface)。使其保留这些语言代码的一种方法是围绕此类创建包装器并使用它。

关于locale - JDK Locale 类处理希伯来语 (he)、意第绪语 (yi) 和印度尼西亚语 (id) 的 ISO 语言代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13974169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com