L::get in custom field

I’m in the process of improving the default “textarea” field. The three additional buttons now need a localized label and the modal headline needs to be translated.

It’s easily possible to overwrite the default fields by placing a custom field in the site/fields folder with the same name. But I’m not sure where to put the four additional translations.

The existing buttons use “l::get(‘fields.textarea.buttons.*.label’)” but I don’t want to change any file in the “kirby” or “panel” folders. That would be a pain in the ass when updating.

Other custom fields like the Visual Markdown Editor use a completely different way: manually detecting the panel language and loading the language files.
Is it possible to just add a “languages” folder to the field folder and use “l::get” to get these translations somehow?

I don’t really want to go the complicated path if it’s possible to do it the easy way.

Thank you!

I don’t know but I think that should be a core feature, therefore I created an issue on GitHub. 2.3 is not out yet, so there’s always hope …

1 Like

Just a smart - maybe I’m off with this - but maybe you could use l::set() in the constructor of your custom field’s class?

Thanks for your suggestion, but I couldn’t get it to work. Now I simply used the same approach as the Visual Markdown Editor.

That way I couldn’t translate the modal headline, but at least the buttons are translated. I simply hid the modal headline, it wasn’t that useful anyway.

I’m not going to release this right away, there a few things that need improvement, but here’s the GitHub repository and a preview GIF: https://github.com/medienbaecker/kirby-enhanced-textarea