Fix i18n not working if locale is set to a non-existen language
This commit is contained in:
parent
3819048880
commit
447c877f3c
1 changed files with 3 additions and 3 deletions
|
@ -9,9 +9,6 @@
|
||||||
import { strings, defaultLanguage, languages } from "./translations";
|
import { strings, defaultLanguage, languages } from "./translations";
|
||||||
|
|
||||||
export function useTranslations(language: string) {
|
export function useTranslations(language: string) {
|
||||||
if (!(language in strings)) {
|
|
||||||
language = defaultLanguage;
|
|
||||||
}
|
|
||||||
return function t(
|
return function t(
|
||||||
key: keyof (typeof strings)[typeof defaultLanguage],
|
key: keyof (typeof strings)[typeof defaultLanguage],
|
||||||
): string {
|
): string {
|
||||||
|
@ -46,6 +43,9 @@ export function findBestLanguage(): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applyTranslations(language: string) {
|
export function applyTranslations(language: string) {
|
||||||
|
if (!(language in strings)) {
|
||||||
|
language = defaultLanguage;
|
||||||
|
}
|
||||||
const t = useTranslations(language);
|
const t = useTranslations(language);
|
||||||
|
|
||||||
for (const node of document.querySelectorAll("[data-translate]")) {
|
for (const node of document.querySelectorAll("[data-translate]")) {
|
||||||
|
|
Reference in a new issue