aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/i18n.js
blob: 7086852720181e403e6cfb3feb04af1e0d96c70c (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
44
45
46
47
// ==========================================================================
// Plyr internationalization
// ==========================================================================

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

// Skip i18n for abbreviations and brand names
const resources = {
  pip: 'PIP',
  airplay: 'AirPlay',
  html5: 'HTML5',
  vimeo: 'Vimeo',
  youtube: 'YouTube',
};

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

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

    if (is.empty(string)) {
      if (Object.keys(resources).includes(key)) {
        return resources[key];
      }

      return '';
    }

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

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

    return string;
  },
};

export default i18n;