views:

561

answers:

1

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.

A: 

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

Rob Wilkerson
thanks man I'll give it a try and she how it goes. Is there any reference to the use of L10n in cakphp? I could not find one.
ion
There surely is. Take a look at i18n and l10n chapter of the docs (http://book.cakephp.org/view/161/Internationalization-Localization). Much of what I did is pulled straight from there. Originally, I had built my stuff to key off of the subdomain, but ended up stripping a lot of that back for simplicity.
Rob Wilkerson
Hey thanks for the answer. I cannot find the code you're using in the cakephp book. Actually I cannot get any definitions from search results for the 'L10n'.
ion
Did you click the link I included in my comment? It takes you right there. No "finding" required. I don't know that the section includes any code, but the ideas I applied came from there.
Rob Wilkerson