# All files / infrastructure/i18n i18n.engine.ts

100% Statements 17/17
50% Branches 1/2
100% Functions 6/6
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    971x

    1x

    1x

    1x
    1x
    1x

    1x

    1x

    1x

    1x
    2x

    1x
    2x

    1x
    2x

    1x

    1x
     const i18next = require('i18next');

    import {
        TRANSLATION_DE_DE,
        TRANSLATION_EN_US,
        TRANSLATION_ES_ES,
        TRANSLATION_FR_FR,
        TRANSLATION_HU_HU,
        TRANSLATION_IT_IT,
        TRANSLATION_JA_JP,
        TRANSLATION_NL_NL,
        TRANSLATION_PT_BR,
        TRANSLATION_SK_SK,
        TRANSLATION_ZH_CN
    } from './locales';

    class I18nEngine {
        private static instance: I18nEngine;

        private constructor() {}

        public static getInstance() {
            Eif (!I18nEngine.instance) {
                I18nEngine.instance = new I18nEngine();
            }
            return I18nEngine.instance;
        }

        private availablesLanguages = {
            'de-DE': 'de-DE',
            'en-US': 'en-US',
            'es-ES': 'es-ES',
            'fr-FR': 'fr-FR',
            'hu-HU': 'hu-HU',
            'it-IT': 'it-IT',
            'ja-JP': 'ja-JP',
            'nl-NL': 'nl-NL',
            'pt-BR': 'pt-BR',
            'sk-SK': 'sk-SK',
            'zh-CN': 'zh-CN'
        };

        public fallbackLanguage = 'en-US';

        public async init(language: string) {
            return i18next.init({
                lng: language,
                fallbackLng: this.fallbackLanguage,
                resources: {
                    'de-DE': {
                        translation: TRANSLATION_DE_DE
                    },
                    'en-US': {
                        translation: TRANSLATION_EN_US
                    },
                    'es-ES': {
                        translation: TRANSLATION_ES_ES
                    },
                    'fr-FR': {
                        translation: TRANSLATION_FR_FR
                    },
                    'hu-HU': {
                        translation: TRANSLATION_HU_HU
                    },
                    'it-IT': {
                        translation: TRANSLATION_IT_IT
                    },
                    'ja-JP': {
                        translation: TRANSLATION_JA_JP
                    },
                    'nl-NL': {
                        translation: TRANSLATION_NL_NL
                    },
                    'pt-BR': {
                        translation: TRANSLATION_PT_BR
                    },
                    'sk-SK': {
                        translation: TRANSLATION_SK_SK
                    },
                    'zh-CN': {
                        translation: TRANSLATION_ZH_CN
                    }
                }
            });
        }

        public translate(key: string): string {
            return i18next.t(key);
        }

        public supportLanguage(language: string): boolean {
            return typeof this.availablesLanguages[language] !== 'undefined';
        }
    }

    export default I18nEngine.getInstance();