Storefront Locale Files
Storefront locale files have a .json
file extension, and control translations for storefront content. These translations can be edited by sellers through the theme's language editor.
Rather than hard-coded text strings, theme layouts, templates, snippets, and Liquid assets can reference these translations with the Liquid translation filter (t
filter). This returns the appropriate translated string from the locale file for the active language.
Location
Storefront locale files are located in the locales directory of the theme:
└── theme
...
├── config
└── locales
├── en.default.json
├── ar.json
...
Schema
Locale files need to follow a specific naming structure. They also follow a basic organizational structure:
Category: The top-level category of your translations.
Group: The second level grouping of translations within a category.
Translation: The third level, which represents the individual translations.
{
"my_category": {
"my_group": {
"my_translation": "translation text",
// ...
},
// ...
},
// ...
}
File Naming
You can use the 2-letter lowercase language representation to name your locale files.
Language | Format |
---|---|
French | fr.json |
English | en.json |
Arabic | ar.json |
Additionally, you must designate a default locale file for each type.
Default Locale File
You must designate a default locale file in the format of *.default.json
, where *
is your selected language. This file contains the translations for the default language of the theme. Only one default file is permitted.
Example |
---|
en.default.json |
Usage
When working with storefront locale files, you should familiarize yourself with referencing schema translations.
Reference schema translations
To reference translations from the storefront locale file for your theme's active language, you can use translation keys and the Liquid translation filter (t
filter).
For example, let's assume you have locale files for English, Arabic, and French. In this case, you might have the following in each associated locale file:
{
"cart": {
"page": {
"title": "Shopping Cart"
}
}
}
{
"cart": {
"page": {
"title": "عربة التسوق"
}
}
}
{
"cart": {
"page": {
"title": "Panier"
}
}
}
To reference this translation, you might use something like the following:
<span>{{ "cart.page.title" | t }}</span>
The output is customized based on the settings in each locale file:
<!-- English -->
<span>Shopping Cart</span>
<!-- Arabic -->
<span>عربة التسوق</span>
<!-- Frenhc -->
<span>Panier</span>
Placeholder Replacement
Translation strings can use placeholder symbols to insert dynamic values when displayed.
Include the %
symbol or any symbol in your locale file as a placeholder:
{
"layout": {
"header": {
"hello_user": "Hello %!"
}
}
}
When referencing the translation in your theme, use the replace
filter to substitute the placeholder:
{{ 'layout.header.hello_user' | t | replace: '%', 'Mark' }}
This outputs:
Hello Mark!