define(function () {

    var fallbackLanguage = "en-us",
        texts = {
            "player": {
                "sound": {
                    "on": {
                        "et-ee": "Lülitage heli välja",
                        "bg-bg": "Изключете аудиото",
                        "cs-cz": "Vypněte zvuk",
                        "da-dk": "Sluk for lyd",
                        "de-de": "Ton ausschalten",
                        "en-us": "Turn off audio",
                        "es-es": "Apagar audio",
                        "es-ar": "Apagar audio",
                        "fi-fi": "Kytke ääni pois päältä",
                        "fr-fr": "Désactiver le son",
                        "el-gr": "Απενεργοποιήστε τον ήχο",
                        "hi-in": "ऑडियो बंद करें",
                        "hr-hr": "Isključite zvuk",
                        "hu-hu": "Kapcsolja ki a hangot",
                        "it-it": "Disattiva l'audio",
                        "ja-jp": "オーディオをオフにする",
                        "ko-kr": "오디오 끄기",
                        "lt-lt": "Išjungti garsą",
                        "mk-mk": "Исклучете го аудиото",
                        "mn-mn": "Аудио унтраа",
                        "ms-id": "Matikan audio",
                        "nl-nl": "Schakel audio uit",
                        "no-no": "Schakel audio uit",
                        "pl-pl": "Wyłącz dźwięk",
                        "pt-pt": "Desligue o áudio",
                        "pt-br": "Desligue o áudio",
                        "ro-ro": "Opriți sunetul",
                        "ru-ru": "Выключить звук",
                        "sk-sk": "Vypnite zvuk",
                        "sl-si": "Izklopi zvok",
                        "sr-rs": "Искључите звук",
                        "sv-se": "Stäng av ljudet",
                        "th-th": "ปิดเสียง",
                        "tr-tr": "Sesi kapat",
                        "zh-tw": "關閉音頻",
                        "zh-cn": "关闭音频",
                        "de-at": "Ton ausschalten",
                        "de-ch": "Ton ausschalten",
                        "eo-de": "Ton ausschalten",
                        "nl-be": "Schakel audio uit",
                        "en-ie": "Turn off audio",
                        "en-gb": "Turn off audio",
                        "eo-en": "Ton ausschalten",
                        "fr-be": "Désactiver le son"
                    },
                    "off": {
                        "et-ee": "Lülitage heli sisse",
                        "bg-bg": "Включете аудиото",
                        "cs-cz": "Zapněte zvuk",
                        "da-dk": "Slå lyd til",
                        "de-de": "Ton einschalten",
                        "en-us": "Turn on audio",
                        "es-es": "Activar audio",
                        "es-ar": "Activar audio",
                        "fi-fi": "Laita ääni päälle",
                        "fr-fr": "Activer le son",
                        "el-gr": "Ενεργοποιήστε τον ήχο",
                        "hi-in": "ऑडियो चालू करें",
                        "hr-hr": "Uključi zvuk",
                        "hu-hu": "Kapcsolja be a hangot",
                        "it-it": "Attiva l'audio",
                        "ja-jp": "オーディオをオンにする",
                        "ko-kr": "오디오 켜기",
                        "lt-lt": "Įjungti garsą",
                        "mk-mk": "Вклучете аудио",
                        "mn-mn": "Аудио асаана уу",
                        "ms-id": "Hidupkan audio",
                        "nl-nl": "Schakel audio in",
                        "no-no": "Slå på lyd",
                        "pl-pl": "Włącz dźwięk",
                        "pt-pt": "Ativar o áudio",
                        "pt-br": "Ativar o áudio",
                        "ro-ro": "Porniți sunetul",
                        "ru-ru": "Включите звук",
                        "sk-sk": "Zapnite zvuk",
                        "sl-si": "Vklopi zvok",
                        "sr-rs": "Укључите звук",
                        "sv-se": "Slå på ljud",
                        "th-th": "เปิดเสียง",
                        "tr-tr": "Sesi aç",
                        "zh-tw": "打開音頻",
                        "zh-cn": "打开音频",
                        "de-at": "Ton einschalten",
                        "de-ch": "Ton einschalten",
                        "eo-de": "Ton einschalten",
                        "nl-be": "Schakel audio in",
                        "en-ie": "Turn on audio",
                        "en-gb": "Turn on audio",
                        "eo-en": "Ton einschalten",
                        "fr-be": "Activer le son"
                    }
                }
            }
        };

    /**
     * Gets data from a nested object
     *
     * @private
     * @param {string} key - a dot separated representation of the objectstructure e.g.("cmi.core.lesson_status")
     * @param {object|string} data - the data object where the value should be got from
     */
    function getData(key, data) {

        var parts = key.split("."),
            i = 0,
            parent = data;

        for (; i < parts.length; ++i) {
            if (!parent[parts[i]]) {
                return null;
            }
            parent = parent[parts[i]];
        }

        return parent;
    }

    // revealing public API
    return {

        /**
         * Gets a text in a given language
         * If the text is not defined in the given language, the text in teh fallback "en-us" is used, otherwise "null".
         *
         * @public
         * @param {string} key - a dot separated representation of the resource e.g.("quiz.evaluate")
         * @param {string} [language] - the language for the text e.g.("en-us")
         */
        get: function (key, language) {

            var text = getData(key, texts);
            if (text) {
                return getData(language, text) || getData(fallbackLanguage, text);
            }

            return null;
        }
    }
});