Skip to content

SallaApp/twilight-i18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation


Logo

Twilight i18n

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
  1. Overview
  2. Usage
  3. Support
  4. Contributing
  5. Credits
  6. License

Overview

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
      .....
...

Usage

The developer can simply use this Twilight i18n to extend or update the given translation comes with the Twilight default theme.

Download

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.

Upload

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.

Translation retrieval

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>

(back to top)

Support

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.

(back to top)

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Credits

(back to top)

License

The MIT License (MIT). Please see License File for more information.

(back to top)

Releases

No releases published

Packages

No packages published