kirby-staticbuilder icon indicating copy to clipboard operation
kirby-staticbuilder copied to clipboard

Empty translations when rendering pages

Open fvsch opened this issue 8 years ago • 3 comments

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;
}

fvsch avatar Feb 09 '17 23:02 fvsch

The work around works! Merci!

PaulMorel avatar Feb 10 '17 19:02 PaulMorel

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;
?>

shoesforindustry avatar Jul 11 '17 07:07 shoesforindustry

Good catch, thanks.

fvsch avatar Jul 11 '17 07:07 fvsch