Developing your Twilight Theme to support multiple languages is known as internationalization, or i18n (18 letters separate the i and n). Twilight i18n provides you with access to translations that are ready made for your Twilight Theme.
Explore our blogs »
Report Bug ·
Request Feature . </Salla Developers> . Official Documentation
Table of Contents
The internationalization feature of Twilight Themes makes it easy to pull out strings in other languages, because it involves separating the texts from the code. This makes it easy for Salla theme developers to support multiple languages. The internationalization files, which are JSON-based files, are located in the locales directory src/locales/
and are used to define translation strings. This directory contains a JSON file for each language supported by the Twilight Theme. For applications with a large number of translatable strings, this strategy is recommended.
Following is the location of the internationalization files within a Twilight Theme:
...
└── src
├── locales
├── ar.json
├── en.json
.....
...
The developer can simply use this Twilight i18n to extend or update the given translation comes with the Twilight default theme.
By browsing the folder Twilight i18n, the developer may download the language translations file that he wants to support in his theme.
You can find a complete list of all the language translation files supported by Twilight here.
For any Twilight Theme, the internationalization files are located in the locales directory src/locales/
, so simply the developer can upload the translation file of the language he is supporting to this path .
The developer has the option to add more strings to his translation files as well as update any of the given translations. This is meant to give better support for the developer to meet his own special needs.
The internationalization file is a JSON string file that consists of a list of key-value pairs, e.g. "Key":"Value"
:
{
"common": {
"titles": {
"home": "الرئيسية"
},
"errors": {
"404": "٤٠٤ الصفحة غير موجودة",
"failed_to_add_into_wishlist": "تعذر الإحتفاظ بالمنتج في قائمة الأمنيات!",
"error_occurred": "حصل خطأ غير متوقع، يرجى إعادة المحاولة",
"field_required": "الحقل :attribute مطلوب"
}
}
}
For retrieving the translation strings, the developer can simply use the default Twig helper trans() function. This helper translates the passed key to the current store language. Retrieving the translation can be done in deafferent ways:
- Simple key:
<!-- simple key -->
<span>{{ trans('common.titles.home') }}</span>
- Key with variable:
<!-- key with variable -->
<span>{{ trans('common.errors.field_required', ['attribute ' => 'البريد']) }}</span>
- Key with enforced locale/language:
<!-- key with enforced locale/language -->
<!-- this will always print the result of key in English even if the store has different default language -->
<span>{{ trans('common.errors.error_occurred', [], en) }}</span>
The team is always here to help you. Happen to face an issue? Want to report a bug? You can submit one here on Github using the Issue Tracker. If you still have any questions, please contact us by joining the Global Developer Community on Telegram or via the Support Email.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
The MIT License (MIT). Please see License File for more information.