Translation keys and the t filter
Hard-coded text strings in template files are not permitted in an internationalized theme. Instead, you must use translation keys and the translation filter (or
Translated string retrieval
The translation filter retrieves the translated content from the locale file for the active language.
When a translation key is passed in a template file:
tfilter uses that key to access the locale file for the active language.
The corresponding string of translated text in the locale file is returned.
If your theme offers English, French, and Spanish, you need a corresponding key for
'blog.comment.email' in each of three locale files:
locales/fr-CA.json (Canadian French)
The returned HTML for these three locale files is:
Interpolation of template key arguments
Any arguments passed to the
t filter can be interpolated, for example:
Passing multiple arguments
You can pass multiple arguments to a
t filter by separating them with commas:
Escaping of translated content
Translated content is escaped by default. Any HTML character is converted into its entity equivalent.
Including HTML in translation keys
To include HTML code in translation keys, append
_html to the end of the key, for example:
HTML characters returned unchanged
.js.liquid asset file, it should always use the
Shopify escapes all translations except those that use
.html. For example, as a result of not using
.html, single quotes and double quotes in a translation will end up being rendered as
" when added with
Pluralization in translation keys
count to the
t filter allows custom pluralization. Supported pluralization keys are:
For more information about pluralization rules in different languages, take a look at the Unicode Language Plural Rules tables.
Values can contain HTML and Liquid objects (through interpolation.) You should limit the presence of these elements in the translation files, to ensure a simple translation process for merchants creating an additional language.
In some cases, you might have to include template elements in the values, to accommodate linguistic and grammatical differences, for example: