依赖 setlocale 并依赖正在安装的语言环境是否可行?

发布于 2024-08-15 19:00:11 字数 546 浏览 10 评论 0原文

我试图用 strftime 生成本地化日期字符串,我使用的占位符是 %x。语言/区域设置为 setlocale(LC_ALL, array('jp','japanese')),但这两个区域设置都不可用,因此它生成了包含不正确字符的字符串。然后,我安装了 ja_JP.utf8 语言环境,并将其指定为数组中的第一个元素,并且解决了我遇到的日期格式问题。

我的问题是,我应该始终依赖安装的语言环境吗?我知道如何将它们安装在我有 root 访问权限的机器上,但如果我没有访问权限怎么办?

我相信 Zend_LocaleZend_Translate 根本不依赖 setlocale 而是以某种方式在内部完成它,这给我的印象是它实际上并不依赖适合企业级应用。

我知道我可能可以在我的应用程序中使用 Zend_LocaleZend_Translate 但它还需要支持 PHP4,至少再一年,这就是为什么我不能仅仅依赖这些。

I was trying to generate a localized date string with strftime, the placeholder I use is %x. The language/locale is setlocale(LC_ALL, array('jp','japanese')), however neither locale was available so it generated a string with improper characters. I then installed the ja_JP.utf8 locale and specified that as the first element in the array and the date formatting issue I had was resolved.

My question is, should I always rely on locales being installed? I'm aware of how to install them on boxes I have root access to, but what if I don't have access?

I believe Zend_Locale and Zend_Translate do not rely on setlocale at all but somehow do it internally, which gives me the impression that it isn't practically feasible for enterprise level applications.

I know I could probably use Zend_Locale and Zend_Translate in my application but it also needs to support PHP4, at least for another year which is why I can't solely rely upon those.

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

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

发布评论

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

评论(3

握住你手 2024-08-22 19:00:11

您可以检查 setlocale 的返回值,至少检查它是否已安装。否则你将会遇到无声的失败:

setlocale(LC_ALL, 'en_US') or die('Locale not installed');

You can check the return value of setlocale and at least check that it was installed. Otherwise you will have silent failures:

setlocale(LC_ALL, 'en_US') or die('Locale not installed');
寻找一个思念的角度 2024-08-22 19:00:11

如果我对 setlocale() 的检查是正确的,那么答案是:不,不。安装的区域设置的范围各不相同,其名称也各不相同,并且最终无法完全确定地预测特定区域设置的可用性。

If my examination of setlocale() is correct, the answer is: No and no. The range of installed locales varies, as does their name, and the availability of a certain locale ultimately cannot be predicted with total certainty.

不可一世的女人 2024-08-22 19:00:11

可行,是的。明智,一点也不!

Feasible, yes. Wise, not at all!

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