-
Notifications
You must be signed in to change notification settings - Fork 37
Multilingual support in LiteCommerce
In LiteCommerce, you can translate both the messages shown from templates and PHP code and the data in your models.
When LiteCommerce is running in connection with Drupal, it uses the language selected by visitor in the Drupal language selector.
To enable translating a label/message, wrap it in a translation function as follows:
-
Inside LiteCommerce template files (it is a good practice to place all messages inside template files):
- Translate to customer language:
{t(#Weight#)} - Translation with replacement:
{t(#My name is {name}#,_ARRAY_(#name#^#test#))} - Translate to specified language:
{t(#Weight#,_ARRAY_(),#de#)}
- Translate to customer language:
-
Inside common LiteCommerce scripts:
- Translate to customer language:
\XLite\Core\Translation::lbl('Weight'); - Translation with replacement:
\XLite\Core\Translation::lbl('My name is {name}', array('name' => 'test')); - Translate to specified language:
\XLite\Core\Translation::lbl('Weight', array(), 'de');
- Translate to customer language:
-
Inside controllers and widget classes, you can use the short notation:
- Translate to customer language:
$this->t('Weight'); - Translation with replacement:
$this->t('My name is {name}', array('name' => 'test')); - Translate to specified language:
$this->('Weight', array(), 'de');
- Translate to customer language:
Messages, wrapped in a translation function like shown above, can be translated by any LiteCommerce module (see Creating LiteCommerce module). In order to do so, the translating module should define the translations in its install.yaml file (it should be UTF-8; use 2 spaces for indentation) as follows (replace “ru” with a two-character ISO 639-1 code of the language you are translating to):
directives: { addModel: 'XLite\Model\LanguageLabelTranslation' }
- { name: 'Weight', translations: [{ code: ru, label: 'Weight (russian)' }] }
- { name: 'Add to cart', translations: [{ code: ru, label: 'Add to Cart (russian)' }] }
- { name: 'Other LC3 message', translations: [{ code: ru, label: 'Your translation' }] }
...
You can use “\n” for inserting line breaks into translations.
The “addModel” directive forces LiteCommerce to import translations for existing labels and messages only. You may remove the directive to have all the records from your YAML file imported.
Although it is not recommended for a translation module, it is possible to store multiple translations in one YAML file as follows:
- { name: 'Weight', translations: [{ code: nl, label: 'Weight (dutch)' }, { code: sv, label: 'Weight (swedish)' }] }
Also, you may write YAML files as follows (recommended to avoid mixing different notations in one file):
- name: 'Weight'
translations:
- code: nl
label: 'Weight (dutch)'
- code: sv
label: 'Weight (swedish)'
Note: Since LiteCommerce v3 is based on the LiteCommerce v2 code, some labels and message are not passed through the translation functions and cannot be translated through YAML files. So, if you notice a label/message of such kind, you can fix it as follows:
-
Submit a ticket at https://bt.litecommerce.com/ and ask us to fix the labels you have found.
-
Fix it in your forked GitHub repository (in a separate branch) and then submit us a Pull Request on adding your changes to the core LiteCommerce repository.
The forms in LiteCommerce are validated using validationEngine jQuery plugin. The error/warning texts for validation messages comes in the separated JS file (validationEngine language pack file).
Since there are already several language pack files for some languages in LiteCommerce distributive you may need your own messages, warning and so on.
For that case your custom translation module must decorate method: \XLite\View\AView::getValidationEngineLanguageFile(). The method should return the system path of your custom validationEngine language file under the "skins/common/" directory.
For example:
file : skins/common/modules/MyCompany/MyTranslation/jQuery.validationEngine-LNG.js
method returns: "modules/MyCompany/MyTranslation/jQuery.validationEngine-LNG.js"
This section is to be written.