forked from akanyan/STARTLINER
feat: internationalization
This commit is contained in:
@ -4,6 +4,7 @@ import { listen } from '@tauri-apps/api/event';
|
||||
import * as path from '@tauri-apps/api/path';
|
||||
import { PhysicalSize, getCurrentWindow } from '@tauri-apps/api/window';
|
||||
import { readTextFile, writeTextFile } from '@tauri-apps/plugin-fs';
|
||||
import { Locale, setLocale as actualSetLocale } from './i18n';
|
||||
import { invoke, invoke_nopopup } from './invoke';
|
||||
import { Dirs, Feature, Game, Package, Profile, ProfileMeta } from './types';
|
||||
import {
|
||||
@ -371,6 +372,7 @@ export const useClientStore = defineStore('client', () => {
|
||||
const verbose = ref(false);
|
||||
const theme: Ref<'light' | 'dark' | 'system'> = ref('system');
|
||||
const onboarded: Ref<Game[]> = ref([]);
|
||||
const locale: Ref<Locale> = ref('en');
|
||||
|
||||
const _scaleValue = (value: ScaleType) =>
|
||||
value === 's' ? 1 : value === 'm' ? 1.25 : value === 'l' ? 1.5 : 2;
|
||||
@ -433,6 +435,11 @@ export const useClientStore = defineStore('client', () => {
|
||||
if (input.onboarded) {
|
||||
onboarded.value = input.onboarded;
|
||||
}
|
||||
|
||||
if (input.locale) {
|
||||
locale.value = input.locale;
|
||||
}
|
||||
await setLocale(locale.value);
|
||||
await setTheme(theme.value);
|
||||
} catch (e) {
|
||||
console.error(`Error reading client options: ${e}`);
|
||||
@ -466,6 +473,7 @@ export const useClientStore = defineStore('client', () => {
|
||||
},
|
||||
theme: theme.value,
|
||||
onboarded: onboarded.value,
|
||||
locale: locale.value,
|
||||
})
|
||||
);
|
||||
};
|
||||
@ -518,6 +526,12 @@ export const useClientStore = defineStore('client', () => {
|
||||
await save();
|
||||
};
|
||||
|
||||
const setLocale = async (loc: Locale) => {
|
||||
locale.value = loc;
|
||||
await save();
|
||||
await actualSetLocale(loc);
|
||||
};
|
||||
|
||||
getCurrentWindow().onResized(async ({ payload }) => {
|
||||
// For whatever reason this is 0 when minimized
|
||||
if (payload.width > 0) {
|
||||
@ -532,6 +546,7 @@ export const useClientStore = defineStore('client', () => {
|
||||
verbose,
|
||||
theme,
|
||||
onboarded,
|
||||
locale,
|
||||
timeout,
|
||||
scaleModel,
|
||||
_scaleValue,
|
||||
@ -544,5 +559,6 @@ export const useClientStore = defineStore('client', () => {
|
||||
setVerbose,
|
||||
setTheme,
|
||||
setOnboarded,
|
||||
setLocale,
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user