kirby-staticbuilder
kirby-staticbuilder copied to clipboard
Empty translations when rendering pages
Bug report: https://forum.getkirby.com/t/staticbuilder-kirby-as-a-static-site-generator/4084/26
So basically how the l::set
and l::get
system works in Kirby:
-
L::$data
is an empty array. - On page load for multilang websites, Kirby identifies the current language from the URL (e.g.
/fr/foo/bar
) and loads the corresponding PHP file insite/languages/fr.php
. - In this file, using the L class instead of the C class (
c::set
) is just convention. There's nothing special about it. It's a static class with an array and the get/set methods.
When rendering from /staticbuilder/
, Kirby does not set the current language and does not load this language-specific config file. We then go to great lengths to set the page's language when rendering each version, but don't load those files either. Not sure what would be a decent solution. :/
Possible workaround, in e.g. site/snippets/header.php
:
<?php
// make sure to load the translations for each page
$langfile = $kirby->roots()->languages() . '/' . $site->language()->code() . '.php';
if (file_exists($langfile)) {
include $langfile;
}
The work around works! Merci!
Ref the workaround code above, I found that it only worked on the home/index page. To get it to work on sub pages I had to include
rather than include_once
.
<?php
// make sure to load the translations
$langfile = $kirby->roots()->languages() . '/' . $site->language()->code() . '.php';
if (file_exists($langfile)) include $langfile;
?>
Good catch, thanks.