如何将挪威语添加到 setlocale() 中?
我想添加挪威日期。这样我的网站上就可以有两种语言。
根据 PHP 手册,它说
setlocale()的返回值 取决于 PHP 所在的系统 跑步。它返回的正是 系统setlocale函数返回。
如何添加挪威语?
提前致谢。
我想使用 setlocale() 和 strftime() 如下。 (挪威语和英语)
setlocale(LC_TIME, "C");
echo strftime("%A");
setlocale(LC_TIME, "fi_FI");
echo strftime(" in Finnish is %A,");
setlocale(LC_TIME, "fr_FR");
echo strftime(" in French %A and");
setlocale(LC_TIME, "de_DE");
echo strftime(" in German %A.\n");
I want to add Norwegian date. So that I can have two languages on my website.
According to PHP manual, it says that
The return value of setlocale()
depends on the system that PHP is
running. It returns exactly what the
system setlocale function returns.
How can I add Norwegian ?
Thanks in advance.
I want to use setlocale(), and strftime() as followings. (for Norwegian and English)
setlocale(LC_TIME, "C");
echo strftime("%A");
setlocale(LC_TIME, "fi_FI");
echo strftime(" in Finnish is %A,");
setlocale(LC_TIME, "fr_FR");
echo strftime(" in French %A and");
setlocale(LC_TIME, "de_DE");
echo strftime(" in German %A.\n");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果尚未安装,您需要安装挪威语言环境。如何做到这一点取决于您的服务器操作系统。
如果您展示的示例已经可以工作,并且/或者它是挪威服务器,那么它很可能已经安装。我会尝试一下
no_NO
、no_NN
(Nynorsk) 和no_NB
(Bokmål) 之一是否可以解决问题。但另一方面,这些功能严重依赖于底层操作系统的设置,并且解决语言代码/区域设置的方式因系统而异(从而给程序的配置带来了彻底的混乱!),这一事实已经说服了我认为使用像 Zend_Locale 这样的基于 PHP 的库是最重要的更好的选择。
我不确定它对挪威语的支持有多好,但我很确定添加必要的资源很容易。
You would need to install the Norwegian locale, if it isn't installed yet. How to do that, depends on your server OS.
If the examples you show work already, and/or it's a norwegian server, chances are it is already installed. I would try whether one of
no_NO
,no_NN
(Nynorsk) andno_NB
(Bokmål) does the trick.On a side note though, the very fact that these functions rely so heavily on the underlying OS's setup, and the way to address the language codes/locales varies from system to system (thus adding utter chaos to the program's configuration!), have convinced me that using a PHP-based library like Zend_Locale for this is the much better option.
I'm not sure how well norwegian is supported by it out of the box, but I'm pretty sure adding the necessary resources is easy.