views:

716

answers:

1

Hi, i have some questions about cakephp, i spent long time googling for a solution and as i didn't find any i'm not sure i'm taking the right approach.

So, i have a menu/sitemap wich is part static (xml file - i10n) and part dynamic (database i18n)

i've been asked to cache the menu so that:

  1. A component creates a cache xml file of the whole menu for each language if it doesn't exist

  2. An helper creates a cache html formatted from the xml file created from the component

  3. The layout uses the helper to add the menu in the page

Questions: - How do i get the list of available languages from the helper and from the component?

  • Is this

$this->L10n = new L10n(); $this->L10n->lang

the correct way to get the actual language?

  • if i import the helpers/component in the app_controller instead of typing them in each controller

    class AppController extends Controller { var $components = array('menu', 'otherComponent'); var $helpers = array('menuCache');

    function beforeFilter(){ $this->menu->doSomething(); } }

i get a "call to undefined object $html" for the echo $html->charset(); in the layout

can't understand why...

thanks for your help

+2  A: 

You can use Configure::read('Config.language'). A part of the CakePHP cookbook states:

The current locale is the current value of Configure::read('Config.language'). The value of Config.language is assigned in the L10n Class - unless it is already set.

I18n, the class responsible for translation using __(), uses Config.language so, unless you override it in bootstrap.php, that variable contains the selected language. Actually, even if you override it, it will still contain the used language (there might be inconsistencies because I10n is not really aware of the change but I never ran into any).

To get a list of languages, you can use L10n::catalog(). I'm not sure it's what you're after, however, since it lists all languages CakePHP knows about, not only the languages that actually have a translation in app/locale.

Xr