src/Wasabi.php
public static function loadLanguages($langId = null, $backend = false)
    {
        // Configure all available frontend and backend languages.
        $languages = Cache::remember('languages', function () {
            /** @var LanguagesTable $Languages */
            $Languages = TableRegistry::get('Wasabi/Core.Languages');
            $langs = $Languages->find('allFrontendBackend')->all();

            return [
                'frontend' => array_values($Languages->filterFrontend($langs)->toArray()),
                'backend' => array_values($Languages->filterBackend($langs)->toArray())
            ];
        }, 'wasabi/core/longterm');
        Configure::write('languages', $languages);

        if ($backend === true) {
            // Backend
            $request = Router::getRequest();

            // Setup the users backend language.
            $backendLanguage = $languages['backend'][0];
            if ($request->session()->check('Auth.User.language_id')) {
                $backendLanguageId = $request->session()->read('Auth.User.language_id');

                if ($backendLanguageId !== null) {
                    foreach ($languages['backend'] as $lang) {
                        if ($lang->id === $backendLanguageId) {
                            $backendLanguage = $lang;
                            break;
                        }
                    }
                }
            }

            // Setup the users content language.
            $contentLanguage = $languages['frontend'][0];
            if ($request->session()->check('contentLanguageId')) {
                $contentLanguageId = $request->session()->read('contentLanguageId');
                foreach ($languages['frontend'] as $lang) {
                    if ($lang->id === $contentLanguageId) {
                        $contentLanguage = $lang;
                        break;
                    }
                }
            }
            Configure::write('contentLanguage', $contentLanguage);
            Configure::write('backendLanguage', $backendLanguage);
            I18n::locale($backendLanguage->iso2);
        } else {
            // Frontend
            if ($langId !== null) {
                foreach ($languages['frontend'] as $frontendLanguage) {
                    if ($frontendLanguage->id === $langId) {
                        Configure::write('contentLanguage', $frontendLanguage);
                        I18n::locale($frontendLanguage->iso2);
                        break;
                    }
                }
            } else {
                Configure::write('contentLanguage', $languages['frontend'][0]);
                I18n::locale($languages['frontend'][0]->iso2);
            }
        }
    }
public static function loadLanguages($langId = null, $backend = false)
    {
        // Configure all available frontend and backend languages.
        $languages = Cache::remember('languages', function () {
            /** @var LanguagesTable $Languages */
            $Languages = TableRegistry::get('Wasabi/Core.Languages');
            $langs = $Languages->find('allFrontendBackend')->all();

            return [
                'frontend' => array_values($Languages->filterFrontend($langs)->toArray()),
                'backend' => array_values($Languages->filterBackend($langs)->toArray())
            ];
        }, 'wasabi/core/longterm');
        Configure::write('languages', $languages);

        if ($backend === true) {
            // Backend
            $request = Router::getRequest();

            // Setup the users backend language.
            $backendLanguage = $languages['backend'][0];
            if ($request->session()->check('Auth.User.language_id')) {
                $backendLanguageId = $request->session()->read('Auth.User.language_id');

                if ($backendLanguageId !== null) {
                    foreach ($languages['backend'] as $lang) {
                        if ($lang->id === $backendLanguageId) {
                            $backendLanguage = $lang;
                            break;
                        }
                    }
                }
            }

            // Setup the users content language.
            $contentLanguage = $languages['frontend'][0];
            if ($request->session()->check('contentLanguageId')) {
                $contentLanguageId = $request->session()->read('contentLanguageId');
                foreach ($languages['frontend'] as $lang) {
                    if ($lang->id === $contentLanguageId) {
                        $contentLanguage = $lang;
                        break;
                    }
                }
            }
            Configure::write('contentLanguage', $contentLanguage);
            Configure::write('backendLanguage', $backendLanguage);
            I18n::locale($backendLanguage->iso2);
        } else {
            // Frontend
            if ($langId !== null) {
                foreach ($languages['frontend'] as $frontendLanguage) {
                    if ($frontendLanguage->id === $langId) {
                        Configure::write('contentLanguage', $frontendLanguage);
                        I18n::locale($frontendLanguage->iso2);
                        break;
                    }
                }
            } else {
                Configure::write('contentLanguage', $languages['frontend'][0]);
                I18n::locale($languages['frontend'][0]->iso2);
            }
        }
    }
public static function loadLanguages ( $ langId = null , $ backend = false ) { // Configure all available frontend and backend languages. $ languages = Cache :: remember ( 'languages' , function ( ) { /** @var LanguagesTable $Languages */ $ Languages = TableRegistry :: get ( 'Wasabi/Core.Languages' ) ; $ langs = $ Languages -> find ( 'allFrontendBackend' ) -> all ( ) ; return [ 'frontend' => array_values ( $ Languages -> filterFrontend ( $ langs ) -> toArray ( ) ) , 'backend' => array_values ( $ Languages -> filterBackend ( $ langs ) -> toArray ( ) ) ] ; } , 'wasabi/core/longterm' ) ; Configure :: write ( 'languages' , $ languages ) ; if ( $ backend === true ) { // Backend $ request = Router :: getRequest ( ) ; // Setup the users backend language. $ backendLanguage = $ languages [ 'backend' ] [ 0 ] ; if ( $ request -> session ( ) -> check ( 'Auth.User.language_id' ) ) { $ backendLanguageId = $ request -> session ( ) -> read ( 'Auth.User.language_id' ) ; if ( $ backendLanguageId !== null ) { foreach ( $ languages [ 'backend' ] as $ lang ) { if ( $ lang -> id === $ backendLanguageId ) { $ backendLanguage = $ lang ; break ; } } } } // Setup the users content language. $ contentLanguage = $ languages [ 'frontend' ] [ 0 ] ; if ( $ request -> session ( ) -> check ( 'contentLanguageId' ) ) { $ contentLanguageId = $ request -> session ( ) -> read ( 'contentLanguageId' ) ; foreach ( $ languages [ 'frontend' ] as $ lang ) { if ( $ lang -> id === $ contentLanguageId ) { $ contentLanguage = $ lang ; break ; } } } Configure :: write ( 'contentLanguage' , $ contentLanguage ) ; Configure :: write ( 'backendLanguage' , $ backendLanguage ) ; I18n :: locale ( $ backendLanguage -> iso2 ) ; } else { // Frontend if ( $ langId !== null ) { foreach ( $ languages [ 'frontend' ] as $ frontendLanguage ) { if ( $ frontendLanguage -> id === $ langId ) { Configure :: write ( 'contentLanguage' , $ frontendLanguage ) ; I18n :: locale ( $ frontendLanguage -> iso2 ) ; break ; } } } else { Configure :: write ( 'contentLanguage' , $ languages [ 'frontend' ] [ 0 ] ) ; I18n :: locale ( $ languages [ 'frontend' ] [ 0 ] -> iso2 ) ; } } }
Load and setup all languages.

@param null $langId If set, then the language with id = $langId will be set as the content language.
@param bool|false $backend If true also initializes all backend languages
@return void
Load and setup all languages .