问题描述
我想将我的Symfony 2.5应用程序的语言环境强制设置为ru_RU.UTF-8
.我希望将此语言环境用于strftime()
函数.
I would like to force locale for my Symfony 2.5 application to ru_RU.UTF-8
. I want this locale to be used for strftime()
function.
我的app/config.yml
中具有以下配置:
framework:
default_locale: "ru_RU.UTF-8"
我正在其中一个控制器中使用以下代码来调试此代码:
I'm using the following code in one of my controllers to debug this:
//setlocale(LC_TIME, 'ru_RU.UTF-8');
var_dump(setlocale(LC_TIME, 0));
var_dump(strftime('%B', time()));
die();
当这样执行时,它显示:string(1) "C" string(6) "August"
.
When executed like this, it shows: string(1) "C" string(6) "August"
.
但是,当第一行未注释时,它会显示:string(11) "ru_RU.UTF-8" string(12) "Август"
,因此语言环境已安装在系统中并且可以正常工作.
However, when first line is uncommented it shows: string(11) "ru_RU.UTF-8" string(12) "Август"
, so the locale is installed in the system and works correctly.
我如何使Symfony始终使用配置中指定的语言环境?
Ho do I make Symfony to always use locale specified in the config?
$语言环境-a :
C
C.UTF-8
en_US.utf8
POSIX
ru_RU
ru_RU.iso88595
ru_RU.utf8
推荐答案
Symfony的语言环境设置不会影响PHP设置,它只是一个Symfony设置.
The locale setting for Symfony doesn't influence the PHP settings, it's only a Symfony setting.
您必须使用setlocale()
来配置PHP的语言环境.您可以将其放置在前端控制器(web/app.php
和web/app_dev.php
)中,或为kernel.request创建一个侦听器.
You have to use setlocale()
to configure PHP's locale. You can place this in the front controllers (web/app.php
and web/app_dev.php
) or create a listener for kernel.request.
这篇关于设置Symfony 2.5应用程序的语言环境(强制语言环境)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!