Spree is ready out of the box to make your brand a global one.
default_locale
attribute. Alongside that, you can also set supported_locales
which will enable multi-language capabilities for that Store.
You can change both in the Admin Panel in Configurations -> Store
or via rails console / API.
en
,es-MX
etc - full list of supported locales is available in the Spree I18n GitHub repository..default_currency
attribute. Alongside that, you can also set supported_currencies
which will enable multi-currency capabilities for that Store.
You can change both in the Admin Panel in Configurations -> Store
or via rails console / API.
USD
, CAD
, EUR
Resource | Translatable Fields |
---|---|
Product | name , description , slug , meta_description , meta_keywords , meta_title |
Taxon | name , description , permalink |
Taxonomy | name |
Option Type | presentation |
Option Value | presentation |
Property | presentation |
Product Property | value |
Store | name , meta_description , meta_keywords , seo_title , facebook , twitter , instagram , customer_support_email , description , address , contact_phone |
spree_product_translations
.
TranslatableResource
module, which sets the default scope for the resource to i18n
. This makes it so that when querying the translatable resource on a translatable field, Mobility will know to search in the translation tables. Read more about querying translatable fields and the i18n scope in the Mobility docs.
Due to some shortcomings of the Mobility gem, not all Active Record Query Interface methods work with translations. This includes:
distinct
when ordering by a translated field raises an error. To work around this, explicitly select the translated field that you are ordering by. For example, instead of Spree::Product.order(:name).distinct
do Spree::Product.select(:name).order(:name).distinct
first_or_create
or first_or_initialize
on a clause that checks for a translated field does not work correctly with Mobility. For example, the following line of code will not perform as expected: Spree::Product.where(name: ‘Denim Shirt').first_or_create!
Instead, you’ll need to rewrite it as an if statement that calls either first
or create
like so:Spree::Product.joins(:taxons).where(taxons: {name: "30% Off"})
. Instead, you can make use of the join_translation_table
method in in the TranslatableResourceScopes
Module. The above query can be rewritten like this:spree_i18n
projectconfig/locales
. Each YAML file contains one top level key which is the language code for the translations contained within that file. The following is a snippet showing the basic layout of a locale file:
spree
key so that they don’t conflict with translations from other parts of the parent application.
Please submit Pull Requests or issues directly to Spree I18n for missing translations.
config/locales/ru.yml
.
Spree has over 43 locale files and counting. See the GitHub Repository for a complete list.
spree_i18n
gem.
You don’t need to copy any files from spree_i18n
or rails-i18n
for their translations to be available within your application. They are made available automatically, because both spree_i18n
and rails-i18n
are railties.
Spree.t()
helper method looks up the currently configured locale and retrieves the translated value from the relevant locale YAML file. Assuming a default locale, this translation would be fetched from the en translations collated from the application, spree_i18n
and rails-i18n
. Its relative key within those translation files would need to be this:
config/locales
directory where developers can include YAML files for each language they wish to support.
We strongly urge all extension developers to ensure all customer facing text is rendered via the Spree.t()
helper method even if they only include a single default language locale file (as other users can simply include the required YAML file and translations in their site extension).