🚧 WIP: main process i18n

This commit is contained in:
PiEgg 2022-01-11 21:50:29 +08:00
parent c2991dde2f
commit c19f741243
13 changed files with 121 additions and 60 deletions

View File

@ -215,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: T('UPLOAD_SUCCESSFULLY'),
title: T('UPLOAD_SUCCEED'),
body: imgs[i].imgUrl!,
icon: files[i]
})

View File

@ -9,6 +9,7 @@ import pasteTemplate from '~/main/utils/pasteTemplate'
import db, { GalleryDB } from '~/main/apis/core/datastore'
import { handleCopyUrl } from '~/main/utils/common'
import { handleUrlEncode } from '#/utils/common'
import { T } from '#/i18n/index'
export const uploadClipboardFiles = async (): Promise<string> => {
const win = windowManager.getAvailableWindow()
const img = await uploader.setWebContents(win!.webContents).upload()
@ -18,7 +19,7 @@ export const uploadClipboardFiles = async (): Promise<string> => {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
handleCopyUrl(pasteTemplate(pasteStyle, img[0], db.get('settings.customLink')))
const notification = new Notification({
title: '上传成功',
title: T('UPLOAD_SUCCEED'),
body: img[0].imgUrl!,
icon: img[0].imgUrl
})
@ -33,8 +34,8 @@ export const uploadClipboardFiles = async (): Promise<string> => {
return handleUrlEncode(img[0].imgUrl as string)
} else {
const notification = new Notification({
title: '上传不成功',
body: '你剪贴板最新的一条记录不是图片哦'
title: T('UPLOAD_FAILED'),
body: T('TIPS_UPLOAD_NOT_PICTURES')
})
notification.show()
return ''
@ -54,7 +55,7 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
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_SUCCEED'),
body: imgs[i].imgUrl!,
icon: files[i].path
})

View File

@ -14,6 +14,7 @@ import { IPicGo } from 'picgo'
import { showNotification, calcDurationRange } from '~/main/utils/common'
import { RENAME_FILE_NAME, TALKING_DATA_EVENT } from '~/universal/events/constants'
import logger from '@core/picgo/logger'
import { T } from '~/universal/i18n'
const waitForShow = (webcontent: WebContents) => {
return new Promise<void>((resolve) => {
@ -71,8 +72,8 @@ class Uploader {
picgo.on('beforeTransform', () => {
if (db.get('settings.uploadNotification')) {
const notification = new Notification({
title: '上传进度',
body: '正在上传'
title: T('UPLOAD_PROGRESS'),
body: T('UPLOADING')
})
notification.show()
}
@ -129,7 +130,7 @@ class Uploader {
logger.error(e)
setTimeout(() => {
showNotification({
title: '上传失败',
title: T('UPLOAD_FAILED'),
body: util.format(e.stack),
clickToCopy: true
})

View File

@ -3,6 +3,7 @@ import path from 'path'
import { app as APP } from 'electron'
import { getLogger } from '@core/utils/localLogger'
import dayjs from 'dayjs'
import { T } from '~/universal/i18n'
const STORE_PATH = APP.getPath('userData')
const configFilePath = path.join(STORE_PATH, 'data.json')
const configFileBackupPath = path.join(STORE_PATH, 'data.bak.json')
@ -11,8 +12,8 @@ let _configFilePath = ''
let hasCheckPath = false
const errorMsg = {
broken: 'PicGo 配置文件损坏,已经恢复为默认配置',
brokenButBackup: 'PicGo 配置文件损坏,已经恢复为备份配置'
broken: T('TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT'),
brokenButBackup: T('TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP')
}
/** ensure notification list */
@ -36,7 +37,7 @@ function dbChecker () {
}
let configFile: string = '{}'
const optionsTpl = {
title: '注意',
title: T('TIPS_NOTICE'),
body: ''
}
// config save bak
@ -51,7 +52,9 @@ function dbChecker () {
JSON.parse(configFile)
fs.writeFileSync(configFilePath, configFile, { encoding: 'utf-8' })
const stats = fs.statSync(configFileBackupPath)
optionsTpl.body = `${errorMsg.brokenButBackup}\n备份文件版本${dayjs(stats.mtime).format('YYYY-MM-DD HH:mm:ss')}`
optionsTpl.body = `${errorMsg.brokenButBackup}\n${T('TIPS_PICGO_BACKUP_FILE_VERSION', {
v: dayjs(stats.mtime).format('YYYY-MM-DD HH:mm:ss')
})}`
global.notificationList?.push(optionsTpl)
return
} catch (e) {
@ -98,8 +101,8 @@ function dbPathChecker (): string {
const logger = getLogger(picgoLogPath)
if (!hasCheckPath) {
const optionsTpl = {
title: '注意',
body: '自定义文件解析出错,请检查路径内容是否正确'
title: T('TIPS_NOTICE'),
body: T('TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR')
}
global.notificationList?.push(optionsTpl)
hasCheckPath = true

View File

@ -5,6 +5,7 @@ import FileSync from 'lowdb/adapters/FileSync'
import fs from 'fs-extra'
import { dbPathChecker, dbPathDir, getGalleryDBPath } from './dbChecker'
import { DBStore } from '@picgo/store'
import { T } from '~/universal/i18n'
const STORE_PATH = dbPathDir()
@ -38,7 +39,7 @@ class ConfigStore {
enable: true,
key: 'CommandOrControl+Shift+P',
name: 'upload',
label: '快捷上传'
label: T('QUICK_UPLOAD')
}).write()
}
}

View File

@ -17,6 +17,7 @@ import {
SHOW_INPUT_BOX
} from '~/universal/events/constants'
import { DBStore } from '@picgo/store'
import { T } from '~/universal/i18n'
// Cross-process support may be required in the future
class GuiApi implements IGuiApi {
@ -81,7 +82,7 @@ class GuiApi implements IGuiApi {
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_SUCCEED'),
body: imgs[i].imgUrl as string,
icon: imgs[i].imgUrl
})
@ -151,8 +152,8 @@ class GuiApi implements IGuiApi {
return new Promise((resolve) => {
const guiApi = GuiApi.getInstance()
guiApi.showMessageBox({
title: '警告',
message: '有插件正在试图删除一些相册图片,是否继续',
title: T('TIPS_WARNING'),
message: T('TIPS_PLUGIN_REMOVE_GALLERY_ITEM'),
type: 'info',
buttons: ['Yes', 'No']
}).then(res => {

View File

@ -37,6 +37,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'
const STORE_PATH = app.getPath('userData')
@ -51,7 +52,7 @@ export default {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
handleCopyUrl(pasteTemplate(pasteStyle, img[0], db.get('settings.customLink')))
const notification = new Notification({
title: '上传成功',
title: T('UPLOAD_SUCCEED'),
body: img[0].imgUrl!,
// icon: file[0]
icon: img[0].imgUrl
@ -79,14 +80,14 @@ export default {
evt.sender.send('updateShortKeyResponse', result)
if (result) {
const notification = new Notification({
title: '操作成功',
body: '你的快捷键已经修改成功'
title: T('OPERATION_SUCCEED'),
body: T('TIPS_SHORTCUT_MODIFIED_SUCCEED')
})
notification.show()
} else {
const notification = new Notification({
title: '操作失败',
body: '快捷键冲突,请重新设置'
title: T('OPERATION_FAILED'),
body: T('TIPS_SHORTCUT_MODIFIED_CONFLICT')
})
notification.show()
}
@ -96,14 +97,14 @@ export default {
const result = shortKeyHandler.bindOrUnbindShortKey(item, from)
if (result) {
const notification = new Notification({
title: '操作成功',
body: '你的快捷键已经修改成功'
title: T('OPERATION_SUCCEED'),
body: T('TIPS_SHORTCUT_MODIFIED_SUCCEED')
})
notification.show()
} else {
const notification = new Notification({
title: '操作失败',
body: '快捷键冲突,请重新设置'
title: T('OPERATION_FAILED'),
body: T('TIPS_SHORTCUT_MODIFIED_CONFLICT')
})
notification.show()
}
@ -111,8 +112,8 @@ export default {
ipcMain.on('updateCustomLink', () => {
const notification = new Notification({
title: '操作成功',
body: '你的自定义链接格式已经修改成功'
title: T('OPERATION_SUCCEED'),
body: T('TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED')
})
notification.show()
})

View File

@ -31,6 +31,7 @@ import {
import { GalleryDB } from 'apis/core/datastore'
import { IObject, IFilter } from '@picgo/store/dist/types'
import pasteTemplate from '../utils/pasteTemplate'
import { T } from '~/universal/i18n'
// eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
@ -143,7 +144,7 @@ const handlePluginInstall = () => {
shortKeyHandler.registerPluginShortKey(res.body[0])
} else {
showNotification({
title: '插件安装失败',
title: T('PLUGIN_INSTALL_FAILED'),
body: res.body as string
})
}
@ -161,7 +162,7 @@ const handlePluginUninstall = async (fullName: string) => {
shortKeyHandler.unregisterPluginShortKey(res.body[0])
} else {
showNotification({
title: '插件卸载失败',
title: T('PLUGIN_UNINSTALL_FAILED'),
body: res.body as string
})
}
@ -177,7 +178,7 @@ const handlePluginUpdate = async (fullName: string) => {
window.webContents.send('updateSuccess', res.body[0])
} else {
showNotification({
title: '插件更新失败',
title: T('PLUGIN_UPDATE_FAILED'),
body: res.body as string
})
}
@ -189,8 +190,8 @@ const handleNPMError = (): IDispose => {
const handler = (msg: string) => {
if (msg === 'NPM is not installed') {
dialog.showMessageBox({
title: '发生错误',
message: '请安装Node.js并重启PicGo再继续操作',
title: T('TIPS_ERROR'),
message: T('TIPS_INSTALL_NODE_AND_RELOAD_PICGO'),
buttons: ['Yes']
}).then((res) => {
if (res.response === 0) {
@ -265,12 +266,12 @@ const handleImportLocalPlugin = () => {
const list = getPluginList()
event.sender.send('pluginList', list)
showNotification({
title: '导入插件成功',
title: T('PLUGIN_IMPORT_SUCCEED'),
body: ''
})
} else {
showNotification({
title: '导入插件失败',
title: T('PLUGIN_IMPORT_FAILED'),
body: res.body as string
})
}

View File

@ -12,6 +12,7 @@ import GuiApi from 'apis/gui'
import { PICGO_CONFIG_PLUGIN, PICGO_HANDLE_PLUGIN_ING, PICGO_TOGGLE_PLUGIN } from '~/universal/events/constants'
import picgoCoreIPC from '~/main/events/picgoCoreIPC'
import { PicGo as PicGoCore } from 'picgo'
import { T } from '~/universal/i18n'
interface GuiMenuItem {
label: string
@ -39,7 +40,7 @@ const buildMiniPageMenu = () => {
})
const template = [
{
label: '打开详细窗口',
label: T('OPEN_MAIN_WINDOW'),
click () {
windowManager.get(IWindowList.SETTING_WINDOW)!.show()
if (windowManager.has(IWindowList.MINI_WINDOW)) {
@ -48,30 +49,30 @@ const buildMiniPageMenu = () => {
}
},
{
label: '选择默认图床',
label: T('CHOOSE_DEFAULT_PICBED'),
type: 'submenu',
submenu
},
{
label: '剪贴板图片上传',
label: T('UPLOAD_BY_CLIPBOARD'),
click () {
uploadClipboardFiles()
}
},
{
label: '隐藏窗口',
label: T('HIDE_WINDOW'),
click () {
BrowserWindow.getFocusedWindow()!.hide()
}
},
{
label: '隐私协议',
label: T('PRIVACY_AGREEMENT'),
click () {
privacyManager.show(false)
}
},
{
label: '重启应用',
label: T('RELOAD_APP'),
click () {
app.relaunch()
app.exit(0)
@ -79,7 +80,7 @@ const buildMiniPageMenu = () => {
},
{
role: 'quit',
label: '退出'
label: T('QUIT')
}
]
// @ts-ignore
@ -89,7 +90,7 @@ const buildMiniPageMenu = () => {
const buildMainPageMenu = () => {
const template = [
{
label: '关于',
label: T('ABOUT'),
click () {
dialog.showMessageBox({
title: 'PicGo',
@ -99,20 +100,20 @@ const buildMainPageMenu = () => {
}
},
{
label: '赞助PicGo',
label: T('SPONSOR_PICGO'),
click () {
// TODO: show donation
}
},
{
label: '生成图床配置二维码',
label: T('SHOW_PICBED_QRCODE'),
click () {
// TODO: qrcode
// _this.qrcodeVisible = true
}
},
{
label: '隐私协议',
label: T('PRIVACY_AGREEMENT'),
click () {
privacyManager.show(false)
}
@ -169,7 +170,7 @@ const handleRestoreState = (item: string, name: string): void => {
const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
const menu = [{
label: '启用插件',
label: T('ENABLE_PLUGIN'),
enabled: !plugin.enabled,
click () {
picgo.saveConfig({
@ -179,7 +180,7 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
window.webContents.send(PICGO_TOGGLE_PLUGIN, plugin.fullName, true)
}
}, {
label: '禁用插件',
label: T('DISABLE_PLUGIN'),
enabled: plugin.enabled,
click () {
picgo.saveConfig({
@ -196,14 +197,14 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
}
}
}, {
label: '卸载插件',
label: T('UNINSTALL_PLUGIN'),
click () {
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
window.webContents.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
picgoCoreIPC.handlePluginUninstall(plugin.fullName)
}
}, {
label: '更新插件',
label: T('UPDATE_PLUGIN'),
click () {
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
window.webContents.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName)
@ -213,7 +214,9 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
for (const i in plugin.config) {
if (plugin.config[i].config.length > 0) {
const obj = {
label: `配置${i} - ${plugin.config[i].fullName || plugin.config[i].name}`,
label: T('CONFIG_THING', {
c: `${i} - ${plugin.config[i].fullName || plugin.config[i].name}`
}),
click () {
const window = windowManager.get(IWindowList.SETTING_WINDOW)!
const currentType = i
@ -231,7 +234,7 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => {
const currentTransformer = picgo.getConfig<string>('picBed.transformer') || 'path'
const pluginTransformer = plugin.config.transformer.name
const obj = {
label: `${currentTransformer === pluginTransformer ? '禁用' : '启用'}transformer - ${plugin.config.transformer.name}`,
label: `${currentTransformer === pluginTransformer ? T('DISABLE') : T('ENABLE')}transformer - ${plugin.config.transformer.name}`,
click () {
const transformer = plugin.config.transformer.name
const currentTransformer = picgo.getConfig<string>('picBed.transformer') || 'path'

View File

@ -3,6 +3,7 @@ import ConfigStore from '~/main/apis/core/datastore'
import path from 'path'
import fse from 'fs-extra'
import { PicGo as PicGoCore } from 'picgo'
import { T } from '~/universal/i18n'
// from v2.1.2
const updateShortKeyFromVersion212 = (db: typeof ConfigStore, shortKeyConfig: IShortKeyConfigs | IOldShortKeyConfigs) => {
// #557 极端情况可能会出现配置不存在,需要重新写入
@ -11,7 +12,7 @@ const updateShortKeyFromVersion212 = (db: typeof ConfigStore, shortKeyConfig: IS
enable: true,
key: 'CommandOrControl+Shift+P',
name: 'upload',
label: '快捷上传'
label: T('QUICK_UPLOAD')
}
db.set('settings.shortKey[picgo:upload]', defaultShortKeyConfig)
return true
@ -22,7 +23,7 @@ const updateShortKeyFromVersion212 = (db: typeof ConfigStore, shortKeyConfig: IS
enable: true,
key: shortKeyConfig.upload,
name: 'upload',
label: '快捷上传'
label: T('QUICK_UPLOAD')
}
// @ts-ignore
delete shortKeyConfig.upload

View File

@ -2,6 +2,7 @@ import db from '~/main/apis/core/datastore'
import { ipcMain } from 'electron'
import { showMessageBox } from '~/main/utils/common'
import { SHOW_PRIVACY_MESSAGE } from '~/universal/events/constants'
import { T } from '~/universal/i18n'
class PrivacyManager {
async init () {
@ -25,7 +26,7 @@ class PrivacyManager {
const res = await showMessageBox({
type: 'info',
buttons: showCancel ? ['Yes', 'No'] : ['Yes'],
title: '隐私协议',
title: T('PRIVACY_AGREEMENT'),
message: `
使使使使使

View File

@ -3,6 +3,7 @@ import db from '~/main/apis/core/datastore'
import axios from 'axios'
import pkg from 'root/package.json'
import { lt } from 'semver'
import { T } from '~/universal/i18n'
const version = pkg.version
const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases/latest'
const releaseUrlBackup = 'https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@latest/package.json'
@ -30,10 +31,12 @@ const checkVersion = async () => {
if (result) {
dialog.showMessageBox({
type: 'info',
title: '发现新版本',
title: T('FIND_NEW_VERSION'),
buttons: ['Yes', 'No'],
message: `发现新版本${latest},更新了很多功能,是否去下载最新的版本?`,
checkboxLabel: '以后不再提醒',
message: T('TIPS_FIND_NEW_VERSION', {
v: latest
}),
checkboxLabel: T('NO_MORE_NOTICE'),
checkboxChecked: false
}).then(res => {
if (res.response === 0) { // if selected yes

View File

@ -1,3 +1,4 @@
/* eslint-disable no-template-curly-in-string */
export const ZH_CN = {
ABOUT: '关于',
OPEN_MAIN_WINDOW: '打开主窗口',
@ -5,7 +6,50 @@ export const ZH_CN = {
OPEN_UPDATE_HELPER: '打开更新助手',
PRIVACY_AGREEMENT: '隐私协议',
RELOAD_APP: '重启应用',
UPLOAD_SUCCESSFULLY: '上传成功',
UPLOAD_SUCCEED: '上传成功',
UPLOAD_FAILED: '上传失败',
UPLOAD_PROGRESS: '上传进度',
OPERATION_SUCCEED: '操作成功',
OPERATION_FAILED: '操作失败',
UPLOADING: '正在上传',
QUICK_UPLOAD: '快捷上传',
UPLOAD_BY_CLIPBOARD: '剪贴板图片上传',
HIDE_WINDOW: '隐藏窗口',
SPONSOR_PICGO: '赞助 PicGo',
SHOW_PICBED_QRCODE: '生成图床配置二维码',
ENABLE: '启用',
DISABLE: '禁用',
CONFIG_THING: '配置${c}',
FIND_NEW_VERSION: '发现新版本',
NO_MORE_NOTICE: '以后不再提醒',
// plugins
PLUGIN_INSTALL_SUCCEED: '插件安装成功',
PLUGIN_INSTALL_FAILED: '插件安装失败',
PLUGIN_UNINSTALL_SUCCEED: '插件卸载成功',
PLUGIN_UNINSTALL_FAILED: '插件卸载失败',
PLUGIN_UPDATE_SUCCEED: '插件更新成功',
PLUGIN_UPDATE_FAILED: '插件更新失败',
PLUGIN_IMPORT_SUCCEED: '插件导入成功',
PLUGIN_IMPORT_FAILED: '插件导入失败',
ENABLE_PLUGIN: '启用插件',
DISABLE_PLUGIN: '禁用插件',
UNINSTALL_PLUGIN: '卸载插件',
UPDATE_PLUGIN: '更新插件',
// tips
TIPS_NOTICE: '注意',
TIPS_WARNING: '警告',
TIPS_ERROR: '发生错误',
TIPS_INSTALL_NODE_AND_RELOAD_PICGO: '请安装Node.js并重启PicGo再继续操作',
TIPS_PLUGIN_REMOVE_GALLERY_ITEM: '有插件正在试图删除一些相册图片,是否继续',
TIPS_UPLOAD_NOT_PICTURES: '剪贴板最新的一条记录不是图片',
TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: 'PicGo 配置文件损坏,已经恢复为默认配置',
TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: 'PicGo 配置文件损坏,已经恢复为备份配置',
TIPS_PICGO_BACKUP_FILE_VERSION: '备份文件版本: ${v}',
TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: '自定义文件解析出错,请检查路径内容是否正确',
TIPS_SHORTCUT_MODIFIED_SUCCEED: '快捷键已经修改成功',
TIPS_SHORTCUT_MODIFIED_CONFLICT: '快捷键冲突,请重新设置',
TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: '自定义链接格式已经修改成功',
TIPS_FIND_NEW_VERSION: '发现新版本${v},更新了很多功能,是否去下载最新的版本?',
QUIT: '退出'
}