Cakephp本地化,在设置DEFAULT_LANGUAGE时无法更改语言 [英] Cakephp Localization, Cannot Change language when DEFAULT_LANGUAGE is set

查看:465
本文介绍了Cakephp本地化,在设置DEFAULT_LANGUAGE时无法更改语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑:)



我在这里使用cakephp中的p18n组件:

http://www.palivoda.eu/2008/04/这个组件要求我在core.php中设置以下常量(例如,以下的常量):


define(DEFAULT_LANGUAGE,'eng')


但是,当设置这个时,我不能用下面的语言改变语言:


,'eng');


根据我的知识,改变静态内容区域设置的唯一方法是使用Configure :: write。但是对于通过使用p28n组件的动态内容来说,我必须将DEFINE_LANGUAGE常量设置为一个值。



这很令人困惑。任何帮助将非常感激。

解决方案

我不熟悉特定的组件,但我做到了手动通过在我的 app / config / bootstrap.php 文件中设置相同的常量,然后设置在我的 AppController (从核心代码复制到 app / app_controller.php )。该控制器的相应片段如下所示:

  uses('L10n'); 

类AppController extends Controller {
public function beforeFilter(){
$ this-> _setLanguage();
/ **
*设置翻译的默认域。域是
*,与给定语言环境目录中的po文件名相同。例如
* __d('homepage','message_id')将在homepage.po中查找
* message_id键。使用__()方便
*函数将总是在default.po中查找。
* /
$ this-> set('domain','default');
}

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

#自动检测请求语言设置
$ this-> L10n-> get();
}
}

很好的香草的东西,但它工作得很好。打开 _setLanguage()方法允许使用不同的方法来确定语言环境(例如子域名如fr.mydomain.com)。


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).

这篇关于Cakephp本地化,在设置DEFAULT_LANGUAGE时无法更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆