Skip to content

Commit

Permalink
fix: properly do language fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
vgskye authored Oct 20, 2024
1 parent 046976a commit e7ee282
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { writable, derived } from 'svelte/store';
import { langs } from './lang';

const defaultLocale = 'en';

function determineLocale(locale: string): string {
if (langs[locale.toLowerCase()] != undefined) {
return locale.toLowerCase();
} else {
} else if (langs[locale.toLowerCase().split('-')[0]] != undefined) {
return locale.toLowerCase().split('-')[0];
} else {
return defaultLocale;
}
}

export const locale = writable(determineLocale(navigator.language));
const defaultLocale = 'en';

export const trans = derived(
locale,
Expand Down

0 comments on commit e7ee282

Please sign in to comment.