mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
feat: add support i18n (#1468)
This commit is contained in:
@ -6,6 +6,8 @@ import { allPlugins, mainPlugins } from 'virtual:plugins';
|
||||
import config from '@/config';
|
||||
import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import { t } from '@/i18n';
|
||||
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import type { BackendContext } from '@/types/contexts';
|
||||
|
||||
@ -67,14 +69,23 @@ export const forceUnloadMainPlugin = async (
|
||||
plugin.backend)
|
||||
) {
|
||||
delete loadedPluginMap[id];
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
console.log(LoggerPrefix, t(
|
||||
'common.console.plugins.unloaded',
|
||||
{ pluginName: id },
|
||||
));
|
||||
return;
|
||||
} else {
|
||||
console.log(LoggerPrefix, `Cannot unload "${id}" plugin`);
|
||||
console.log(
|
||||
LoggerPrefix,
|
||||
t('common.console.plugins.unload-failed', { pluginName: id }),
|
||||
);
|
||||
return Promise.reject();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(LoggerPrefix, `Cannot unload "${id}" plugin`);
|
||||
console.error(
|
||||
LoggerPrefix,
|
||||
t('common.console.plugins.unload-failed', { pluginName: id }),
|
||||
);
|
||||
console.trace(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
@ -100,18 +111,24 @@ export const forceLoadMainPlugin = async (
|
||||
) {
|
||||
loadedPluginMap[id] = plugin;
|
||||
} else {
|
||||
console.log(LoggerPrefix, `Cannot load "${id}" plugin`);
|
||||
console.log(
|
||||
LoggerPrefix,
|
||||
t('common.console.plugins.load-failed', { pluginName: id }),
|
||||
);
|
||||
return Promise.reject();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(LoggerPrefix, `Cannot initialize "${id}" plugin: `);
|
||||
console.error(
|
||||
LoggerPrefix,
|
||||
t('common.console.plugins.initialize-failed', { pluginName: id }),
|
||||
);
|
||||
console.trace(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const loadAllMainPlugins = async (win: BrowserWindow) => {
|
||||
console.log(LoggerPrefix, 'Loading all plugins');
|
||||
console.log(LoggerPrefix, t('common.console.plugins.load-all'));
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
const queue: Promise<void>[] = [];
|
||||
|
||||
|
||||
@ -6,6 +6,8 @@ import { setApplicationMenu } from '@/menu';
|
||||
|
||||
import { LoggerPrefix } from '@/utils';
|
||||
|
||||
import { t } from '@/i18n';
|
||||
|
||||
import type { MenuContext } from '@/types/contexts';
|
||||
import type { BrowserWindow, MenuItemConstructorOptions } from 'electron';
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
@ -48,9 +50,15 @@ export const forceLoadMenuPlugin = async (id: string, win: BrowserWindow) => {
|
||||
}
|
||||
} else return;
|
||||
|
||||
console.log(LoggerPrefix, `Successfully loaded '${id}::menu'`);
|
||||
console.log(
|
||||
LoggerPrefix,
|
||||
t('common.console.plugins.loaded', { pluginName: `${id}::menu` })
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(LoggerPrefix, `Cannot initialize '${id}::menu': `);
|
||||
console.error(
|
||||
LoggerPrefix,
|
||||
t('common.console.plugins.initialize-failed', { pluginName: `${id}::menu` }),
|
||||
);
|
||||
console.trace(err);
|
||||
}
|
||||
};
|
||||
|
||||
@ -5,6 +5,8 @@ import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
import { t } from '@/i18n';
|
||||
|
||||
import type { PreloadContext } from '@/types/contexts';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
|
||||
@ -31,10 +33,13 @@ export const forceUnloadPreloadPlugin = async (id: string) => {
|
||||
context: createContext(id),
|
||||
});
|
||||
if (hasStopped || (hasStopped === null && loadedPluginMap[id].preload)) {
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
console.log(
|
||||
LoggerPrefix,
|
||||
t('common.console.plugins.unloaded', { pluginName: id }),
|
||||
);
|
||||
delete loadedPluginMap[id];
|
||||
} else {
|
||||
console.error(LoggerPrefix, `Cannot stop "${id}" plugin`);
|
||||
console.error(LoggerPrefix, t('common.console.plugins.unload-failed', { pluginName: id }));
|
||||
}
|
||||
};
|
||||
|
||||
@ -57,9 +62,9 @@ export const forceLoadPreloadPlugin = async (id: string) => {
|
||||
loadedPluginMap[id] = plugin;
|
||||
}
|
||||
|
||||
console.log(LoggerPrefix, `"${id}" plugin is loaded`);
|
||||
console.log(LoggerPrefix, t('common.console.plugins.loaded', { pluginName: id }));
|
||||
} catch (err) {
|
||||
console.error(LoggerPrefix, `Cannot initialize "${id}" plugin: `);
|
||||
console.error(LoggerPrefix, t('common.console.plugins.initialize-failed', { pluginName: id }));
|
||||
console.trace(err);
|
||||
}
|
||||
};
|
||||
|
||||
@ -6,6 +6,7 @@ import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import type { RendererContext } from '@/types/contexts';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import { t } from '@/i18n';
|
||||
|
||||
const unregisterStyleMap: Record<string, (() => void)[]> = {};
|
||||
const loadedPluginMap: Record<
|
||||
@ -54,9 +55,9 @@ export const forceUnloadRendererPlugin = async (id: string) => {
|
||||
document.querySelector(`style#plugin-${id}`)?.remove();
|
||||
}
|
||||
if (hasStopped || (hasStopped === null && plugin?.renderer)) {
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
console.log(LoggerPrefix, t('common.console.plugins.unloaded', { pluginName: id }));
|
||||
} else {
|
||||
console.error(LoggerPrefix, `Cannot stop "${id}" plugin`);
|
||||
console.error(LoggerPrefix, t('common.console.plugins.unload-failed', { pluginName: id }));
|
||||
}
|
||||
};
|
||||
|
||||
@ -92,9 +93,9 @@ export const forceLoadRendererPlugin = async (id: string) => {
|
||||
];
|
||||
}
|
||||
|
||||
console.log(LoggerPrefix, `"${id}" plugin is loaded`);
|
||||
console.log(LoggerPrefix, t('common.console.plugins.loaded', { pluginName: id }));
|
||||
} else {
|
||||
console.log(LoggerPrefix, `Cannot initialize "${id}" plugin`);
|
||||
console.log(LoggerPrefix, t('common.console.plugins.initialize-failed', { pluginName: id }));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user