依靠setlocale和依靠正在安装的语言环境是否可行? [英] Is it feasible to rely on setlocale, and rely on locales being installed?

查看:88
本文介绍了依靠setlocale和依靠正在安装的语言环境是否可行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我的问题是,是否应该一直依赖于安装的语言环境?我知道如何将它们安装在我具有root访问权限的盒子上,但是如果我没有访问权限怎么办?

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?

我相信Zend_LocaleZend_Translate完全不依赖setlocale,而是内部进行某种方式,这给我的印象是,对于企业级应用程序来说,这实际上是不可行的.

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.

我知道我可能会在我的应用程序中使用Zend_LocaleZend_Translate,但是它还需要支持PHP4,至少要再过一年,这就是为什么我不能完全依靠它们的原因.

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.

推荐答案

如果我对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.

这篇关于依靠setlocale和依靠正在安装的语言环境是否可行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆