mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-06 21:35:52 +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,
|
||||
"files.associations": {
|
||||
"*.css": "tailwindcss",
|
||||
".oxlintrc.json": "jsonc"
|
||||
".oxlintrc.json": "jsonc",
|
||||
"*.css": "tailwindcss"
|
||||
},
|
||||
"files.eol": "\n",
|
||||
"i18n-ally.defaultNamespace": "translation",
|
||||
// "i18n-ally.defaultNamespace": "translation",
|
||||
// "i18n-ally.displayLanguage": "zh-cn", // 界面显示语言
|
||||
"i18n-ally.enabledFrameworks": [
|
||||
"react-i18next",
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { getI18n } from '@main/utils/language'
|
||||
import { t } from '@main/utils/language'
|
||||
import type { MenuItemConstructorOptions } from 'electron'
|
||||
import { Menu } from 'electron'
|
||||
|
||||
@ -26,12 +26,10 @@ class ContextMenu {
|
||||
}
|
||||
|
||||
private createInspectMenuItems(w: Electron.WebContents): MenuItemConstructorOptions[] {
|
||||
const i18n = getI18n()
|
||||
const { common } = i18n.translation
|
||||
const template: MenuItemConstructorOptions[] = [
|
||||
{
|
||||
id: 'inspect',
|
||||
label: common.inspect,
|
||||
label: t('common.inspect'),
|
||||
click: () => {
|
||||
w.toggleDevTools()
|
||||
},
|
||||
@ -43,29 +41,27 @@ class ContextMenu {
|
||||
}
|
||||
|
||||
private createEditMenuItems(properties: Electron.ContextMenuParams): MenuItemConstructorOptions[] {
|
||||
const i18n = getI18n()
|
||||
const { common } = i18n.translation
|
||||
const hasText = properties.selectionText.trim().length > 0
|
||||
const can = (type: string) => properties.editFlags[`can${type}`] && hasText
|
||||
|
||||
const template: MenuItemConstructorOptions[] = [
|
||||
{
|
||||
id: 'copy',
|
||||
label: common.copy,
|
||||
label: t('common.copy'),
|
||||
role: 'copy',
|
||||
enabled: can('Copy'),
|
||||
visible: properties.isEditable || hasText
|
||||
},
|
||||
{
|
||||
id: 'paste',
|
||||
label: common.paste,
|
||||
label: t('common.paste'),
|
||||
role: 'paste',
|
||||
enabled: properties.editFlags.canPaste,
|
||||
visible: properties.isEditable
|
||||
},
|
||||
{
|
||||
id: 'cut',
|
||||
label: common.cut,
|
||||
label: t('common.cut'),
|
||||
role: 'cut',
|
||||
enabled: can('Cut'),
|
||||
visible: properties.isEditable
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { preferenceService } from '@data/PreferenceService'
|
||||
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 { app, Menu, nativeImage, nativeTheme, Tray } from 'electron'
|
||||
|
||||
@ -72,23 +72,20 @@ export class TrayService {
|
||||
}
|
||||
|
||||
private updateContextMenu() {
|
||||
const i18n = getI18n()
|
||||
const { tray: trayLocale, selection: selectionLocale } = i18n.translation
|
||||
|
||||
const quickAssistantEnabled = preferenceService.get('feature.quick_assistant.enabled')
|
||||
const selectionAssistantEnabled = preferenceService.get('feature.selection.enabled')
|
||||
|
||||
const template = [
|
||||
{
|
||||
label: trayLocale.show_window,
|
||||
label: t('tray.show_window'),
|
||||
click: () => windowService.showMainWindow()
|
||||
},
|
||||
quickAssistantEnabled && {
|
||||
label: trayLocale.show_mini_window,
|
||||
label: t('tray.show_mini_window'),
|
||||
click: () => windowService.showMiniWindow()
|
||||
},
|
||||
(isWin || isMac) && {
|
||||
label: selectionLocale.name + (selectionAssistantEnabled ? ' - On' : ' - Off'),
|
||||
label: t('selection.name') + (selectionAssistantEnabled ? ' - On' : ' - Off'),
|
||||
click: () => {
|
||||
if (selectionService) {
|
||||
selectionService.toggleEnabled()
|
||||
@ -98,7 +95,7 @@ export class TrayService {
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: trayLocale.quit,
|
||||
label: t('tray.quit'),
|
||||
click: () => this.quit()
|
||||
}
|
||||
].filter(Boolean) as MenuItemConstructorOptions[]
|
||||
|
||||
@ -3,7 +3,7 @@ import { loggerService } from '@logger'
|
||||
import { defaultLanguage } from '@shared/config/constant'
|
||||
import type { LanguageVarious } from '@shared/data/preference/preferenceTypes'
|
||||
import { app } from 'electron'
|
||||
import i18next from 'i18next'
|
||||
import i18n from 'i18next'
|
||||
|
||||
// import deDE from '../../renderer/src/i18n/locales/de-de.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 resources = Object.fromEntries([
|
||||
['en-US', EnUs],
|
||||
['zh-CN', ZhCn],
|
||||
['zh-TW', ZhTw]
|
||||
['en-us', EnUs],
|
||||
['zh-cn', ZhCn],
|
||||
['zh-tw', ZhTw]
|
||||
// ['ja-JP', JaJP],
|
||||
// ['ru-RU', RuRu],
|
||||
// ['de-DE', deDE],
|
||||
@ -47,7 +47,7 @@ export const getI18n = (): Record<string, any> => {
|
||||
return resources[language]
|
||||
}
|
||||
|
||||
const i18n = i18next.init({
|
||||
i18n.init({
|
||||
resources,
|
||||
lng: getAppLanguage(),
|
||||
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 { initReactI18next } from 'react-i18next'
|
||||
|
||||
import deDE from './locales/de-de.json'
|
||||
import elGR from './locales/el-gr.json'
|
||||
// import deDE from './locales/de-de.json'
|
||||
// import elGR from './locales/el-gr.json'
|
||||
import enUS from './locales/en-us.json'
|
||||
import esES from './locales/es-es.json'
|
||||
import frFR from './locales/fr-fr.json'
|
||||
import jaJP from './locales/ja-jp.json'
|
||||
import ptPT from './locales/pt-pt.json'
|
||||
import ruRU from './locales/ru-ru.json'
|
||||
// import esES from './locales/es-es.json'
|
||||
// import frFR from './locales/fr-fr.json'
|
||||
// import jaJP from './locales/ja-jp.json'
|
||||
// import ptPT from './locales/pt-pt.json'
|
||||
// import ruRU from './locales/ru-ru.json'
|
||||
import zhCN from './locales/zh-cn.json'
|
||||
import zhTW from './locales/zh-tw.json'
|
||||
|
||||
@ -19,15 +19,15 @@ const logger = loggerService.withContext('I18N')
|
||||
|
||||
const resources = Object.fromEntries([
|
||||
['en-US', enUS],
|
||||
['ja-JP', jaJP],
|
||||
['ru-RU', ruRU],
|
||||
// ['ja-JP', jaJP],
|
||||
// ['ru-RU', ruRU],
|
||||
['zh-CN', zhCN],
|
||||
['zh-TW', zhTW],
|
||||
['de-DE', deDE],
|
||||
['el-GR', elGR],
|
||||
['es-ES', esES],
|
||||
['fr-FR', frFR],
|
||||
['pt-PT', ptPT]
|
||||
['zh-TW', zhTW]
|
||||
// ['de-DE', deDE],
|
||||
// ['el-GR', elGR],
|
||||
// ['es-ES', esES],
|
||||
// ['fr-FR', frFR],
|
||||
// ['pt-PT', ptPT]
|
||||
])
|
||||
|
||||
export const getLanguage = async () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user