/** * Flattens an object recursively. Nested keys are joined with slashes ('/') * @param {object} obj The object to flatten * @returns {object} The flattened object */ export function flattenObj(obj) { const res = {} Object.entries(obj).forEach(([key, value]) => { if (typeof value === "object") { value = flattenObj(value) Object.entries(value).forEach(([key2, value2]) => { res[key + "/" + key2] = value2 }) } else { res[key] = value } }) return res } export const LANGUAGES = { "fr": ["fre", "fra", "french", "francais", "français", "vf", "vff"], "fr-ca": ["vfq", "quebec", "québec"], "en": ["eng", "ang", "english", "anglais"], "de": ["deu", "ger", "german", "allemand"], "ko": ["kor", "cor", "korean", "coreen", "coréen"], "ja": ["jap", "japanese", "japonais"] } /** * Tries to find a language name in the given string * @param {string} value The string in which to search for a language * @returns {?string} The language key if it could be determined, null otherwise */ export function findLanguage(value) { for (const lang in LANGUAGES) { const aliases = [lang].concat(LANGUAGES[lang]) const matches = aliases.map(a => new RegExp("\\b" + a + "\\b").test(value)).some(v => v) if (matches) { return lang } } return null } export function isLanguageAlias(langKey, value) { return [langKey].concat(LANGUAGES[langKey]).includes(value) }