mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-16 10:27:36 +08:00
🚧 WIP: add i18n ing
This commit is contained in:
@@ -17,6 +17,7 @@ import pasteTemplate from '~/main/utils/pasteTemplate'
|
||||
import pkg from 'root/package.json'
|
||||
import { handleCopyUrl } from '~/main/utils/common'
|
||||
import { privacyManager } from '~/main/utils/privacyManager'
|
||||
import { T } from '#/i18n'
|
||||
let contextMenu: Menu | null
|
||||
let menu: Menu | null
|
||||
let tray: Tray | null
|
||||
@@ -41,7 +42,7 @@ export function createContextMenu () {
|
||||
})
|
||||
contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '关于',
|
||||
label: T('ABOUT'),
|
||||
click () {
|
||||
dialog.showMessageBox({
|
||||
title: 'PicGo',
|
||||
@@ -51,7 +52,7 @@ export function createContextMenu () {
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '打开详细窗口',
|
||||
label: T('OPEN_MAIN_WINDOW'),
|
||||
click () {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
settingWindow!.show()
|
||||
@@ -62,14 +63,14 @@ export function createContextMenu () {
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '选择默认图床',
|
||||
label: T('CHOOSE_DEFAULT_PICBED'),
|
||||
type: 'submenu',
|
||||
// @ts-ignore
|
||||
submenu
|
||||
},
|
||||
// @ts-ignore
|
||||
{
|
||||
label: '打开更新助手',
|
||||
label: T('OPEN_UPDATE_HELPER'),
|
||||
type: 'checkbox',
|
||||
checked: db.get('settings.showUpdateTip'),
|
||||
click () {
|
||||
@@ -78,13 +79,13 @@ export function createContextMenu () {
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '隐私协议',
|
||||
label: T('PRIVACY_AGREEMENT'),
|
||||
click () {
|
||||
privacyManager.show(false)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '重启应用',
|
||||
label: T('RELOAD_APP'),
|
||||
click () {
|
||||
app.relaunch()
|
||||
app.exit(0)
|
||||
@@ -93,7 +94,7 @@ export function createContextMenu () {
|
||||
// @ts-ignore
|
||||
{
|
||||
role: 'quit',
|
||||
label: '退出'
|
||||
label: T('QUIT')
|
||||
}
|
||||
])
|
||||
} else if (process.platform === 'linux') {
|
||||
@@ -106,7 +107,7 @@ export function createContextMenu () {
|
||||
|
||||
contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '打开详细窗口',
|
||||
label: T('OPEN_MAIN_WINDOW'),
|
||||
click () {
|
||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
settingWindow!.show()
|
||||
@@ -118,7 +119,7 @@ export function createContextMenu () {
|
||||
},
|
||||
// @ts-ignore
|
||||
{
|
||||
label: '打开更新助手',
|
||||
label: T('OPEN_UPDATE_HELPER'),
|
||||
type: 'checkbox',
|
||||
checked: db.get('settings.showUpdateTip'),
|
||||
click () {
|
||||
@@ -127,7 +128,7 @@ export function createContextMenu () {
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '关于应用',
|
||||
label: T('ABOUT'),
|
||||
click () {
|
||||
dialog.showMessageBox({
|
||||
title: 'PicGo',
|
||||
@@ -140,7 +141,7 @@ export function createContextMenu () {
|
||||
// @ts-ignore
|
||||
{
|
||||
role: 'quit',
|
||||
label: '退出'
|
||||
label: T('QUIT')
|
||||
}
|
||||
])
|
||||
}
|
||||
@@ -214,7 +215,7 @@ export function createTray () {
|
||||
for (let i = 0; i < imgs.length; i++) {
|
||||
pasteText.push(pasteTemplate(pasteStyle, imgs[i], db.get('settings.customLink')))
|
||||
const notification = new Notification({
|
||||
title: '上传成功',
|
||||
title: T('UPLOAD_SUCCESSFULLY'),
|
||||
body: imgs[i].imgUrl!,
|
||||
icon: files[i]
|
||||
})
|
||||
|
||||
18
src/main/lifeCycle/fixPath.ts
Normal file
18
src/main/lifeCycle/fixPath.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
// TODO: so how to import pure esm module in electron main process????? help wanted
|
||||
|
||||
// just copy the fix-path because I can't import pure ESM module in electron main process
|
||||
|
||||
const shellPath = require('shell-path')
|
||||
|
||||
export default function fixPath () {
|
||||
if (process.platform === 'win32') {
|
||||
return
|
||||
}
|
||||
|
||||
process.env.PATH = shellPath.sync() || [
|
||||
'./node_modules/.bin',
|
||||
'/.nodebrew/current/bin',
|
||||
'/usr/local/bin',
|
||||
process.env.PATH
|
||||
].join(':')
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import bus from '@core/bus'
|
||||
import { privacyManager } from '~/main/utils/privacyManager'
|
||||
import logger from 'apis/core/picgo/logger'
|
||||
import picgo from 'apis/core/picgo'
|
||||
import fixPath from './fixPath'
|
||||
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||
|
||||
@@ -57,8 +58,6 @@ const handleStartUpFiles = (argv: string[], cwd: string) => {
|
||||
class LifeCycle {
|
||||
private async beforeReady () {
|
||||
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
|
||||
// https://stackoverflow.com/questions/56691391/dynamic-loading-of-external-modules-in-webpack-fails
|
||||
const fixPath = (await import(/* webpackIgnore: true */ 'fix-path')).default
|
||||
// fix the $PATH in macOS & linux
|
||||
fixPath()
|
||||
beforeOpen()
|
||||
|
||||
27
src/universal/i18n/index.ts
Normal file
27
src/universal/i18n/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ZH_CN } from './zh-CN'
|
||||
import { ObjectAdapter, I18n } from '@picgo/i18n'
|
||||
|
||||
const languageList = {
|
||||
'zh-CN': ZH_CN
|
||||
}
|
||||
|
||||
const lowercaseKeys = (obj: any) =>
|
||||
Object.keys(obj).reduce((acc: any, key: string) => {
|
||||
acc[key.toLowerCase()] = obj[key]
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
// FIXME: @picgo/i18n no lowecase
|
||||
const objectAdapter = new ObjectAdapter(lowercaseKeys(languageList))
|
||||
|
||||
const i18n = new I18n({
|
||||
adapter: objectAdapter,
|
||||
defaultLanguage: 'zh-cn'
|
||||
})
|
||||
|
||||
// FIXME: @picgo/i18n args should be optional
|
||||
const T = (key: ILocalesKey, args: IStringKeyMap = {}): string => {
|
||||
return i18n.translate(key, args)!
|
||||
}
|
||||
|
||||
export { i18n, T }
|
||||
12
src/universal/i18n/zh-CN.ts
Normal file
12
src/universal/i18n/zh-CN.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const ZH_CN = {
|
||||
ABOUT: '关于',
|
||||
OPEN_MAIN_WINDOW: '打开主窗口',
|
||||
CHOOSE_DEFAULT_PICBED: '选择默认图床',
|
||||
OPEN_UPDATE_HELPER: '打开更新助手',
|
||||
PRIVACY_AGREEMENT: '隐私协议',
|
||||
RELOAD_APP: '重启应用',
|
||||
UPLOAD_SUCCESSFULLY: '上传成功',
|
||||
QUIT: '退出'
|
||||
}
|
||||
|
||||
export type ILocalesKey = keyof typeof ZH_CN
|
||||
2
src/universal/types/types.d.ts
vendored
2
src/universal/types/types.d.ts
vendored
@@ -335,3 +335,5 @@ interface IMiniWindowPos {
|
||||
}
|
||||
|
||||
type PromiseResType<T> = T extends Promise<infer R> ? R : T
|
||||
|
||||
type ILocalesKey = import('#/i18n/zh-CN').ILocalesKey
|
||||
|
||||
Reference in New Issue
Block a user