CakePHP and i18n Helpers

I have some questions about cakePHP, I've googled for a long time for a solution, and since I didn't find it, I'm not sure if I'm taking the right approach.

So I have a file / sitemap which is part of static (xml file - i10n) and dynamic part (database i18n)

I was prompted to cache the menu so that:

  • The component creates an xml cache file of the entire menu for each language if it does not exist

  • The helper creates a cache of the html file formatted from the XML file generated from the component

  • The layout uses a helper to add a menu to the page

Questions:

  • How do I get a list of available languages ​​from the helper and from the component?

  • it

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

    is the correct way to get the actual language?

  • If I import helpers / component in app_controller instead of injecting them into each controller

    class AppController extends Controller {
        var $components = array('menu', 'otherComponent');
        var $helpers = array('menuCache');
    
        function beforeFilter(){
            $this->menu->doSomething();
        }
    }
    
          

I get call to undefined object $html

for echo $html->charset();

in layout

can't figure out why ...

0


a source to share


1 answer


You can use Configure::read('Config.language')

. Part of the CakePHP cookbook reads:

Current language is the current value of Configure :: read ('Config.language'). Config.language is assigned in class L10n - if not already set.



I18n, the class responsible for translating using __()

uses Config.language

, so unless you override it in bootstrap.php

, this variable contains the selected language. In fact, even if you override it, it will still contain the language used (there may be inconsistencies since I10n is unaware of the changes, but I've never encountered them). In the meantime, there is no need to worry about it. ”

For a list of languages ​​you can use L10n::catalog()

. However, I'm not sure if you're after that, as it lists all the languages ​​CakePHP knows about, not just the languages ​​that actually have a translation in app/locale

.

+3


a source







All Articles