aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/i18n.js
blob: f71e1a425d2bb3c117e37069c8b466f0c6c3339c (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
// ==========================================================================
// Plyr internationalization
// ==========================================================================

import is from './is';
import { getDeep } from './objects';
import { replaceAll } from './strings';

const i18n = {
    get(key = '', config = {}) {
        if (is.empty(key) || is.empty(config)) {
            return '';
        }

        let string = getDeep(config.i18n, key);

        if (is.empty(string)) {
            return '';
        }

        const replace = {
            '{seektime}': config.seekTime,
            '{title}': config.title,
        };

        Object.entries(replace).forEach(([key, value]) => {
            string = replaceAll(string, key, value);
        });

        return string;
    },
};

export default i18n;