Namespace

language

kiss.language

Simple translation management

Provides 4 functions to translate the texts:

  • txt
  • txtTitleCase
  • txtUpperCase
  • txtLowerCase

Note:

  • You can also merge data directly into the translated text using a "merge" object (see below).
  • Any translation which is not found will fallback to the text passed to the function.
  • Any unfound text will be automatically stored into the "missingTexts" variable to ease the debug phase

View Source client/core/modules/language.js, line 19

Members

# static texts

All the static texts used in the UI components

View Source client/core/modules/language.texts.js, line 6

Methods

# static get() → {string}

Get the current language

  • first check the url parameter "language" (for example: &language=fr)
  • if no parameter, tries to get the browser language
  • defaults to "en" (English)

View Source client/core/modules/language.js, line 105

The current language. Examples: "en", "fr", "de", "it"...

string

# static init()

    1. Set the language from the browser settings, or system locales, or localStorage
    1. Consolidate the library's texts and the specific application's texts into a single object to lookup

View Source client/core/modules/language.js, line 76

# static select()

Open a window to switch the language

View Source client/core/modules/language.js, line 287

# static set(newLanguage)

Switch to another language

Parameters:
Name Type Description
newLanguage *

View Source client/core/modules/language.js, line 193

# static setAvailable(languages)

Set the available languages

Parameters:
Name Type Description
languages Array.<object>

Passeed as an array of objects with a "code" and a "name" property

View Source client/core/modules/language.js, line 67

this

Example
kiss.language.setAvailable([
 {
     code: "en",
     name: "English"
 },
 {
     code: "fr",
     name: "Français"
 },
 {
     code: "es",
     name: "Español"
 }
])

# static showMissingTexts() → {string}

Show all missing texts in the console

View Source client/core/modules/language.js, line 203

  • All the missing texts
string

# static showTranslationWindow()

Show a window to translate texts without translation

View Source client/core/modules/language.js, line 215

# static translate(key, customSourceTextsopt, merge) → {string}

Return a localized text from a key, or a fallback text If a translation is missing, the text key is stored into the "kiss.language.missingTexts" array, in order to ease the debug phase. When a merge object is passed as a parameter, the values are merged into the final string.

Parameters:
Name Type Attributes Description
key string

The text key, which should be in lowercase by convention (txtTitleCase, txtUpperCase, and txtLowerCase handle the case)

customSourceTexts object <optional>

Custom source texts. Must be provided in the same format as default source texts. See example.

merge object

Contextual data that must be merged into the text

View Source client/core/modules/language.js, line 158

  • The localized text, or the key passed to the function if not found
string
Example
txt("hello") // bonjour
txtTitleCase("hello") // Bonjour
txt("hello %firstName %lastName", null, {firstName: "Bob", lastName: "Wilson"}) // bonjour Bob Wilson
txt("Devil number: %num%num%num", null, {num: 6}) // Devil number: 666

let customSource = {
     "apple": {
         fr: "pomme"
     },
     "banana": {
         fr: "banana"
     },
     "fruits": {
         en: "choose between those fruits...",
         fr: "choisissez parmi ces fruits..."
     }
}

kiss.language.set("en")
txtTitleCase("apple", customSource) // Apple
txtUpperCase("banana", customSource) // BANANA
txtTitleCase("fruits", customSource) // Choose between those fruits...

kiss.language.set("fr")
txtUpperCase("fruits", customSource) // CHOISISSEZ PARMI CES FRUITS...