Localization
Learn how to translate messages inside CMS themes.
View the Multisite article to learn how to set the active language for your website.
Themes can provide localization keys through files placed in the lang subdirectory of the theme's directory. These localization keys are registered automatically and can be used inside the theme contents or as backend form labels similar to plugin localization.
# Localization File Structure
Below is an example of the theme's lang directory.
├── themes
| └── website
| └── lang
← Localization Directory
| ├── en.json ← Localization File
| └── fr.json ← Localization File
The localization file is a JSON file where strings use the "default" translation of the string as the key. For example, if your application has a French translation, you should create a lang/fr.json
file.
{
"I love programming.": "j'adore programmer"
}
You are also able to define code-based keys by using the complete language key in the JSON file, for example, theme.options.website_name
for the acme theme can be used.
{
"theme.options.website_name": "October CMS"
}
Language strings can be accessed in your theme files using the trans
Twig filter.
View the markup guide to learn more about translation in Twig.
<!-- j'adore programmer -->
{{ 'I love programming.'|trans }}
<!-- October CMS -->
{{ 'theme.options.website_name'|trans }}