Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LocalisationService.js « Services « js « src - github.com/marius-wieschollek/passwords-webextension.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 258b1bf07a3040c6ded3fa06e588dcc5de8f5bb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import SystemService from "@js/Services/SystemService";
import SettingsService from "@js/Services/SettingsService";

class LocalisationService {

    constructor() {
        this._browser = SystemService.getBrowserApi();
        this._debug = null;
    }

    /**
     *
     */
    init() {
        SettingsService
            .get('debug.localisation.enabled')
            .then((s) => {
                this._debug = s;
            });
    }

    /**
     *
     * @param {(String|String[])} key
     * @param {(String|String[])} [variables]
     * @returns {String}
     */
    translate(key, ...variables) {
        if(this._debug && !this._debug.getValue()) return key;
        if(Array.isArray(key)) {
            if(key.length < 0) return '';

            variables = key.slice(1);
            key = key.slice(0, 1)[0];
        }
        if(Array.isArray(variables[0])) variables = variables[0];
        let translation = this._browser.i18n.getMessage(key, variables);

        return translation ? translation:key;
    }
}

export default new LocalisationService();