fvsch / kirby-staticbuilder

Static HTML exporter for Kirby CMS (v2 only)
MIT License
112 stars 8 forks source link

Empty translations when rendering pages #27

Open fvsch opened 7 years ago

fvsch commented 7 years ago

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:

  1. L::$data is an empty array.
  2. 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 in site/languages/fr.php.
  3. 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;
}
PaulMorel commented 7 years ago

The work around works! Merci!

shoesforindustry commented 7 years ago

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;
?>
fvsch commented 7 years ago

Good catch, thanks.