Storefront Localization Files
Storefront localization files are JSON files with the .json
file extension. These files contain the translation strings for content shown on the storefront throughout the theme. Merchants can access these translations through the SHOPLINE language editor.
Within the theme's layout, templates, snippets, and sections, you can use the Handlebars translation helper (t
helper) to reference these translations. This ensures the text is translated according to the store's default language, rather than using hard-coded text strings.
Using the t
helper allows you to insert dynamic values.
Location
Storefront localization files are located in the locales
directory of the theme:
└── theme
...
└── locales
├── en.json
...
Structure
Storefront localization files must follow a specific naming structure and adhere to a basic organizational hierarchy:
- Products: The top-level products of translations.
- Product_list: The second-level grouping within the products.
- Load_more_tip: The third level, representing individual
{
"products": {
"product_list": {
"load_more_tip": "custom text",
...
},
...
},
...
}
When naming translation descriptions, be descriptive enough to provide context for the translation. For example, order.order_details.insuranceService_content_email
offers more context than order.order_details.email
.
File Naming
Localization files must follow the standard IETF language tag naming convention, where the first lowercase code represents the language, followed by .json
. For example:
Language | Storefront |
---|---|
English | en.json |
Indonesian | id.json |
Thai | th.json |
Exceptions for Simplified and Traditional Chinese are:
Language | Storefront |
---|---|
Chinese (Simplified) | zh-hans-cn.json |
Chinese (Traditional) | zh-hant-tw.json |
Content
To ensure proper translation mapping and simplify the translation process for merchants, the organizational structure for multilingual files should reflect the theme structure.
For instance, the first two tiers of the structure might be as follows:
Level 1 | Level 2 |
---|---|
gift_cards | title, terms of use |
blogs | articles, article comments, blog sidebar |
home_page | blank slate, featured, help |
contact | contact form, form errors |
products | products, product-related |
layout | general field titles and identifiers |
cart | cart content, update, notes, checkout link |
customer | Account, orders (summary and detail), account setup, addresses, sign-in, password, registration |
general | 404, breadcrumbs, search (results and empty state), pagination |
collection | collections, collection-related |
When using translations in snippets, group them with the category most pertinent to the snippet's role. For example, if you have a related-products.html
snippet, any related translations should be included in the products
group.
Usage
When using store localization files, keep the following in mind:
Reference Storefront Translations
Using the key
and the Handlebars translation helper (t
), you can reference translations from the theme file corresponding to the store's current language.
Assuming you have multilingual configuration files for English, French, and Spanish, with each containing the following:
/locales/en.default.json (English)
:
{
"products": {
"product_list": {
"load_more_tip": "Loading more items"
}
}
}
/locales/id.json (Indonesian)
:
{
"products": {
"product_list": {
"load_more_tip": "Muat lebih banyak proyek"
}
}
}
/locales/th.json (Thai)
:
{
"products": {
"product_list": {
"load_more_tip": "โหลดรายการเพิ่มเติม"
}
}
}
To reference this translation, you can use the following:
<span></span>
When referencing translation keys in Handlebars, you must enclose them in single ('') or double ("") quotes.
The output will be defined by each multilingual file configuration:
// English
<span>Loading more items</span>
// Indonesian
<span>Muat lebih banyak proyek</span>
// Thai
<span>โหลดรายการเพิ่มเติม</span>
Insert Dynamic Values
Multilingual copy supports interpolation, allowing you to include variables within strings that are dynamically filled when referenced in Handlebars.
For example, you can include the following in a multilingual file:
/locales/en.json
:
{
"blog": {
"comment": {
"single_count": "{{count}} comments"
}
}
}
When you refer to this translation in your theme, you can set values for the count
variables:
/sections/main-article.html
:
<h2>
</h2>
Assign values of 5 to count, this code outputs:
<h2>5 comments</h2>