mirror of
https://github.com/lukasabbe/liu-stats-website.git
synced 2026-04-30 10:50:52 +00:00
init
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { translations, type Locale } from './translations';
|
||||
import type { TranslationKey } from './translations';
|
||||
|
||||
function createLocaleStore() {
|
||||
const { subscribe, set, update } = writable<Locale>('en');
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
setSwedish: () => set('sv'),
|
||||
setEnglish: () => set('en'),
|
||||
toggle: () =>
|
||||
update((current) => {
|
||||
return current === 'en' ? 'sv' : 'en';
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
export const locale = createLocaleStore();
|
||||
|
||||
export function t(key: TranslationKey): string {
|
||||
let currentLocale: Locale = 'en';
|
||||
locale.subscribe((l) => (currentLocale = l))();
|
||||
return translations[currentLocale][key];
|
||||
}
|
||||
|
||||
export function getTranslation(key: TranslationKey, currentLocale: Locale): string {
|
||||
return translations[currentLocale][key];
|
||||
}
|
||||
Reference in New Issue
Block a user