"use strict";

var resources = {
    en: {
        translation: {
            "apple": "apple",
            "banana": "banana",
            "grape": "grape",
            "pineapple":"pineapple",
            "english":"English",
            "simplifiedChinese":"简体中文",
            "traditionalChinese":"繁體中文",
            "japanese":"日本語"
        }
    },
    zh: {
        translation: {
            "apple": "苹果",
            "banana": "香蕉",
            "grape": "葡萄",
            "pineapple":"菠萝",
            "english":"English",
            "simplifiedChinese":"简体中文",
            "traditionalChinese":"繁體中文",
            "japanese":"日本語"
        }
    },
    zhTW: {
        translation: {
            "apple": "蘋果",
            "banana": "香蕉",
            "grape": "葡萄",
            "pineapple":"鳳梨",
            "english":"English",
            "simplifiedChinese":"简体中文",
            "traditionalChinese":"繁體中文",
            "japanese":"日本語"
        }
    },
    jp: {
        translation: {
            "apple": "りんご",
            "banana": "バナナ",
            "grape": "ブドウ",
            "pineapple":"パイナップル",
            "english":"English",
            "simplifiedChinese":"简体中文",
            "traditionalChinese":"繁體中文",
            "japanese":"日本語"
        }
    }
};

var config = {
    lng: 'en',
    debug: true,
    resources: resources
};

function updateContent() {
    document.getElementById('apple').innerHTML = i18next.t('apple');
    document.getElementById('banana').innerHTML = i18next.t('banana');
    document.getElementById('grape').innerHTML = i18next.t('grape');
    document.getElementById('pineapple').innerHTML = i18next.t('pineapple');
}

function updateButtonContent(){
    document.getElementById('english').value = i18next.t('english');
    document.getElementById('simplifiedChinese').value = i18next.t('simplifiedChinese');
    document.getElementById('traditionalChinese').value = i18next.t('traditionalChinese');
    document.getElementById('japanese').value = i18next.t('japanese');
}

function initCb(err, t) {
    // initialized and ready to go!
    updateContent();
    updateButtonContent();
};

i18next.init(config, initCb);

i18next.on('languageChanged', () => {
    updateContent();
    updateButtonContent();
});

function changeLang(lang) {
    i18next.changeLanguage(lang);
}