define(function () {

    var fallbackLanguage = "en-us",
        texts = {
            "player": {
                "navigation": {
                    "button": {
                        "sitemap": {
                            "close": {
                                "et-ee": "Sulgege sisukord",
                                "bg-bg": "Затваряне на съдържанието",
                                "cs-cz": "Zavřít obsah",
                                "da-dk": "Luk indholdsfortegnelse",
                                "de-de": "Inhaltsübersicht schließen",
                                "en-us": "Close table of contents",
                                "es-es": "Cerrar tabla de contenidos",
                                "es-ar": "Cerrar tabla de contenidos",
                                "fi-fi": "Sulje sisällysluettelo",
                                "fr-fr": "Fermer la table des matières",
                                "el-gr": "Κλείσιμο πίνακα περιεχομένων",
                                "hi-in": "सामग्री की तालिका बंद करें",
                                "hr-hr": "Zatvori sadržaj",
                                "hu-hu": "Tartalomjegyzék bezárása",
                                "it-it": "Chiudi il sommario",
                                "ja-jp": "目次を閉じる",
                                "ko-kr": "목차 닫기",
                                "lt-lt": "Uždarykite turinį",
                                "mk-mk": "Затворете ја содржината",
                                "mn-mn": "Агуулгын хүснэгтийг хаах",
                                "ms-id": "Tutup jadual kandungan",
                                "nl-nl": "Inhoudsopgave sluiten",
                                "no-no": "Lukk innholdsfortegnelse",
                                "pl-pl": "Zamknij spis treści",
                                "pt-pt": "Fechar índice",
                                "pt-br": "Fechar índice",
                                "ro-ro": "Închideți cuprinsul",
                                "ru-ru": "Закрыть оглавление",
                                "sk-sk": "Zavrieť obsah",
                                "sl-si": "Zapri kazalo",
                                "sr-rs": "Затворите садржај",
                                "sv-se": "Stäng innehållsförteckning",
                                "th-th": "ปิดสารบัญ",
                                "tr-tr": "İçindekileri kapat",
                                "zh-tw": "關閉目錄",
                                "zh-cn": "关闭目录",
                                "de-at": "Inhaltsübersicht schließen",
                                "de-ch": "Inhaltsübersicht schließen",
                                "eo-de": "Inhaltsübersicht schließen",
                                "nl-be": "Inhoudsopgave sluiten",
                                "en-ie": "Close table of contents",
                                "en-gb": "Close table of contents",
                                "eo-en": "Inhaltsübersicht schließen",
                                "fr-be": "Fermer la table des matières"
                            },
                            "open": {
                                "et-ee": "Ava sisukord",
                                "bg-bg": "Отворете съдържанието",
                                "cs-cz": "Otevřít obsah",
                                "da-dk": "Åbn indholdsfortegnelsen",
                                "de-de": "Inhaltsübersicht öffnen",
                                "en-us": "Open table of contents",
                                "es-es": "Abrir tabla de contenido",
                                "es-ar": "Abrir tabla de contenido",
                                "fi-fi": "Avaa sisällysluettelo",
                                "fr-fr": "Ouvrir la table des matières",
                                "el-gr": "Ανοιχτός πίνακας περιεχομένων",
                                "hi-in": "सामग्री की खुली तालिका",
                                "hr-hr": "Otvorite sadržaj",
                                "hu-hu": "Tartalomjegyzék megnyitása",
                                "it-it": "Apri il sommario",
                                "ja-jp": "目次を開く",
                                "ko-kr": "목차 열기",
                                "lt-lt": "Atidarykite turinį",
                                "mk-mk": "Отворете ја содржината",
                                "mn-mn": "Агуулгын хүснэгтийг нээх",
                                "ms-id": "Buka jadual kandungan",
                                "nl-nl": "Inhoudsopgave openen",
                                "no-no": "Åpne innholdsfortegnelsen",
                                "pl-pl": "Otwórz spis treści",
                                "pt-pt": "Abra o índice",
                                "pt-br": "Abra o índice",
                                "ro-ro": "Deschideți cuprinsul",
                                "ru-ru": "Открыть оглавление",
                                "sk-sk": "Otvorte obsah",
                                "sl-si": "Odpri kazalo",
                                "sr-rs": "Отворите садржај",
                                "sv-se": "Öppna innehållsförteckningen",
                                "th-th": "เปิดสารบัญ",
                                "tr-tr": "İçindekileri aç",
                                "zh-tw": "打開目錄",
                                "zh-cn": "打开目录",
                                "de-at": "Inhaltsübersicht öffnen",
                                "de-ch": "Inhaltsübersicht öffnen",
                                "eo-de": "Inhaltsübersicht öffnen",
                                "nl-be": "Inhoudsopgave openen",
                                "en-ie": "Open table of contents",
                                "en-gb": "Open table of contents",
                                "eo-en": "Inhalt",
                                "fr-be": "Ouvrir la table des matières"
                            }
                        }
                    }
                }
            }
        };

    /**
     * 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;
        }
    }
});