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: b9d4420a3e6c2ba1c9f52e97bbc4b422e33ebfed (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
import SystemService from "@js/Services/SystemService";

class LocalisationService {

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

    /**
     *
     * @param {(String|String[])} key
     * @param {(String|String[])} [variables]
     * @returns {String}
     */
    translate(key, ...variables ) {
        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();