Files
outline/app/utils/language.ts
Tom Moor 9281287dba one
2022-04-09 20:25:54 -07:00

19 lines
552 B
TypeScript

import { i18n } from "i18next";
export function detectLanguage() {
const [ln, r] = navigator.language.split("-");
const region = (r || ln).toUpperCase();
return `${ln}_${region}`;
}
export function changeLanguage(
toLanguageString: string | null | undefined,
i18n: i18n
) {
if (toLanguageString && i18n.language !== toLanguageString) {
// Languages are stored in en_US format in the database, however the
// frontend translation framework (i18next) expects en-US
i18n.changeLanguage(toLanguageString.replace("_", "-"));
}
}