i18n/gettext : Web 应用程序中的 setlocale 配置

发布于 2024-08-14 21:21:42 字数 1286 浏览 4 评论 0原文

所以我开始摆弄 gettext 但我仍然对某些事情感到困惑,如果有人能帮助我并填补我的空白,那就太好了。

  1. 通常大多数实现只是根据语言参数调用setlocale。是否有任何情况需要使用 putenv,也许是 Windows 设置上的边缘情况?

  2. 我的 php 框架的默认语言是英语,UTF-8 - 因此我将 LC_ALL 设置为 en_US.utf-8,因为 en_US< /code> 是 ISO-8859-1/Latin1 ,显然这不像 UTF-8 那样支持?

  3. 调用 setlocale(LC_ALL, 'en_US.utf-8') 后是否有我应该了解的问题?由于它改变了所有这些:LC_COLLATE、LC_CTYPE、LC_MONETARY、LC_NUMERIC、LC_TIME 和 LC_MESSAGES - 我是否必须更新任何脚本,例如生成时间或类似内容的脚本

  4. 假设新配置的服务器没有配置 es_ES.utf-8 语言环境,我知道如何生成语言环境,但如果它不可用,那么我应该在大批?如果有人可以提供一个实际的例子,例如:

    setlocale( LC_ALL, array('es_ES.UTF-8', 'es_ES', 'es') )

    是否有某种网站提供此类示例,或者人们通常会自己提出优先级排序?

  5. 我在某处读到,localei18n 文件夹的通常结构如下所示。

    结构真的很重要吗?似乎所有发生的事情都是当您执行 bindtextdomain('messages', 'locale') 时,它会递归地在该目录中搜索 messages.mo,我可能没有注意到,但是它可能会考虑目录。

我对结构应该有多严格?

locale
  en_US
      LC_MESSAGES
         messages.po
  es_ES
      LC_MESSAGES
         messages.po


    6. 我是否应该尝试测试系统是否确实支持该语言环境?因为例如,如果服务器没有区域设置,并且我尝试使用 setlocale 设置它,它不会出错或出现任何问题,它只会默默地让它过去。

So I started messing around with gettext but I'm still puzzled about certain things, would be great if anyone could help me out and fill in the gaps for me.

  1. Usually most of the implementations just invoke setlocale based on a language parameter. Is there any case in which I need to use putenv, perhaps for edge cases on Windows setups?

  2. The default language for my php framework is English, UTF-8 - so I'd set LC_ALL to en_US.utf-8, since en_US is ISO-8859-1/Latin1 and obviously that's not as supportive as UTF-8?

  3. Are there any gotchas I should know about after invoking setlocale(LC_ALL, 'en_US.utf-8')? Since it changes all of these: LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, and LC_MESSAGES - will I have to update any scripts for example, that generate time or something like that?

  4. Let's say for example a freshly configured server did not have es_ES.utf-8 locale configured, I know how to generate the locale but if it wasn't available then should I provide backups in an array? Would be great if someone could provide a practical example, like:

    setlocale( LC_ALL, array('es_ES.UTF-8', 'es_ES', 'es') )

    Is there some sort of website that offers examples such as this, or do people usually come up with the priority ordering themselves?

  5. I read somewhere that the usual structure of the locale or i18n folder is something like below.

    Does the structure really matter? It seems like all that's happening is when you do bindtextdomain('messages', 'locale') it recursively searches that directory for messages.mo, I might not be noticing but it might be taking the directories into account.

How strict should I be with the structure?

locale
  en_US
      LC_MESSAGES
         messages.po
  es_ES
      LC_MESSAGES
         messages.po

   6.  Should I even bother with trying to test whether the system actually supports the locale or not? Because for example, if a server didn't have a locale and I attempted to set it with setlocale it wouldn't error out or anything, it would just silently let it go by.

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

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

发布评论

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

评论(1

时光礼记 2024-08-21 21:21:42

这不是对你的问题的合格答案,我并不是说使用 gettext 不好 - 我从来没有足够多地使用它来对它有一个真正深刻的看法 - 但我决定不理会 gettext因为它的复杂性和在不同地区不同平台上的巨大不可预测性。我发布了一个寻找替代方案的问题此处,虽然有周围并不多,Zend_translate 包似乎值得一看。我自己还没有抽出时间来做这件事。

如果您使用 gettext,请务必查看关于 Gettext 的 PHP 手册用户贡献注释

This is not a qualified answer to your question, and I'm not saying using gettext is bad - I never worked enough with it to have a really deep opinion on it - but I decided to leave gettext alone because of its complexity and massive unpredictability on different platforms with different locales. I posted a question looking for alternatives here and while there is not really much around, the Zend_translate package seems to be worth a look. I haven't got around to it myself yet.

If you work with gettext, be sure to check out the PHP Manual User Contributed Notes on Gettext.

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