mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-01-06 09:13:44 -08:00
refactor: rename i18n
This commit is contained in:
parent
af2ed1bb34
commit
5a6cd12f1e
16 changed files with 57 additions and 57 deletions
|
|
@ -23,7 +23,7 @@ import type { INativeService } from '@services/native/interface';
|
|||
import type { IAuthenticationService, ServiceBranchTypes } from '@services/auth/interface';
|
||||
import type { IWikiService } from '@services/wiki/interface';
|
||||
import { logger } from '@services/libs/log';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import { ICommitAndSyncConfigs, IGitLogMessage, IGitService, IGitUserInfos } from './interface';
|
||||
import { WikiChannel } from '@/constants/channels';
|
||||
import { GitWorker } from './gitWorker';
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ import changeToDefaultLanguage from './useDefaultLanguage';
|
|||
import { mainBindings, clearMainBindings } from './i18nMainBindings';
|
||||
|
||||
// init i18n is async, but our usage is basically await the electron app to start, so this is basically ok
|
||||
const i18n = i18next.use(Backend);
|
||||
// eslint-disable-next-line import/no-named-as-default-member
|
||||
export const i18n = i18next.use(Backend);
|
||||
export const t = (key: string): string => i18n.t(key) ?? key;
|
||||
|
||||
export async function initRendererI18NHandler(): Promise<void> {
|
||||
await i18n.init({
|
||||
|
|
@ -29,5 +31,3 @@ export async function initRendererI18NHandler(): Promise<void> {
|
|||
mainBindings();
|
||||
await changeToDefaultLanguage(i18next);
|
||||
}
|
||||
|
||||
export default i18n;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import { DeferredMenuItemConstructorOptions } from './interface';
|
||||
|
||||
export class InsertMenuAfterSubMenuIndexError extends Error {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import type { IWorkspaceViewService } from '@services/workspacesView/interface';
|
|||
import type { IUpdaterService } from '@services/updater/interface';
|
||||
import { getWorkspaceMenuTemplate, openWorkspaceTagTiddler } from '@services/workspaces/getWorkspaceMenuTemplate';
|
||||
import { logger } from '@services/libs/log';
|
||||
import i18next from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import ContextMenuBuilder from './contextMenu/contextMenuBuilder';
|
||||
import { IpcSafeMenuItem, mainMenuItemProxy } from './contextMenu/rendererMenuItemProxy';
|
||||
import { InsertMenuAfterSubMenuIndexError } from './error';
|
||||
|
|
@ -120,27 +120,27 @@ export class MenuService implements IMenuService {
|
|||
private loadDefaultMenuTemplate(): void {
|
||||
this._menuTemplate = [
|
||||
{
|
||||
label: () => i18next.t('Menu.TidGi'),
|
||||
label: () => i18n.t('Menu.TidGi'),
|
||||
id: 'TidGi',
|
||||
submenu: [
|
||||
{
|
||||
label: () => i18next.t('ContextMenu.About'),
|
||||
label: () => i18n.t('ContextMenu.About'),
|
||||
click: async () => await this.windowService.open(WindowNames.about),
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
id: 'update',
|
||||
label: () => i18next.t('Updater.CheckUpdate'),
|
||||
label: () => i18n.t('Updater.CheckUpdate'),
|
||||
click: async () => await this.updaterService.checkForUpdates(),
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('ContextMenu.Preferences'),
|
||||
label: () => i18n.t('ContextMenu.Preferences'),
|
||||
accelerator: 'CmdOrCtrl+,',
|
||||
click: async () => await this.windowService.open(WindowNames.preferences),
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: () => i18next.t('Preference.Notifications'),
|
||||
label: () => i18n.t('Preference.Notifications'),
|
||||
click: async () => await this.windowService.open(WindowNames.notifications),
|
||||
accelerator: 'CmdOrCtrl+Shift+N',
|
||||
},
|
||||
|
|
@ -150,60 +150,60 @@ export class MenuService implements IMenuService {
|
|||
{ role: 'hide' },
|
||||
{ role: 'hideOthers' },
|
||||
{ role: 'unhide' },
|
||||
{ label: () => i18next.t('ContextMenu.Quit') + i18next.t('Menu.TidGi'), role: 'quit' },
|
||||
{ label: () => i18n.t('ContextMenu.Quit') + i18n.t('Menu.TidGi'), role: 'quit' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.Edit'),
|
||||
label: () => i18n.t('Menu.Edit'),
|
||||
id: 'Edit',
|
||||
role: 'editMenu',
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.View'),
|
||||
label: () => i18n.t('Menu.View'),
|
||||
id: 'View',
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.Language'),
|
||||
label: () => i18n.t('Menu.Language'),
|
||||
id: 'Language',
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.History'),
|
||||
label: () => i18n.t('Menu.History'),
|
||||
id: 'History',
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.Workspaces'),
|
||||
label: () => i18n.t('Menu.Workspaces'),
|
||||
id: 'Workspaces',
|
||||
submenu: [],
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.Wiki'),
|
||||
label: () => i18n.t('Menu.Wiki'),
|
||||
id: 'Wiki',
|
||||
submenu: [],
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.Window'),
|
||||
label: () => i18n.t('Menu.Window'),
|
||||
role: 'windowMenu',
|
||||
id: 'Window',
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.Help'),
|
||||
label: () => i18n.t('Menu.Help'),
|
||||
role: 'help',
|
||||
id: 'help',
|
||||
submenu: [
|
||||
{
|
||||
label: () => i18next.t('ContextMenu.TidGiSupport'),
|
||||
label: () => i18n.t('ContextMenu.TidGiSupport'),
|
||||
click: async () => await shell.openExternal('https://github.com/tiddly-gittly/TidGi-desktop/issues'),
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.ReportBugViaGithub'),
|
||||
label: () => i18n.t('Menu.ReportBugViaGithub'),
|
||||
click: async () => await shell.openExternal('https://github.com/tiddly-gittly/TidGi-desktop/issues'),
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.RequestFeatureViaGithub'),
|
||||
label: () => i18n.t('Menu.RequestFeatureViaGithub'),
|
||||
click: async () => await shell.openExternal('https://github.com/tiddly-gittly/TidGi-desktop/issues/new?template=feature.md&title=feature%3A+'),
|
||||
},
|
||||
{
|
||||
label: () => i18next.t('Menu.LearnMore'),
|
||||
label: () => i18n.t('Menu.LearnMore'),
|
||||
click: async () => await shell.openExternal('https://github.com/tiddly-gittly/TidGi-desktop/'),
|
||||
},
|
||||
],
|
||||
|
|
@ -369,7 +369,7 @@ export class MenuService implements IMenuService {
|
|||
menu.append(new MenuItem({ type: 'separator' }));
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('ContextMenu.OpenCommandPalette'),
|
||||
label: i18n.t('ContextMenu.OpenCommandPalette'),
|
||||
enabled: workspaces.length > 0,
|
||||
click: () => {
|
||||
void this.wikiService.requestWikiSendActionMessage('open-command-palette');
|
||||
|
|
@ -378,11 +378,11 @@ export class MenuService implements IMenuService {
|
|||
);
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('Menu.Workspaces'),
|
||||
label: i18n.t('Menu.Workspaces'),
|
||||
submenu: [
|
||||
...(await Promise.all(
|
||||
workspaces.map(async (workspace) => {
|
||||
const workspaceContextMenuTemplate = await getWorkspaceMenuTemplate(workspace, i18next.t.bind(i18next), services);
|
||||
const workspaceContextMenuTemplate = await getWorkspaceMenuTemplate(workspace, i18n.t.bind(i18n), services);
|
||||
return {
|
||||
label: workspace.name,
|
||||
submenu: workspaceContextMenuTemplate,
|
||||
|
|
@ -390,7 +390,7 @@ export class MenuService implements IMenuService {
|
|||
}),
|
||||
)),
|
||||
{
|
||||
label: i18next.t('WorkspaceSelector.Add'),
|
||||
label: i18n.t('WorkspaceSelector.Add'),
|
||||
click: async () => await this.windowService.open(WindowNames.addWorkspace),
|
||||
},
|
||||
],
|
||||
|
|
@ -398,9 +398,9 @@ export class MenuService implements IMenuService {
|
|||
);
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('WorkspaceSelector.OpenWorkspaceMenuName'),
|
||||
label: i18n.t('WorkspaceSelector.OpenWorkspaceMenuName'),
|
||||
submenu: workspaces.map((workspace) => ({
|
||||
label: i18next.t('WorkspaceSelector.OpenWorkspaceTagTiddler', { tagName: workspace.tagName ?? workspace.name }),
|
||||
label: i18n.t('WorkspaceSelector.OpenWorkspaceTagTiddler', { tagName: workspace.tagName ?? workspace.name }),
|
||||
click: async () => {
|
||||
await openWorkspaceTagTiddler(workspace, services);
|
||||
},
|
||||
|
|
@ -412,15 +412,15 @@ export class MenuService implements IMenuService {
|
|||
if (activeWorkspace !== undefined) {
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('Menu.Workspaces'),
|
||||
submenu: await getWorkspaceMenuTemplate(activeWorkspace, i18next.t.bind(i18next), services),
|
||||
label: i18n.t('Menu.Workspaces'),
|
||||
submenu: await getWorkspaceMenuTemplate(activeWorkspace, i18n.t.bind(i18n), services),
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('ContextMenu.Back'),
|
||||
label: i18n.t('ContextMenu.Back'),
|
||||
enabled: webContents.canGoBack(),
|
||||
click: () => {
|
||||
webContents.goBack();
|
||||
|
|
@ -429,7 +429,7 @@ export class MenuService implements IMenuService {
|
|||
);
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('ContextMenu.Forward'),
|
||||
label: i18n.t('ContextMenu.Forward'),
|
||||
enabled: webContents.canGoForward(),
|
||||
click: () => {
|
||||
webContents.goForward();
|
||||
|
|
@ -438,7 +438,7 @@ export class MenuService implements IMenuService {
|
|||
);
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('ContextMenu.Reload'),
|
||||
label: i18n.t('ContextMenu.Reload'),
|
||||
click: () => {
|
||||
webContents.reload();
|
||||
},
|
||||
|
|
@ -446,7 +446,7 @@ export class MenuService implements IMenuService {
|
|||
);
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('ContextMenu.RestartService'),
|
||||
label: i18n.t('ContextMenu.RestartService'),
|
||||
click: async () => {
|
||||
const workspace = await this.workspaceService.getActiveWorkspace();
|
||||
if (workspace !== undefined) {
|
||||
|
|
@ -458,7 +458,7 @@ export class MenuService implements IMenuService {
|
|||
);
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: sidebar ? i18next.t('Preference.HideSideBar') : i18next.t('Preference.ShowSideBar'),
|
||||
label: sidebar ? i18n.t('Preference.HideSideBar') : i18n.t('Preference.ShowSideBar'),
|
||||
click: async () => {
|
||||
await this.preferenceService.set('sidebar', !sidebar);
|
||||
await this.workspaceViewService.realignActiveWorkspace();
|
||||
|
|
@ -468,28 +468,28 @@ export class MenuService implements IMenuService {
|
|||
menu.append(new MenuItem({ type: 'separator' }));
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: i18next.t('ContextMenu.More'),
|
||||
label: i18n.t('ContextMenu.More'),
|
||||
submenu: [
|
||||
{
|
||||
label: i18next.t('ContextMenu.Preferences'),
|
||||
label: i18n.t('ContextMenu.Preferences'),
|
||||
click: async () => await this.windowService.open(WindowNames.preferences),
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: i18next.t('ContextMenu.About'),
|
||||
label: i18n.t('ContextMenu.About'),
|
||||
click: async () => await this.windowService.open(WindowNames.about),
|
||||
},
|
||||
{
|
||||
label: i18next.t('ContextMenu.TidGiSupport'),
|
||||
label: i18n.t('ContextMenu.TidGiSupport'),
|
||||
click: async () => await shell.openExternal('https://github.com/tiddly-gittly/TidGi-Desktop/issues/new/choose'),
|
||||
},
|
||||
{
|
||||
label: i18next.t('ContextMenu.TidGiWebsite'),
|
||||
label: i18n.t('ContextMenu.TidGiWebsite'),
|
||||
click: async () => await shell.openExternal('https://github.com/tiddly-gittly/TidGi-Desktop'),
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: i18next.t('ContextMenu.Quit'),
|
||||
label: i18n.t('ContextMenu.Quit'),
|
||||
click: () => app.quit(),
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
|
||||
export class ZxInitializationError extends Error {
|
||||
constructor(extraMessage?: string) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import serviceIdentifier from '@services/serviceIdentifier';
|
|||
import type { IWindowService } from '@services/windows/interface';
|
||||
import type { INotificationService } from '@services/notifications/interface';
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import { IPreferences, IPreferenceService } from './interface';
|
||||
import { defaultPreferences } from './defaultPreferences';
|
||||
import { lazyInject } from '@services/container';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
|
||||
export class ViewLoadUrlError extends Error {
|
||||
constructor(initialUrl: string, additionalMessage = '') {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import type { IWindowService } from '@services/windows/interface';
|
|||
import type { IMenuService } from '@services/menu/interface';
|
||||
|
||||
import { WindowNames, IBrowserViewMetaData } from '@services/windows/WindowProperties';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import getViewBounds from '@services/libs/getViewBounds';
|
||||
import { IWorkspace } from '@services/workspaces/interface';
|
||||
import setupViewEventHandlers from './setupViewEventHandlers';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import { IWorkspace } from '@services/workspaces/interface';
|
||||
|
||||
export class CopyWikiTemplateError extends Error {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import type { IGitService, IGitUserInfos } from '@services/git/interface';
|
|||
import type { IWorkspaceViewService } from '@services/workspacesView/interface';
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import { logger, wikiOutputToFile, refreshOutputFile, getWikiLogFilePath } from '@services/libs/log';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import { lazyInject } from '@services/container';
|
||||
import { TIDDLYWIKI_TEMPLATE_FOLDER_PATH, TIDDLERS_PATH } from '@/constants/paths';
|
||||
import { updateSubWikiPluginContent, getSubWikiPluginContent, ISubWikiPluginContent } from './plugin/subWikiPlugin';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { IGitUserInfos } from '@services/git/interface';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
|
||||
export class InitWikiGitError extends Error {
|
||||
constructor(extraMessage?: string) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import { WindowNames } from '@services/windows/WindowProperties';
|
|||
import { lazyInject } from '@services/container';
|
||||
|
||||
import { logger } from '@services/libs/log';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import { IWikiGitWorkspaceService } from './interface';
|
||||
import { InitWikiGitError, InitWikiGitRevertError, InitWikiGitSyncedWikiNoGitUserInfoError } from './error';
|
||||
import { SupportedStorageServices } from '@services/types';
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import type { IWorkspaceViewService } from '@services/workspacesView/interface';
|
|||
import type { IMenuService } from '@services/menu/interface';
|
||||
import { Channels, WindowChannel, MetaDataChannel, ViewChannel } from '@/constants/channels';
|
||||
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import getViewBounds from '@services/libs/getViewBounds';
|
||||
import getFromRenderer from '@services/libs/getFromRenderer';
|
||||
import { lazyInject } from '@services/container';
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import type { IWikiGitWorkspaceService } from '@services/wikiGitWorkspace/interf
|
|||
import { SupportedStorageServices } from '@services/types';
|
||||
import { lazyInject } from '@services/container';
|
||||
import type { IWorkspaceService, IWorkspace, IWorkspaceMetaData, INewWorkspaceConfig, IWorkspaceWithMetadata } from './interface';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import { defaultServerIP } from '@/constants/urls';
|
||||
import { logger } from '@services/libs/log';
|
||||
import { workspaceSorter } from './utils';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
|
||||
export class WorkspaceFailedToLoadError extends Error {
|
||||
constructor(extraMessage?: string, url?: string) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { injectable } from 'inversify';
|
|||
import { delay, mapSeries } from 'bluebird';
|
||||
|
||||
import serviceIdentifier from '@services/serviceIdentifier';
|
||||
import i18n from '@services/libs/i18n';
|
||||
import { i18n } from '@services/libs/i18n';
|
||||
import type { IViewService } from '@services/view/interface';
|
||||
import type { IWorkspaceService, IWorkspace } from '@services/workspaces/interface';
|
||||
import type { IWindowService } from '@services/windows/interface';
|
||||
|
|
@ -82,13 +82,13 @@ export class WorkspaceView implements IWorkspaceViewService {
|
|||
if (workspace.storageService !== SupportedStorageServices.local) {
|
||||
const mainWindow = this.windowService.get(WindowNames.main);
|
||||
if (mainWindow === undefined) {
|
||||
throw new Error(i18n.t(`Error.MainWindowMissing`));
|
||||
throw new Error(i18n.t(`Error.MainWindowMissing`) ?? `Error.MainWindowMissing`);
|
||||
}
|
||||
const userInfo = this.authService.getStorageServiceUserInfo(workspace.storageService);
|
||||
if (userInfo === undefined) {
|
||||
// user not login into Github or something else
|
||||
void dialog.showMessageBox(mainWindow, {
|
||||
title: i18n.t('Dialog.StorageServiceUserInfoNoFound'),
|
||||
title: i18n.t('Dialog.StorageServiceUserInfoNoFound') ?? 'Dialog.StorageServiceUserInfoNoFound',
|
||||
message: i18n.t('Dialog.StorageServiceUserInfoNoFoundDetail'),
|
||||
buttons: ['OK'],
|
||||
cancelId: 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue