translate
Can be used to translate hardcoded texts in your theme, using locale files. It expects you to put a .yml
(YAML) file for each language of your site in the locales
folder. So if your site supports Dutch and English, you should have the following files:
footer:
heading: "Welkom bij de footer"
served_by_plate: "Deze website wordt geserveerd door Plate"
contacts:
phone: "Telefoon"
email: "Email"
footer:
heading: "Welcome to the footer"
served_by_plate: "This site is served by Plate"
contacts:
phone: "Phone"
email: "Email"
When these files are in place, you can use the translate
filter as follows.
On the Dutch version of the site:
Input:
{{ "footer.heading" | translate }}
{{ "footer.contacts.phone" | translate }}
Output:
Welkom bij de footer
Telefoon
On the English version of the site:
Input:
{{ "footer.heading" | translate }}
{{ "footer.contacts.phone" | translate }}
Output:
Welcome to the footer
Phone
Warning: When using ‘yes’ or ‘no’ as key values, YAML parses this as true or false. You have to escape the key value with quotes. See following example:
language:
'no': "Norks language"
⚠️ Warning: When using ‘yes’ or ‘no’ as key values, YAML parses this as true or false. You have to escape the key value with quotes. See following example:
language:
'no': "Norks language"
site:
previous: "Previous"
next: "Next"
month:
january: "january"
february: "february"
march: "march"
april: "april"
may: "may"
june: "june"
july: "july"
august: "august"
september: "september"
october: "oktober"
november: "november"
december: "december"
date:
year: "Year"
month: "Month"
day: "Day"
form:
optional: "Optional"