aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/i18n.js
blob: 5b0ebbab64255893a96d4ca29ce0e6e542b5d2d7 (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 './utils/is';
import { getDeep } from './utils/objects';
import { replaceAll } from './utils/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;