Fulgenzio
Fulgenzio

Reputation:

CakePHP helpers and i18n

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 which 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:

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

can't understand why...

Upvotes: 0

Views: 2386

Answers (1)

Xr.
Xr.

Reputation: 1410

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.

Upvotes: 3

Related Questions