Translations
Localize theme templates with the t tag, locale JSON files, variable arguments, and cardinal and ordinal pluralization
Theme templates can be fully localized with translations so that your store visitors are shown content in their local language. Use the t (translation) tag in your templates to access string translations in the locale files. Learn more about the t tag and theme Locale files.
Using Translations in Practice
The t tag accepts an initial argument that is the key reference to the translation string in a locale file.
<h2>{% t 'customer.orders.order_history' %}</h2>Passing Variable Arguments to Translations
You can pass multiple named arguments to translations through the t tag used in the translation.
<h2>{% t 'customer.profile.welcome_msg' with name=request.user.first_name %}</h2>Pluralization Support
The t tag accepts two arguments for pluralization:
- Pass the count argument with a value for cardinal pluralization, ie 1, 2, 3, 4.
- Pass the index argument with a value for ordinal pluralization, ie First, Second, Third, Forth.
Pluralization rules follow Unicode CLDR specification, available keys include:
oneothertwozerofewmany
Cardinal Pluralization
Cardinal pluralization can be used to display different translations based on the value passed to count.
<h2>{% t 'customer.notifcations.total' with count=notification.count %}</h2>Ordinal Pluralization
Ordinal pluralization can be used to display different translations based on the index value to display the ordering of an object.
<h2>{% t 'customer.orders.orders_msg' with index=customer.orders.count %}</h2>