1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-02-03 02:37:49 +01:00

refactor: vue-i18n ts improvements

This commit is contained in:
Fabio Di Stasio 2022-08-05 13:06:08 +02:00
parent f4da28cca0
commit 09a372e96d
3 changed files with 8 additions and 8 deletions

View File

@ -329,7 +329,7 @@ import ModalSettingsChangelog from '@/components/ModalSettingsChangelog.vue';
import BaseTextEditor from '@/components/BaseTextEditor.vue'; import BaseTextEditor from '@/components/BaseTextEditor.vue';
import BaseSelect from '@/components/BaseSelect.vue'; import BaseSelect from '@/components/BaseSelect.vue';
const { t, availableLocales } = useI18n(); const { t, AvailableLocale } = useI18n();
const applicationStore = useApplicationStore(); const applicationStore = useApplicationStore();
const settingsStore = useSettingsStore(); const settingsStore = useSettingsStore();
@ -456,7 +456,7 @@ const selectedTab: Ref<string> = ref('general');
const locales = computed(() => { const locales = computed(() => {
const locales = []; const locales = [];
for (const locale of availableLocales) for (const locale of AvailableLocale)
locales.push({ code: locale, name: localesNames[locale] }); locales.push({ code: locale, name: localesNames[locale] });
return locales; return locales;

View File

@ -29,10 +29,10 @@ type NestedPartial<T> = {
[K in keyof T]?: T[K] extends Array<infer R> ? Array<NestedPartial<R>> : (T[K] extends unknown ? unknown : NestedPartial<T[K]>) [K in keyof T]?: T[K] extends Array<infer R> ? Array<NestedPartial<R>> : (T[K] extends unknown ? unknown : NestedPartial<T[K]>)
}; };
type MessageSchema = typeof enUS export type MessageSchema = typeof enUS
type AvailableLocales = keyof typeof messages export type AvailableLocale = keyof typeof messages
const i18n = createI18n<[NestedPartial<MessageSchema>], AvailableLocales>({ const i18n = createI18n<[NestedPartial<MessageSchema>], AvailableLocale>({
fallbackLocale: 'en-US', fallbackLocale: 'en-US',
legacy: false, legacy: false,
messages messages

View File

@ -1,6 +1,6 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import i18n from '@/i18n'; import i18n, { AvailableLocale } from '@/i18n';
import * as Store from 'electron-store'; import * as Store from 'electron-store';
const persistentStore = new Store({ name: 'settings' }); const persistentStore = new Store({ name: 'settings' });
const isDarkTheme = window.matchMedia('(prefers-color-scheme: dark)'); const isDarkTheme = window.matchMedia('(prefers-color-scheme: dark)');
@ -12,7 +12,7 @@ export type ApplicationTheme = 'light' | 'dark';
export const useSettingsStore = defineStore('settings', { export const useSettingsStore = defineStore('settings', {
state: () => ({ state: () => ({
locale: persistentStore.get('locale', 'en-US') as string, locale: persistentStore.get('locale', 'en-US') as AvailableLocale,
allowPrerelease: persistentStore.get('allow_prerelease', true) as boolean, allowPrerelease: persistentStore.get('allow_prerelease', true) as boolean,
explorebarSize: persistentStore.get('explorebar_size', null) as number, explorebarSize: persistentStore.get('explorebar_size', null) as number,
notificationsTimeout: persistentStore.get('notifications_timeout', 5) as number, notificationsTimeout: persistentStore.get('notifications_timeout', 5) as number,
@ -27,7 +27,7 @@ export const useSettingsStore = defineStore('settings', {
disableScratchpad: persistentStore.get('disable_scratchpad', false) as boolean disableScratchpad: persistentStore.get('disable_scratchpad', false) as boolean
}), }),
actions: { actions: {
changeLocale (locale: string) { changeLocale (locale: AvailableLocale) {
this.locale = locale; this.locale = locale;
i18n.global.locale = locale; i18n.global.locale = locale;
persistentStore.set('locale', this.locale); persistentStore.set('locale', this.locale);