Manage language variables by structure field

I’m trying to manage language variables in the panel using a structure field like it’s suggested here:

function getVariables($lang = null) {
   /* here you can fetch your variables from anywhere:
   ** a spreadsheet, a .csv file, or
   ** from a structure field that you can edit in the Panel
   */
   $translations = [];
   return $translations;
}

It’s probably a stupid question, but how can I actually access the structure field within this function and build the translations array?

The structure field is located in site.yml, but trying to access it using kirby()->site() results in fatal error: allowed memory size exhausted.

That should not happen. Could you post the complete code you tried?

Sure. I call the function in languages/de:

return [
    'code' => 'de',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'de_DE'
    ],
    'name' => 'Deutsch',
    'translations' => getVariables('de')
];

Which is defined in plugins/translations/index.php

function getVariables($lang = null) 
{
	$test = kirby()->site()->test();
	$translations = [
		'jahr' => $test
	];		
	return $translations;
}

Here I use a standard text-field test() instead of a structure field.

Ah, yes, maybe it’s not possible like this after all, because the function is called in the translation file, so a problem similar to calling kirby and site in the config.

There is a plugin you might be interested in: https://github.com/rasteiner/k3-trevor-view

Thank you. So there’s no way to make this approach work? Ok, I’ll check out the plugin or simply use a yaml file.

I have to think about this later, and if there is no way, I will update the cookbook recipe.