开发者

Cakephp Localization, Cannot Change language when DEFAULT_LANGUAGE is set

I am confused :)

I'm using the p18n component in cakephp found here:

http://www.palivoda.eu/2008/04/i18n-in-cakephp-12-database-content-translation-part-2/

This component requires me to set in core.php 开发者_运维知识库the following constant:

define("DEFAULT_LANGUAGE", 'eng')

However when this is set I cannot change the language using:

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

At the moment, into my knowledge, the only way to change the locale of my static content is the use of the Configure::write. But for the dynamic content to change through the use of the p28n component I must have the DEFINE_LANGUAGE constant set to a value.

This is all very confusing. Any help will be much appreciated.


I'm not familiar with particular component, but I've done this "manually" by setting the same constant in my app/config/bootstrap.php file and then setting the "actual" language to be used in my AppController (copied from the core code to app/app_controller.php). The appropriate snippets of that controller look like this:

uses ( 'L10n' );

class AppController extends Controller {
  public function beforeFilter() {
    $this->_setLanguage();
    /**
     * Set the default "domain" for translations. The domain is the
     * same as the po file name in a given locale directory. e.g.
     * __d ( 'homepage', 'message_id' ) would look for the
     * message_id key in homepage.po. Using the __() convenience
     * function will always look in default.po.
     */
    $this->set ( 'domain', 'default' );
  }

  private function _setLanguage() {
    $this->L10n = new L10n();

    # Auto-detect the request language settings
    $this->L10n->get();
  }
}

Pretty vanilla stuff, but it works great. And breaking out the _setLanguage() method allows for the use of different methodologies to determine locale (e.g subdomain like fr.mydomain.com).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜