Feature: add i18n for en

This commit is contained in:
PiEgg
2022-02-20 21:30:22 +08:00
parent 7f6d58f992
commit 1936ccfedc
15 changed files with 333 additions and 19 deletions

View File

@@ -10,9 +10,19 @@ import { CREATE_APP_MENU } from '@core/bus/constants'
import db from '~/main/apis/core/datastore'
import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants'
import { app } from 'electron'
import { i18n } from '~/universal/i18n'
import { URLSearchParams } from 'url'
const windowList = new Map<IWindowList, IWindowListItem>()
const handleWindowParams = (windowURL: string) => {
const [baseURL, hash = ''] = windowURL.split('#')
const search = new URLSearchParams()
const lang = i18n.getLanguage()
search.append('lang', lang)
return `${baseURL}?${search.toString()}#${hash}`
}
windowList.set(IWindowList.TRAY_WINDOW, {
isValid: process.platform !== 'linux',
multiple: false,
@@ -35,7 +45,7 @@ windowList.set(IWindowList.TRAY_WINDOW, {
}
},
callback (window) {
window.loadURL(TRAY_WINDOW_URL)
window.loadURL(handleWindowParams(TRAY_WINDOW_URL))
window.on('blur', () => {
window.hide()
})
@@ -76,7 +86,7 @@ windowList.set(IWindowList.SETTING_WINDOW, {
return options
},
callback (window, windowManager) {
window.loadURL(SETTING_WINDOW_URL)
window.loadURL(handleWindowParams(SETTING_WINDOW_URL))
window.on('closed', () => {
bus.emit(TOGGLE_SHORTKEY_MODIFIED_MODE, false)
if (process.platform === 'linux') {
@@ -118,7 +128,7 @@ windowList.set(IWindowList.MINI_WINDOW, {
return obj
},
callback (window) {
window.loadURL(MINI_WINDOW_URL)
window.loadURL(handleWindowParams(MINI_WINDOW_URL))
}
})
@@ -149,7 +159,7 @@ windowList.set(IWindowList.RENAME_WINDOW, {
return options
},
async callback (window, windowManager) {
window.loadURL(RENAME_WINDOW_URL)
window.loadURL(handleWindowParams(RENAME_WINDOW_URL))
const currentWindow = windowManager.getAvailableWindow()
if (currentWindow && currentWindow.isVisible()) {
// bounds: { x: 821, y: 75, width: 800, height: 450 }

View File

@@ -27,7 +27,8 @@ import {
OPEN_URL,
RELOAD_APP,
SHOW_PLUGIN_PAGE_MENU,
SET_MINI_WINDOW_POS
SET_MINI_WINDOW_POS,
CHANGE_LANGUAGE
} from '#/events/constants'
import {
uploadClipboardFiles,
@@ -37,7 +38,7 @@ import picgoCoreIPC from './picgoCoreIPC'
import { handleCopyUrl } from '~/main/utils/common'
import { buildMainPageMenu, buildMiniPageMenu, buildPluginPageMenu, buildUploadPageMenu } from './remotes/menu'
import path from 'path'
import { T } from '~/universal/i18n'
import { i18n, T } from '~/universal/i18n'
const STORE_PATH = app.getPath('userData')
@@ -223,6 +224,10 @@ export default {
const window = BrowserWindow.getFocusedWindow()
window?.setBounds(pos)
})
ipcMain.on(CHANGE_LANGUAGE, (evt: IpcMainEvent, lang: string) => {
lang = lang || 'zh-CN'
i18n.setLanguage(lang)
})
},
dispose () {}
}

View File

@@ -81,9 +81,11 @@ const getPluginList = (): IPicGoPlugin[] => {
const pluginPKG = requireFunc(path.join(pluginPath, 'package.json'))
const uploaderName = plugin.uploader || ''
const transformerName = plugin.transformer || ''
let menu: IGuiMenuItem[] = []
let menu: Omit<IGuiMenuItem, 'handle'>[] = []
if (plugin.guiMenu) {
menu = plugin.guiMenu(picgo)
menu = plugin.guiMenu(picgo).map(item => ({
label: item.label
}))
}
let gui = false
if (pluginPKG.keywords && pluginPKG.keywords.length > 0) {
@@ -127,6 +129,8 @@ const getPluginList = (): IPicGoPlugin[] => {
const handleGetPluginList = () => {
ipcMain.on('getPluginList', (event: IpcMainEvent) => {
const list = getPluginList()
// here can just send JS Object not function
// or will cause [Failed to serialize arguments] error
event.sender.send('pluginList', list)
})
}

View File

@@ -35,6 +35,7 @@ import { privacyManager } from '~/main/utils/privacyManager'
import logger from 'apis/core/picgo/logger'
import picgo from 'apis/core/picgo'
import fixPath from './fixPath'
import { initI18n } from '~/main/utils/handleI18n'
const isDevelopment = process.env.NODE_ENV !== 'production'
@@ -61,6 +62,7 @@ class LifeCycle {
// fix the $PATH in macOS & linux
fixPath()
beforeOpen()
initI18n()
ipcList.listen()
busEventList.listen()
updateShortKeyFromVersion212(db, db.get('settings.shortKey'))

View File

@@ -0,0 +1,6 @@
import db from '~/main/apis/core/datastore'
import { i18n } from '#/i18n'
export const initI18n = () => {
const currentLanguage = db.get('settings.language') || 'zh-CN'
i18n.setLanguage(currentLanguage)
}