更改Symfony2中的默认语言环境 [英] Change default locale in Symfony2
问题描述
我正在尝试更改应用程序的默认语言环境.到目前为止我尝试过的事情:
I'm trying to change the default locale of my application. Things I've tried so far:
- 将intl.default_locale设置为"et_EE"
- 在
app/config/parameters.ini
中将语言环境设置为"et"
- 在此处中所述,更改了我的包的boot()方法中的默认语言环境. li>
- 实现了扩展StubLocale并覆盖方法getDefault()以返回'et_EE'的类Locale.
- set intl.default_locale to 'et_EE'
- set locale to 'et' in
app/config/parameters.ini
- Changed the default locale in my bundle's boot() method described here
- Implemented a class Locale that extends StubLocale and overwrites method getDefault() to return 'et_EE'.
这里是实现.调用\Locale::getDefault()
不会执行此方法,因此Locale类似乎没有被覆盖.
Here is the implementation. The Locale class does not seem to be getting overwritten as calling \Locale::getDefault()
doesn't execute this method.
<?php
use Symfony\Component\Locale\Stub\StubLocale;
class Locale extends StubLocale
{
static public function getDefault()
{
return 'et_EE';
}
}
尝试了所有描述的方法之后,\Locale::getDefault()
仍然返回en
.我需要它返回et_EE
,以在适当的语言环境中呈现表单小部件,例如国家或语言.
After trying all these methods described, \Locale::getDefault()
still returns en
. I need it to return et_EE
to render form widgets, such as country or language, in the proper locale.
我将如何去做?以后能够支持多个语言环境也将很棒.谢谢.
How would I go doing this? Being able to support multiple locales later would also be great. Thanks.
推荐答案
在Symfony 2.0中:
In Symfony 2.0:
# app/config/config.yml
framework:
session: { default_locale: en }
在Symfony 2.1+中:
In Symfony 2.1+:
# app/config/config.yml
framework:
default_locale: en
这篇关于更改Symfony2中的默认语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!