Is it feasible to rely on setlocale, and rely on locales being installed?(依赖 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_Locale
和 Zend_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_Locale
和 Zend_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() 的检查是正确的,那么答案是:No and no.安装的语言环境的范围各不相同,它们的名称也是如此,并且最终无法完全确定地预测某个语言环境的可用性.
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 并依赖安装的语言环境是否可行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:依赖 setlocale 并依赖安装的语言环境是否可行?
基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01