Salla Docs
Merchant API
  • Merchant API
  • Salla OAuth 2.0
Partner APIs
  • App API
  • Shipment API
Storefront
  • Twilight Engine
  • Twilight SDK
  • Web Components
  • Change Log
Salla CLI
Merchant API
  • Merchant API
  • Salla OAuth 2.0
Partner APIs
  • App API
  • Shipment API
Storefront
  • Twilight Engine
  • Twilight SDK
  • Web Components
  • Change Log
Salla CLI
Salla - Opensource
Salla - Developers Community
  1. Twilight SDK
  • Overview
  • Languages
  • Notify
  • Event
  • Storage
  • Configuration
  • Forms
  • Helpers
  • Auth
    • Login
    • Logout
    • Verify
    • Resend
    • Register
    • Refresh
  • Cart
    • Latest
    • Details
    • Quick Add
    • Add Item
    • Delete Item
    • Delete Image
    • Add Coupon
    • Remove Coupon
    • Get Upload Image
    • Get Quick Order Settings
    • Create Quick Order
    • Order Status
    • Get Current Cart Id
    • Price Quote
  • Wishlist
    • Add
    • Remove
    • Toggle
  • Loyalty
    • Get Program
    • Exchange
    • Reset
  • Comment
    • Add Comment
    • Fetch
    • Get Page Comments
    • Get Product Comments
  • Profile
    • Update profile
    • Update contact
  • Product
    • Get price
    • Product availability
    • Categories
    • Offer details
    • Search products
    • Get Gift Details
    • Add Gift To Cart
    • Upload Gift Image
    • Get Product Details
    • Fetch
    • Fetch Options
    • Size Guides
  • Order
    • Create cart from order
    • Cancel
    • Send invoice
    • Show order
  • Booking
    • Add
  • Rating
    • Order
    • Store
    • Products
    • Shipping
  • Currency
    • Change
    • List
  • Component
    • Reviews
    • Menus
  1. Twilight SDK

Languages

Salla theme developers can easily support other languages thanks to the Twilight's localization function, which makes it simple to extract text in a selected language.
In the previous article, we explained how to perform localization within the Twilight theme engine.
INFO
✅ Twilight JS SDK provides API methods meant to ease the access to the store's transaltions.
✅ The theme's languages are all loaded by default when the SDK is initialized via salla.init().
In this article, we are going to talk about using the Twilight JS SDK for setting and getting a store's translation in action. 

📙 What you'll learn#

Usage
Getting transaltion
Setting transaltion

Usage#

The locales directory /locales/ contains the localization files, which are JSON-based files that define translation strings. Each of these is a collection of key-value pairs found in a JSON string file, such as "Key":"Value."
The following is an example of a locale file:
TIP
Supporting multiple languages is known as internationalization, or i18n (18 letters separate the i and n). Twilight i18n provides the developer with access to many translations that are ready made for your Twilight Theme. The developer can find a complete list of all the language translation files supported by Twilight here
Mainly, the Twilight JS SDK offers two methods to manage the translations, get() and set().

Getting transaltion#

The get() method can be used to retrieve text from the locale file. It needs only one parameter, which is key of that text. For example, in the previous code, the developer might return the text "Free Shipping" as follows:

Setting transaltion#

The set() method can be used to change the translation of text in the locale file. It needs two parameters, the key of that text and the value that will be stored for that text. For example, in the previous code, the developer may change the text "Remember my choice" as follows:
WARNING
This updates an existing key of the current locale

Events#

In some scenarios, the developer may need to retrieve some translations upon the completion of the loading. In such a case, the event "onLoaded()" may be invoked as follows:

Adding New Translations#

Using Single Key Path#

The add() method can be used to add a new translation key path to multiple locales. It needs two parameters, which is the key of the text to be translated, and the object that contains the translation of the key in multiple locales. For example, the developer can add the text "New Order" to different locales as follows:

Using Bulk Key Paths#

The addBulk() method can be used to add more than one new translation key paths to multiple locales. It needs one parameter, which is the object containing multiple keys and their corresponding translations in different locales. For example, the developer can add the texts "New Order" and "New Product" to different locales as follows:
Information
To explore more about this API, check the Lang.js library on GitHub.
Modified at 2024-08-14 12:35:28
Previous
Overview
Next
Notify