Skip to content

Language with Script

StefansArya edited this page Jan 19, 2021 · 2 revisions

Loaded language are exposed to sf.lang.list, and you can explore it from the browser's console.

console.log( sf.language.list );

Language Interpolation

The interpolate-able is language string "with {this} curly bracket".

Use interpolation with object

sf.language.get('my.name', {name:"Alex"}); // My Name is Alex

Default interpolation

When you implement this, it's value will be used for interpolate on related language path.

sf.language.interpolate = {
    name:"Lusia",
    timestamp:Date.now,
    ...
};

sf.language.get('my.name'); // My Name is Lusia

Use callback for waiting response from the server side

sf.language.get('my.name', /* {..interpolate data..}, */function(text){
     text; // My Name is someone
});

Get multiple path at once

sf.language.get(['date', 'my.name'], /* {...}, */, function(values){
    /* values = {
        'date': '7 January',
        'my.name': 'My Name is Lusia'
    }*/
});

// You can also do this without callback
var values = sf.language.get(['date', 'my.name']);

Directly assign to object

var obj = {
    /* maybe model/component scope? */
   key: "Waiting..."
};

sf.language.assign(obj, {
    key:'language.path.here'
}, /* {interpolation data} */);
Clone this wiki locally