Access Site Object

Hi There,

I’m trying something close to what’s described here : Flexible language variables | Kirby CMS

I can’t figure out how to access $site object in a plugin function as i would get a result similar to :

site/plugins/gdt-translations/index.php :

function getVariables() {
    return kirby()->site()->content()->translations()->toObject()->toArray();

site/languages/fr.php :

return [
    'code' => 'fr',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'fr_FR'
    'name' => 'French',
    'translations' => getVariables(),
    'url' => NULL

Actually it results in infinite loading…

Thanks for your help !

You cannot use the site object in this context.

Consider registering your translations in the plugin instead: Translations | Kirby CMS

On a side note, you need to return an array of key-value pairs, but what your function probably returns is a nested array.

Thanks for your reply.

because I need to keep this strings translatables inside the panel, I solved the problem with this :

use Kirby\Data\Txt;

function getVariables($lang) {
    $strings = Txt::decode(
    return Yaml::decode($strings['translations']);