I’m developing a plugin that allows you to translate SVG files via language variables. I am using a route:
site/plugins/magicsvg/magicsvg.php
:
kirby()->routes([
[
'pattern' => '(:all)/magicsvg/(:all)',
'method' => 'GET',
'action' => function ($lang, $svg) {
$file = kirby()->roots()->languages() . DS . $lang . '.yml';
$contents = file_get_contents($file);
$l = Yaml::read($contents);
header('Content-type: image/svg+xml');
include __DIR__ . '/svg/' . $svg . '.php';
}
]
]);
After that, I can use $l
in any myimage.svg.php
file. However, is there a better way to load the language variables? Can I somehow load them from the Kirby API, so I can support PHP language files alongside YAML?