0

My site is in 2 languages (english and italian)

My SiteMessagesController.php controller code:

public function index() {
    $this->SiteMessage->locale = 'it';
    $this->SiteMessage->recursive = 0;
    $this->set('siteMessages', $this->paginate());
}

Above code shows all messages in italian language from database. If I comment the 1st line of code, then it will show messages in english.

If I go with this in whole site, I have to write $this->SiteMessage->locale = 'it'; line before $this->ModelName->find(); in each action of each controller.

Is there any way to set $locale to 'it' for each model?

tereško
  • 58,060
  • 25
  • 98
  • 150
gautamlakum
  • 11,815
  • 23
  • 67
  • 90
  • Your question is confusing. I would have guessed @dr Hannibal Lecter's answer was what you were looking for. – Dave Apr 26 '12 at 15:26

2 Answers2

1

If you're asking what I think you're asking, this will do:

Configure::write('Config.language', 'ita');

If you put this somewhere like your AppController::beforeFilter() it should work for the entire app, not individual models or queries. See book on I18n and L10n for more info.

dr Hannibal Lecter
  • 6,665
  • 4
  • 33
  • 42
  • @lakumg: Are you sure you're not overriding something somewhere? The page I linked explicitly claims that this line is all it takes for that to work. – dr Hannibal Lecter Apr 26 '12 at 14:24
  • I am using translate behavior (http://book.cakephp.org/2.0/en/core-libraries/behaviors/translate.html). So your answer will not work with it. – gautamlakum Apr 27 '12 at 06:38
  • 1
    @lakumg: I know you're using the translate behaviour, ergo this: "**Doing this will ensure that both I18n and TranslateBehavior access the same language value.**", from the page I linked. This is exactly what's supposed to work unless you're doing something very special and overriding something somewhere. – dr Hannibal Lecter Apr 27 '12 at 20:34
0

put locale in AppModel.

eg: This one is for english
public $locale = 'en_us';

Saanch
  • 1,814
  • 1
  • 24
  • 38