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 BaseSelect from '@/components/BaseSelect.vue';
const { t, availableLocales } = useI18n();
const { t, AvailableLocale } = useI18n();
const applicationStore = useApplicationStore();
const settingsStore = useSettingsStore();
@ -456,7 +456,7 @@ const selectedTab: Ref<string> = ref('general');
const locales = computed(() => {
const locales = [];
for (const locale of availableLocales)
for (const locale of AvailableLocale)
locales.push({ code: locale, name: localesNames[locale] });
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]>)
};
type MessageSchema = typeof enUS
type AvailableLocales = keyof typeof messages
export type MessageSchema = typeof enUS
export type AvailableLocale = keyof typeof messages
const i18n = createI18n<[NestedPartial<MessageSchema>], AvailableLocales>({
const i18n = createI18n<[NestedPartial<MessageSchema>], AvailableLocale>({
fallbackLocale: 'en-US',
legacy: false,
messages

View File

@ -1,6 +1,6 @@
import { defineStore } from 'pinia';
import { ipcRenderer } from 'electron';
import i18n from '@/i18n';
import i18n, { AvailableLocale } from '@/i18n';
import * as Store from 'electron-store';
const persistentStore = new Store({ name: 'settings' });
const isDarkTheme = window.matchMedia('(prefers-color-scheme: dark)');
@ -12,7 +12,7 @@ export type ApplicationTheme = 'light' | 'dark';
export const useSettingsStore = defineStore('settings', {
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,
explorebarSize: persistentStore.get('explorebar_size', null) 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
}),
actions: {
changeLocale (locale: string) {
changeLocale (locale: AvailableLocale) {
this.locale = locale;
i18n.global.locale = locale;
persistentStore.set('locale', this.locale);