9

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

  • 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'.

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
kgilden
  • 10,336
  • 3
  • 50
  • 48
  • \Locale::getDefault() won't execute this method, as it's provided by the PHP. The Locale class being used by Symfony is not \Locale, rather than \Symfony\Component\Locale\Locale which extends the \Locale. – Nikola Petkanski Apr 05 '12 at 11:22

2 Answers2

18

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
Ryall
  • 12,010
  • 11
  • 53
  • 77
Flask
  • 4,966
  • 1
  • 20
  • 39
  • Kudos! I skimmed that place over many times and since it had session: { default_locale: %locale% } I assumed it took the value from parameters.ini. It works. – kgilden Aug 08 '11 at 21:39
  • 9
    this is outdated. its now a setting of the framework config: `framework: default_locale: %locale%` – ivoba Jul 18 '12 at 08:15
6

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.

enigma
  • 493
  • 2
  • 5
  • 18