mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-11 08:19:01 +08:00
refactor(i18n): simplify i18n implementation and cleanup unused locales
- Rename i18next import to i18n for consistency - Standardize locale keys to lowercase format - Remove commented out locale imports and unused translations - Replace getI18n with direct t function usage in services - Clean up VS Code settings and commented i18n config
This commit is contained in:
parent
5b4f15d355
commit
b02678a714
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -32,11 +32,11 @@
|
|||||||
},
|
},
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"*.css": "tailwindcss",
|
".oxlintrc.json": "jsonc",
|
||||||
".oxlintrc.json": "jsonc"
|
"*.css": "tailwindcss"
|
||||||
},
|
},
|
||||||
"files.eol": "\n",
|
"files.eol": "\n",
|
||||||
"i18n-ally.defaultNamespace": "translation",
|
// "i18n-ally.defaultNamespace": "translation",
|
||||||
// "i18n-ally.displayLanguage": "zh-cn", // 界面显示语言
|
// "i18n-ally.displayLanguage": "zh-cn", // 界面显示语言
|
||||||
"i18n-ally.enabledFrameworks": [
|
"i18n-ally.enabledFrameworks": [
|
||||||
"react-i18next",
|
"react-i18next",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { getI18n } from '@main/utils/language'
|
import { t } from '@main/utils/language'
|
||||||
import type { MenuItemConstructorOptions } from 'electron'
|
import type { MenuItemConstructorOptions } from 'electron'
|
||||||
import { Menu } from 'electron'
|
import { Menu } from 'electron'
|
||||||
|
|
||||||
@ -26,12 +26,10 @@ class ContextMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private createInspectMenuItems(w: Electron.WebContents): MenuItemConstructorOptions[] {
|
private createInspectMenuItems(w: Electron.WebContents): MenuItemConstructorOptions[] {
|
||||||
const i18n = getI18n()
|
|
||||||
const { common } = i18n.translation
|
|
||||||
const template: MenuItemConstructorOptions[] = [
|
const template: MenuItemConstructorOptions[] = [
|
||||||
{
|
{
|
||||||
id: 'inspect',
|
id: 'inspect',
|
||||||
label: common.inspect,
|
label: t('common.inspect'),
|
||||||
click: () => {
|
click: () => {
|
||||||
w.toggleDevTools()
|
w.toggleDevTools()
|
||||||
},
|
},
|
||||||
@ -43,29 +41,27 @@ class ContextMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private createEditMenuItems(properties: Electron.ContextMenuParams): MenuItemConstructorOptions[] {
|
private createEditMenuItems(properties: Electron.ContextMenuParams): MenuItemConstructorOptions[] {
|
||||||
const i18n = getI18n()
|
|
||||||
const { common } = i18n.translation
|
|
||||||
const hasText = properties.selectionText.trim().length > 0
|
const hasText = properties.selectionText.trim().length > 0
|
||||||
const can = (type: string) => properties.editFlags[`can${type}`] && hasText
|
const can = (type: string) => properties.editFlags[`can${type}`] && hasText
|
||||||
|
|
||||||
const template: MenuItemConstructorOptions[] = [
|
const template: MenuItemConstructorOptions[] = [
|
||||||
{
|
{
|
||||||
id: 'copy',
|
id: 'copy',
|
||||||
label: common.copy,
|
label: t('common.copy'),
|
||||||
role: 'copy',
|
role: 'copy',
|
||||||
enabled: can('Copy'),
|
enabled: can('Copy'),
|
||||||
visible: properties.isEditable || hasText
|
visible: properties.isEditable || hasText
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'paste',
|
id: 'paste',
|
||||||
label: common.paste,
|
label: t('common.paste'),
|
||||||
role: 'paste',
|
role: 'paste',
|
||||||
enabled: properties.editFlags.canPaste,
|
enabled: properties.editFlags.canPaste,
|
||||||
visible: properties.isEditable
|
visible: properties.isEditable
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'cut',
|
id: 'cut',
|
||||||
label: common.cut,
|
label: t('common.cut'),
|
||||||
role: 'cut',
|
role: 'cut',
|
||||||
enabled: can('Cut'),
|
enabled: can('Cut'),
|
||||||
visible: properties.isEditable
|
visible: properties.isEditable
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { preferenceService } from '@data/PreferenceService'
|
import { preferenceService } from '@data/PreferenceService'
|
||||||
import { isLinux, isMac, isWin } from '@main/constant'
|
import { isLinux, isMac, isWin } from '@main/constant'
|
||||||
import { getI18n } from '@main/utils/language'
|
import { t } from '@main/utils/language'
|
||||||
import type { MenuItemConstructorOptions } from 'electron'
|
import type { MenuItemConstructorOptions } from 'electron'
|
||||||
import { app, Menu, nativeImage, nativeTheme, Tray } from 'electron'
|
import { app, Menu, nativeImage, nativeTheme, Tray } from 'electron'
|
||||||
|
|
||||||
@ -72,23 +72,20 @@ export class TrayService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateContextMenu() {
|
private updateContextMenu() {
|
||||||
const i18n = getI18n()
|
|
||||||
const { tray: trayLocale, selection: selectionLocale } = i18n.translation
|
|
||||||
|
|
||||||
const quickAssistantEnabled = preferenceService.get('feature.quick_assistant.enabled')
|
const quickAssistantEnabled = preferenceService.get('feature.quick_assistant.enabled')
|
||||||
const selectionAssistantEnabled = preferenceService.get('feature.selection.enabled')
|
const selectionAssistantEnabled = preferenceService.get('feature.selection.enabled')
|
||||||
|
|
||||||
const template = [
|
const template = [
|
||||||
{
|
{
|
||||||
label: trayLocale.show_window,
|
label: t('tray.show_window'),
|
||||||
click: () => windowService.showMainWindow()
|
click: () => windowService.showMainWindow()
|
||||||
},
|
},
|
||||||
quickAssistantEnabled && {
|
quickAssistantEnabled && {
|
||||||
label: trayLocale.show_mini_window,
|
label: t('tray.show_mini_window'),
|
||||||
click: () => windowService.showMiniWindow()
|
click: () => windowService.showMiniWindow()
|
||||||
},
|
},
|
||||||
(isWin || isMac) && {
|
(isWin || isMac) && {
|
||||||
label: selectionLocale.name + (selectionAssistantEnabled ? ' - On' : ' - Off'),
|
label: t('selection.name') + (selectionAssistantEnabled ? ' - On' : ' - Off'),
|
||||||
click: () => {
|
click: () => {
|
||||||
if (selectionService) {
|
if (selectionService) {
|
||||||
selectionService.toggleEnabled()
|
selectionService.toggleEnabled()
|
||||||
@ -98,7 +95,7 @@ export class TrayService {
|
|||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: trayLocale.quit,
|
label: t('tray.quit'),
|
||||||
click: () => this.quit()
|
click: () => this.quit()
|
||||||
}
|
}
|
||||||
].filter(Boolean) as MenuItemConstructorOptions[]
|
].filter(Boolean) as MenuItemConstructorOptions[]
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { loggerService } from '@logger'
|
|||||||
import { defaultLanguage } from '@shared/config/constant'
|
import { defaultLanguage } from '@shared/config/constant'
|
||||||
import type { LanguageVarious } from '@shared/data/preference/preferenceTypes'
|
import type { LanguageVarious } from '@shared/data/preference/preferenceTypes'
|
||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import i18next from 'i18next'
|
import i18n from 'i18next'
|
||||||
|
|
||||||
// import deDE from '../../renderer/src/i18n/locales/de-de.json'
|
// import deDE from '../../renderer/src/i18n/locales/de-de.json'
|
||||||
// import elGR from '../../renderer/src/i18n/locales/el-gr.json'
|
// import elGR from '../../renderer/src/i18n/locales/el-gr.json'
|
||||||
@ -19,9 +19,9 @@ import ZhTw from '../../renderer/src/i18n/locales/zh-tw.json'
|
|||||||
const logger = loggerService.withContext('i18n')
|
const logger = loggerService.withContext('i18n')
|
||||||
|
|
||||||
const resources = Object.fromEntries([
|
const resources = Object.fromEntries([
|
||||||
['en-US', EnUs],
|
['en-us', EnUs],
|
||||||
['zh-CN', ZhCn],
|
['zh-cn', ZhCn],
|
||||||
['zh-TW', ZhTw]
|
['zh-tw', ZhTw]
|
||||||
// ['ja-JP', JaJP],
|
// ['ja-JP', JaJP],
|
||||||
// ['ru-RU', RuRu],
|
// ['ru-RU', RuRu],
|
||||||
// ['de-DE', deDE],
|
// ['de-DE', deDE],
|
||||||
@ -47,7 +47,7 @@ export const getI18n = (): Record<string, any> => {
|
|||||||
return resources[language]
|
return resources[language]
|
||||||
}
|
}
|
||||||
|
|
||||||
const i18n = i18next.init({
|
i18n.init({
|
||||||
resources,
|
resources,
|
||||||
lng: getAppLanguage(),
|
lng: getAppLanguage(),
|
||||||
fallbackLng: defaultLanguage,
|
fallbackLng: defaultLanguage,
|
||||||
@ -60,4 +60,8 @@ const i18n = i18next.init({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export { i18n }
|
const t = i18n.t
|
||||||
|
|
||||||
|
const changeLang: typeof i18n.changeLanguage = i18n.changeLanguage
|
||||||
|
|
||||||
|
export { changeLang, i18n, t }
|
||||||
|
|||||||
@ -4,14 +4,14 @@ import { defaultLanguage } from '@shared/config/constant'
|
|||||||
import i18n from 'i18next'
|
import i18n from 'i18next'
|
||||||
import { initReactI18next } from 'react-i18next'
|
import { initReactI18next } from 'react-i18next'
|
||||||
|
|
||||||
import deDE from './locales/de-de.json'
|
// import deDE from './locales/de-de.json'
|
||||||
import elGR from './locales/el-gr.json'
|
// import elGR from './locales/el-gr.json'
|
||||||
import enUS from './locales/en-us.json'
|
import enUS from './locales/en-us.json'
|
||||||
import esES from './locales/es-es.json'
|
// import esES from './locales/es-es.json'
|
||||||
import frFR from './locales/fr-fr.json'
|
// import frFR from './locales/fr-fr.json'
|
||||||
import jaJP from './locales/ja-jp.json'
|
// import jaJP from './locales/ja-jp.json'
|
||||||
import ptPT from './locales/pt-pt.json'
|
// import ptPT from './locales/pt-pt.json'
|
||||||
import ruRU from './locales/ru-ru.json'
|
// import ruRU from './locales/ru-ru.json'
|
||||||
import zhCN from './locales/zh-cn.json'
|
import zhCN from './locales/zh-cn.json'
|
||||||
import zhTW from './locales/zh-tw.json'
|
import zhTW from './locales/zh-tw.json'
|
||||||
|
|
||||||
@ -19,15 +19,15 @@ const logger = loggerService.withContext('I18N')
|
|||||||
|
|
||||||
const resources = Object.fromEntries([
|
const resources = Object.fromEntries([
|
||||||
['en-US', enUS],
|
['en-US', enUS],
|
||||||
['ja-JP', jaJP],
|
// ['ja-JP', jaJP],
|
||||||
['ru-RU', ruRU],
|
// ['ru-RU', ruRU],
|
||||||
['zh-CN', zhCN],
|
['zh-CN', zhCN],
|
||||||
['zh-TW', zhTW],
|
['zh-TW', zhTW]
|
||||||
['de-DE', deDE],
|
// ['de-DE', deDE],
|
||||||
['el-GR', elGR],
|
// ['el-GR', elGR],
|
||||||
['es-ES', esES],
|
// ['es-ES', esES],
|
||||||
['fr-FR', frFR],
|
// ['fr-FR', frFR],
|
||||||
['pt-PT', ptPT]
|
// ['pt-PT', ptPT]
|
||||||
])
|
])
|
||||||
|
|
||||||
export const getLanguage = async () => {
|
export const getLanguage = async () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user