Custom language variables
When working with a multi-language site, you often need language-specific variables/strings. Simple things like translated button labels for your contact form, for example, or other translatable parts which don't need to be modified by editors. For such cases, Kirby has a built-in language variable management.
Where to store language variables
Language variables can be stored in two places in Kirby:
- As an array of key/value pairs in your language definition files in
/site/languages
- As an array of key/value pairs in a plugin using the
translations
extension
Those arrays can contain as many custom variables as you need.
Manually adding translations in language definition files
Since 4.0.0
Language editor in the Panel
Once you have added one or more languages, you can start adding translation variables via the Language editor. Visit the language you want to edit. You can now add language variables as key/value pairs. These variables will also be stored in the language definition files.
Access to the language editor can be restricted via permissions
Language variables that you add in other languages than the default language will be stored in the default language as well. Language variables added in the default language will only be stored once translated.
If you stored your language variables in separate files as described in this cookbook recipe they will be read by the Panel, but then moved to the language definition files.
Core translation variables and translation variables from plugins are ignored and cannot be overwritten via the Panel.
Using language variables in your template
Those translated variables can be fetched in your template, plugins or snippets with the t()
helper:
You can provide a fallback if the language variable is not defined:
More information
Check out the following cookbook recipes to find out how to make language variables more flexible: