Languages
In the previous article, we explained how to perform localization within the Twilight theme engine.
INFO
✅ The theme's languages are all loaded by default when the SDK is initialized via salla.init().
📙 What you'll learn
Usage
/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."
TIP
get()
and set()
.Getting transaltion
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
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
Events
Adding New Translations
Using Single Key Path
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
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
Modified at 2024-08-14 12:35:28