Accessing the language files from a router / multilang router problem

Hey guys,

I already read this issue: Routes and multi-language sites issue, but this only helped me half. Here’s my scenario: I want to display content in a modal. Therefore I’m using an ajax call and kirby’s routing, because this kind of content is always in a modal and shouldn’t be visible in the panel or accessible via the url. The router needs to set a language, so the currently used language code is put into the url. But nevertheless I can’t get access to my language files in site/languages – the returned value is always null. Is there a fix or workaround to this kind of problem? I guess it would be to use a normal page instead of routes, but as I said I really don’t want those pages to appear in the panel.

Thanks for your help guys,
Jakob

If anyone is interested in my solution: the current language is part of the url the router uses, as a last parameter (can also be a get variable or a kirby parameter). Then I just include the correct language file, before including the corresponding template for the given url. My router looks something like this (simplified):

kirby()->routes(array(
    array(
        'pattern' => 'modals/(:any)/(:any)',
        'action'  => function($template, $lang){
            // Kirby throws an error if the language isn't set.
            site()->visit('', $lang);

            // Include the language file.
            include_once(kirby()->roots()->languages() . DS . str::lower($lang) . '.php');

            // Include the template.
            include_once(__DIR__ . DS . 'templates' . DS . $template . '.php');

            exit;
        }
    )
));
1 Like