为什么 Zend_Locale 不支持 zh_HK 或 zh_CN 等缩写格式

发布于 2024-11-25 05:18:28 字数 1149 浏览 1 评论 0原文

我有以下代码段,并尝试使用 Zend 框架和 Zend_Locale() 做一些简单的事情。

    $supported_langs = array(
    'en' => 'English',
    'zh_CN' => '中文(简体)',
    'zh_HK' => '中國(傳統)',
    'es' => 'Español',
    'ja' => '日本',
    'pt' => 'Português',
    'de' => 'Deutsch',
    'ar' => 'العربية',
    'fr' => 'Française',
    'ru' => 'Pусский',
    'ko' => '한국의',
    'hi' => 'हिन्दी',
    'vi' => 'Việt'
);
echo '<pre>';
foreach ($supported_langs as $lang => $desc) { 
    print Zend_Locale::getTranslation($lang, 'language', 'en') . "\n";
}
echo '</pre>';

上面的输出是:

English


Spanish
Japanese
Portuguese
German
Arabic
French
Russian
Korean
Hindi
Vietnamese

zh_CN, zh_HK< /code> 不提供输出。如果我将其中一个 zh 值更改为 zh,它会打印出 中文,我想这是可以的,但不太有效像我希望的那样?

zh_CN 和 zh_HK 是两种不同的语言...我希望能够打印两种语言的翻译...而不会过度简化为中文...

编辑

事实证明,如果我使用 < code>zh_Hans 和 zh_Hant 然后打印出正确的结果。所以我想:

问题:为什么 Zend_Locale 不支持 zh_HK 或 zh_CN 等缩写格式?

I have the following piece of code and am trying to do something simple with the Zend framework and Zend_Locale()

    $supported_langs = array(
    'en' => 'English',
    'zh_CN' => '中文(简体)',
    'zh_HK' => '中國(傳統)',
    'es' => 'Español',
    'ja' => '日本',
    'pt' => 'Português',
    'de' => 'Deutsch',
    'ar' => 'العربية',
    'fr' => 'Française',
    'ru' => 'Pусский',
    'ko' => '한국의',
    'hi' => 'हिन्दी',
    'vi' => 'Việt'
);
echo '<pre>';
foreach ($supported_langs as $lang => $desc) { 
    print Zend_Locale::getTranslation($lang, 'language', 'en') . "\n";
}
echo '</pre>';

The output from the above is:

English


Spanish
Japanese
Portuguese
German
Arabic
French
Russian
Korean
Hindi
Vietnamese

zh_CN, zh_HK don't provide output. If I change one of the zh values to zh, it prints out Chinese, which is Ok, I suppose, but doesn't quite work the way I hoped?

zh_CN and zh_HK are two different languages ... I would like to be able to print the translation for both ...without over simplifying it to just Chinese...

Edit

Turns out, if I use zh_Hans and zh_Hant then it prints out as correct. So I suppose:

Question: why doesn't the Zend_Locale honor the abbreviated formats like zh_HK or zh_CN?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬色的秋千 2024-12-02 05:18:28

计算机本质上是愚蠢的,你必须告诉他们一切。 Zend_Locale 从相当多的 XML 文件中获取其信息以及其中定义的内容。您的中文代码未知,不知道“官方”正确的缩写是什么。

通过以下内容,您可以获取框架中所有支持的语言的列表。

$locale = new Zend_Locale();
$langList = $locale->getTranslationList('language');
array [..
  ['zh']      => 'Chinese'
  ['zh_Hans'] => 'Simplified Chinese'
  ['zh_Hant'] => 'Traditional Chinese'
.. ]

您可以传递第二个 $locale 参数,您将获得该语言的值。默认是浏览器发送的内容。

更新 zh_CN 和 zh_HK 是中国与香港的地区参考,而不是语言!台湾还有 zh_TW

Computer are inherently stupid, you have to tell them everything. Zend_Locale gets its information from quite a bunch of XML files and what is defined there. Your Chinese language codes are not known, dunno what is "officially" the correct abbreviation for this.

With the following you can pull a list with all supported languages in the framework.

$locale = new Zend_Locale();
$langList = $locale->getTranslationList('language');
array [..
  ['zh']      => 'Chinese'
  ['zh_Hans'] => 'Simplified Chinese'
  ['zh_Hant'] => 'Traditional Chinese'
.. ]

You can pass a second $locale argument and you will get the values for the language in that language. The default is what the browser sends.

UPDATE zh_CN and zh_HK are region reference for China versus Hongkong and not languages! There is also zh_TW for Taiwan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文