This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi! I have a YAML file with options to be used in a dropdown menu
workspaces.yaml
school: author.plugin::lang.workspace.school
home: author.plugin::lang.workspace.home
office: author.plugin::lang.workspace.office
In my lang file plugins/author/plugin/lang/en/lang.php I have:
return [
'workspace' => [
'school' => 'School',
'home' => 'In my home',
'office' => 'I prefer my office',
],
];
I use the ParseFile yaml function in order to get the content file
public function populate()
{
$parser = new Yaml;
$path = plugins_path() . '/author/plugin/additional/populate/workspaces.yaml';
$options = $parser->ParseFile($path);
return $options;
}
The next step is use the populate function in the onRun() function component in order to pass the options to the front end
public function onRun()
{
$this->page['workspaces'] = $this->myOwnClass->populate();
}
Everything in the process works great, except the translation. The string author.plugin::lang.workspace.school pass as it is to the front end, without be translated.
What is going on? :S
mjauvin said:
Try this maybe:
use Yaml; Yaml::parseFile(...);
Hi, thank you for your answer, unfurnetly the parseFile is a non static method, so I can't use it as you sugest.
About the php tag, it's open. The lang file is used across the plugin with other translations.
Well, it's solved.
For an unknown reason, the localization strings doesn't work in the yaml files that are located outside the controllers and models folders.
That's way the parse function gets the string author.plugin::lang.workspace.school without be translated.
I modified my populate function; I parse the yaml and use a foreach to translate the string
public function populate($who)
{
$parser = new Yaml;
$path = plugins_path() . '/author/plugin/additional/populate/workspaces.yaml';
$options = $parser->ParseFile($path);
foreach ($options as $key=>$value) {
$options[$key] = Lang::get($value);
}
return $options;
}
1-6 of 6