Add {lang} param to all Frontend routes, if the site is multilanguage

Backend routes are excluded

@return $this
8834
public  function addLanguagePrefix()
    {
        $projectConfig = Config::get('project');
        if($projectConfig['multilanguage']) {
            foreach (Route::getRoutes() as $route) {
                foreach($route->methods() as $method){

                    // Only proceed routes that have translate as a middleware
                    // base.homepage routes is handled in a separate method, for language purposes
                    if($method !== 'HEAD' && in_array("translate", $route->middleware()) && strpos($route->getName(), 'base.homepage') === false) {
                        $method = strtolower($method);

                        /**
                         * Declare language route
                         **/
                        // Create default language routes
                        $newRoute = Route::$method('{lang}/'. $route->uri(), $route->getActionName());

                        //set name
                        $newRoute->name($route->getName());

                        //set wheres
                        foreach($route->wheres as $key=>$value){
                            $newRoute->where($key, $value);
                        }

                        //set middleware
                        $newRoute->middleware($route->middleware());

                        //change original route name so they don't mess with new ones :)
                        $route->name(".default");
                    }
                }
            }
        }
        return $this;
    }
536107
function ( key, parameters ) {
			var message = key.toLocaleString();
			// FIXME: This changes the state of the I18N object,
			// should probably not change the 'this.parser' but just
			// pass it to the parser.
			this.parser.language = $.i18n.languages[$.i18n().locale] || $.i18n.languages['default'];
			if( message === '' || message === '*' ) {
				
				if ( ( mode == "php" ) && ( message != '*' ) ) {

					$.post( "svc/backend/i18n/", { missing: key, lang : $.i18n().locale , layout : pageInfo["layout"] } );
				}
				
				message = key;
			}
			var result =  this.parser.parse( message, parameters );
			if ( result.substr(0,6) == 'UTF8: ') result = result.substr(6)
			return result;
		}
1165660
public static function initialiseLang()
        {
            $lang = !empty($_REQUEST['lang']) ? preg_replace('/[^a-zA-Z\-]/', null, $_REQUEST['lang']) : 'en';
            Lang::initialize();
            Lang::set($lang, false);
        }
586990
public function mapPluginsFrontendRoutes()
    {
        foreach(Plugin::activePlugins() as $plugin){
            // Frontend routes
            $frontendRoutes = $plugin->frontendRoutes();
            if($frontendRoutes) {
                \Route::group(
                    [
                    'middleware' => $this->middleware['frontend'],
                    'as' => $plugin->namespaceWithDot().".",
                    'namespace' => $plugin->parseNamespace().'\Controllers',
                    ], function () use ($frontendRoutes) {
                        foreach($frontendRoutes as $file){
                            include $file->getPathname();
                        }
                    }
                );
            }
        }
        return $this;
    }
54461
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);
            }
        }
    }
1333265
protected function addWhereConstraints()
    {
        $this->query->where(
            $this->getQualifiedForeignKeyName(), '=', $this->parent->getKey()
        );

        return $this;
    }
1310153
protected function addParameters()
    {
        if (empty($this->params)) {
            return $this;
        }

        $params = http_build_query($this->params);
        if ($this->options[CURLOPT_POST]) {
            $this->options[CURLOPT_POSTFIELDS] = $params;
            return $this;
        }

        //if there is a question mark in the url
        if (strpos($this->options[CURLOPT_URL], '?') === false) {
            //add the question mark
            $params = '?'.$params;
        //else if the question mark is not at the end
        } else if (substr($this->options[CURLOPT_URL], -1, 1) != '?') {
            //append the parameters to the end
            //with the other parameters
            $params = '&'.$params;
        }

        //append the parameters
        $this->options[CURLOPT_URL] .= $params;

        return $this;
    }
469446
public function index()
    {
        $languages = $this->Languages->find('allFrontendBackend')->hydrate(false);
        $this->set([
            'languages' => $languages,
            'language' => $this->Languages->newEntity()
        ]);
    }
1293635
function addAdresse($params=array())
    {
        $index = count($this->coordonnees);

        if (isset($params['adresse']) && $params['adresse']!='') {
            $this->coordonnees[$index]['adresse'] = $params['adresse'];
        } else {
            $this->coordonnees[$index]['adresse'] = '';
        }

        if (isset($params['link']) && $params['link']!='') {
            $this->coordonnees[$index]['link'] = $params['link'];
        } else {
            $this->coordonnees[$index]['link']='';
        }

        if (isset($params['imageFlag']) && $params['imageFlag']!='') {
            $this->coordonnees[$index]['imageFlag']=$params['imageFlag'];
        } else {
            $this->coordonnees[$index]['imageFlag']='';
        }

        if (isset($params['longitude']) && $params['longitude']!='' && isset($params['latitude']) && $params['latitude']!='') {
            $this->coordonnees[$index]['longitude'] = $params['longitude'];
            $this->coordonnees[$index]['latitude'] = $params['latitude'];
        }

        if (isset($params['setImageWidth'])) {
            $this->coordonnees[$index]['imageWidth'] = $params['setImageWidth'];
        }

        if (isset($params['setImageHeight'])) {
            $this->coordonnees[$index]['imageHeight'] = $params['setImageHeight'];
        }

        if (isset($params['pathToImageFlag']) && $params['pathToImageFlag']!='') {
            $this->coordonnees[$index]['pathToImageFlag']=$params['pathToImageFlag'];
        } else {
            $this->coordonnees[$index]['pathToImageFlag']='';
        }
    }
93617
public function prefixQuery() {
        $options = $this->getOptions();

        if ($this->validateOptions($options)) {

            if (array_key_exists('language', $options)) {
                $this->userLanguage = $this->setLanguageCondition($options['language'], true);
            }
            if (array_key_exists('defaultLanguage', $options)) {
                $this->defaultLanguage = $this->setLanguageCondition($options['defaultLanguage'], true);
            }
            if (array_key_exists('model', $options)) {
                $this->model = $options['model'];
            }
            $this->queryPrefix = $this->initQuery();
        }
        return $this;
    }
641347
private function isMultiLangEnvironment()
    {
        // use the multilanguage parameter, if it exists
        if ($this->container->hasParameter('kunstmaan_admin.multi_language')) {
            return $this->container->getParameter('kunstmaan_admin.multi_language');
        }

        // This is a pretty silly implementation.
        // It just checks if it can find _locale in the routing.yml
        $routingFile = file_get_contents($this->rootDir.'/app/config/routing.yml');

        return preg_match('/_locale:/i', $routingFile);
    }
927693
public function mapBackendRoutes()
    {
        $directory = __DIR__.'/../../routes/backend';
        if(is_dir($directory)) {
            $routeFiles = File::files($directory);
            \Route::group(
                [
                'middleware' => $this->middleware['backend'],
                ], function () use ($routeFiles) {
                    foreach ($routeFiles as $file) {
                        include $file;
                    }
                }
            );
        }
        return $this;
    }
878235
protected function registerRoutes()
    {
        $this->app['router']->group(config('langmanGUI.route_group_config'), function ($router) {
            $router->get('/langman', 'LangmanController@index');

            $router->post('/langman/scan', 'LangmanController@scan');

            $router->post('/langman/save', 'LangmanController@save');

            $router->post('/langman/add-language', 'LangmanController@addLanguage');
        });
    }
1182248
public function addGlobal() {
        foreach ($this->getIndex() as $k => $v) {
            if (null === $v) {
                continue;
            }
            $this->getTwigEnvironment()->addGlobal(str_replace("Interface", "", $k), $this->getProviders()[$v]);
        }
    }
57598
private function registerRoutes()
    {
        $config = $this->app->make('community_translation/config');
        $onlineTranslationPath = $config->get('options.onlineTranslationPath');
        $apiEntryPoint = $config->get('options.api.entryPoint');
        $handleRegex = '[A-Za-z0-9]([A-Za-z0-9\_]*[A-Za-z0-9])?';
        $localeRegex = '[a-zA-Z]{2,3}([_\-][a-zA-Z0-9]{2,3})?';
        $this->app->make(Router::class)->registerMultiple([
            // Online Translation
            "$onlineTranslationPath/{packageVersionID}/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::view',
                null,
                ['packageVersionID' => 'unreviewed|[1-9][0-9]*', 'localeID' => $localeRegex],
                [],
                '',
                [],
                ['GET'],
            ],
            "$onlineTranslationPath/action/save_comment/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::save_comment',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/delete_comment/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::delete_comment',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/load_all_places/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::load_all_places',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/process_translation/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::process_translation',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/load_translation/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::load_translation',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/save_glossary_term/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::save_glossary_term',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/delete_glossary_term/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::delete_glossary_term',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/download/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::download',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/upload/{localeID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::upload',
                null,
                ['localeID' => $localeRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$onlineTranslationPath/action/save_notifications/{packageID}" => [
                'Concrete\Package\CommunityTranslation\Controller\Frontend\OnlineTranslation::save_notifications',
                null,
                ['packageID' => '\d+'],
                [],
                '',
                [],
                ['POST'],
            ],
            // API Entry Points
            "$apiEntryPoint/rate-limit/" => [
                'CommunityTranslation\Api\EntryPoint::getRateLimit',
                null,
                [],
                [],
                '',
                [],
                ['GET'],
            ],
            "$apiEntryPoint/locales/" => [
                'CommunityTranslation\Api\EntryPoint::getLocales',
                null,
                [],
                [],
                '',
                [],
                ['GET'],
            ],
            "$apiEntryPoint/packages/" => [
                'CommunityTranslation\Api\EntryPoint::getPackages',
                null,
                [],
                [],
                '',
                [],
                ['GET'],
            ],
            "$apiEntryPoint/package/{packageHandle}/versions/" => [
                'CommunityTranslation\Api\EntryPoint::getPackageVersions',
                null,
                ['packageHandle' => $handleRegex],
                [],
                '',
                [],
                ['GET'],
            ],
            "$apiEntryPoint/package/{packageHandle}/{packageVersion}/locales/{minimumLevel}/" => [
                'CommunityTranslation\Api\EntryPoint::getPackageVersionLocales',
                null,
                ['packageHandle' => $handleRegex, 'minimumLevel' => '[0-9]{1,3}'],
                [],
                '',
                [],
                ['GET'],
            ],
            "$apiEntryPoint/package/{packageHandle}/{packageVersion}/translations/{localeID}/{formatHandle}/" => [
                'CommunityTranslation\Api\EntryPoint::getPackageVersionTranslations',
                null,
                ['packageHandle' => $handleRegex, 'localeID' => $localeRegex, 'formatHandle' => $handleRegex],
                [],
                '',
                [],
                ['GET'],
            ],
            "$apiEntryPoint/fill-translations/{formatHandle}/" => [
                'CommunityTranslation\Api\EntryPoint::fillTranslations',
                null,
                ['formatHandle' => $handleRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$apiEntryPoint/package/{packageHandle}/{packageVersion}/translatables/{formatHandle}/" => [
                'CommunityTranslation\Api\EntryPoint::importPackageVersionTranslatables',
                null,
                ['packageHandle' => $handleRegex, 'formatHandle' => $handleRegex],
                [],
                '',
                [],
                ['POST'],
            ],
            "$apiEntryPoint/translations/{localeID}/{formatHandle}/{approve}/" => [
                'CommunityTranslation\Api\EntryPoint::importTranslations',
                null,
                ['localeID' => $localeRegex, 'formatHandle' => $handleRegex, 'approve' => '[01]'],
                [],
                '',
                [],
                ['POST'],
            ],
            "$apiEntryPoint/import/package/" => [
                'CommunityTranslation\Api\EntryPoint::importPackage',
                null,
                [],
                [],
                '',
                [],
                ['PUT'],
            ],
            "$apiEntryPoint/{unrecognizedPath}" => [
                'CommunityTranslation\Api\EntryPoint::unrecognizedCall',
                null,
                ['unrecognizedPath' => '.*'],
            ],
            "$apiEntryPoint" => [
                'CommunityTranslation\Api\EntryPoint::unrecognizedCall',
            ],
        ]);
    }
799898
public function langChooser()
    {
        $homepage = $this->repository->findBy('is_home', 1);
        if (!$homepage) {
            app('log')->error('No homepage found.');
            abort(404);
        }
        $locales = TypiCMS::enabledLocales();

        return view('core::public.lang-chooser')
            ->with(compact('homepage', 'locales'));
    }
1348607
public function baseRoute()
    {
        if ($this->baseRoute === null) {
            $this->baseRoute = $this->baseUrl();
        }

        $link   = $this->baseRoute;
        $locale = $this->lang();
        if ($locale !== null) {
            $translator = $this->translator();
            $origLocale = $translator->getLocale();
            $translator->setLocale($this->lang());
            $link = $this->renderTemplate((string)$link);
            $translator->setLocale($origLocale);
        }

        return rtrim((string)$link, '/').'/';
    }