mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 11:21:46 +00:00
feat(i18n): i18n auto-importer
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import i18next, { init, t as i18t, changeLanguage } from 'i18next';
|
||||
|
||||
import { languageResources } from '@/i18n/resources';
|
||||
import { languageResources } from 'virtual:i18n';
|
||||
|
||||
export const loadI18n = async () =>
|
||||
await init({
|
||||
|
||||
11
src/i18n/resources/@types/index.ts
Normal file
11
src/i18n/resources/@types/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export interface LanguageResources {
|
||||
[lang: string]: {
|
||||
translation: Record<string, unknown> & {
|
||||
language: {
|
||||
name: string;
|
||||
'local-name': string;
|
||||
code: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
import enJson from './en.json';
|
||||
import koJson from './ko.json';
|
||||
|
||||
export const languageResources = {
|
||||
en: {
|
||||
translation: enJson
|
||||
},
|
||||
ko: {
|
||||
translation: koJson
|
||||
}
|
||||
};
|
||||
@ -26,6 +26,8 @@ import { deepEqual } from 'fast-equals';
|
||||
|
||||
import { allPlugins, mainPlugins } from 'virtual:plugins';
|
||||
|
||||
import { languageResources } from 'virtual:i18n';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
import { refreshMenu, setApplicationMenu } from '@/menu';
|
||||
@ -52,8 +54,6 @@ import {
|
||||
import { LoggerPrefix } from '@/utils';
|
||||
import { loadI18n, setLanguage, t } from '@/i18n';
|
||||
|
||||
import { languageResources } from '@/i18n/resources';
|
||||
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
|
||||
// Catch errors and log them
|
||||
|
||||
@ -11,6 +11,8 @@ import prompt from 'custom-electron-prompt';
|
||||
|
||||
import { allPlugins } from 'virtual:plugins';
|
||||
|
||||
import { languageResources } from 'virtual:i18n';
|
||||
|
||||
import config from './config';
|
||||
|
||||
import { restart } from './providers/app-controls';
|
||||
@ -19,7 +21,7 @@ import promptOptions from './providers/prompt-options';
|
||||
|
||||
import { getAllMenuTemplate, loadAllMenuPlugins } from './loader/menu';
|
||||
import { setLanguage, t } from '@/i18n';
|
||||
import { languageResources } from '@/i18n/resources';
|
||||
|
||||
|
||||
export type MenuTemplate = Electron.MenuItemConstructorOptions[];
|
||||
|
||||
@ -104,7 +106,7 @@ export const mainMenuTemplate = async (
|
||||
return pluginEnabledMenu(id, pluginLabel, true, innerRefreshMenu);
|
||||
});
|
||||
|
||||
const availableLanguages = Object.keys(languageResources) as unknown as (keyof typeof languageResources)[];
|
||||
const availableLanguages = Object.keys(languageResources);
|
||||
|
||||
return [
|
||||
{
|
||||
|
||||
6
src/virtual-module.d.ts
vendored
6
src/virtual-module.d.ts
vendored
@ -12,3 +12,9 @@ declare module 'virtual:plugins' {
|
||||
Omit<Plugin, 'backend' | 'preload' | 'renderer'>
|
||||
>;
|
||||
}
|
||||
|
||||
declare module 'virtual:i18n' {
|
||||
import type { LanguageResources } from '@/i18n/resources/@types';
|
||||
|
||||
export const languageResources: LanguageResources;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user