kgilden
kgilden

Reputation: 10346

Change default locale in Symfony2

I'm trying to change the default locale of my application. Things I've tried so far:

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';
    }
}

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.

Upvotes: 9

Views: 21899

Answers (2)

In Symfony 2.0, you can set default_locale for the session too:

framework:
  translator:      { fallback: %locale% }
  ...
  session:
    default_locale: %locale%
    auto_start:     true

The %locale% is a variable, and it's resolved from the parameters.ini file.

Upvotes: 6

Flask
Flask

Reputation: 4996

In Symfony 2.0:

# app/config/config.yml
framework:
  session: { default_locale: en }

In Symfony 2.1+:

# app/config/config.yml
framework:
  default_locale: en

Upvotes: 18

Related Questions