Skip to content

Commit

Permalink
backend intl
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtarsi committed Apr 28, 2024
1 parent 3a231d5 commit 8687c90
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 88 deletions.
7 changes: 3 additions & 4 deletions packages/selenium-ide/src/browser/I18N/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const testCoreEnglish = {
playFromStart: 'Play From Start',
}

export const langaugeMapEn = {
export const backend = {
windowTab: windowTabEnglish,
electronMenuTree: electronMenuTreeEnglish,
fileMenuTree: fileMenuTreeEnglish,
Expand All @@ -218,7 +218,6 @@ export const langaugeMapEn = {

// Creating a type of this so other locales are prompted to be filled in by
// the developer
export type LanguageMap = typeof langaugeMapEn
export type LanguageMap = typeof backend

const flattenedMap = flattenNestedObject(langaugeMapEn)
export default flattenedMap
export const frontend = flattenNestedObject(backend)
4 changes: 2 additions & 2 deletions packages/selenium-ide/src/browser/I18N/keys.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {langaugeMapEn} from './en'
import {backend} from './en'
import {transformNestedObject} from './util'

/**
* Take this nested object, keep the shape, but make the final keys the dot delimited string
* path of the nested key
*/
const languageMap = transformNestedObject((key) => key, langaugeMapEn)
const languageMap = transformNestedObject((key) => key, backend)

export default languageMap
6 changes: 3 additions & 3 deletions packages/selenium-ide/src/browser/I18N/zh/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LanguageMap } from '../en/index'
import Commands from '@seleniumhq/side-model/dist/I18N/zh/Commands'
import {transformNestedObject} from '../util'
import { transformNestedObject } from '../util'

// 窗口顶部菜单
const windowTabChinese = {
Expand Down Expand Up @@ -202,7 +202,7 @@ const testCoreChinese = {
playFromStart: '从头开始回放',
}

export const languageMapZh: LanguageMap = {
export const backend: LanguageMap = {
windowTab: windowTabChinese,
electronMenuTree: electronMenuTreeChinese,
fileMenuTree: fileMenuTreeChinese,
Expand All @@ -222,4 +222,4 @@ export const languageMapZh: LanguageMap = {
commandMap: Commands,
}

export default transformNestedObject((_k, v) => v, languageMapZh)
export const frontend = transformNestedObject((_k, v) => v, backend)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { LocatorFields } from '@seleniumhq/side-api'
import { useIntl } from 'react-intl'
import languageMap from 'browser/I18N/keys'

const inputLabelProps = {
sx: {
textOverflow: 'ellipsis',
},
}

const CommandTextField: FC<CommandFieldProps> = ({
command,
disabled,
Expand All @@ -33,12 +39,16 @@ const CommandTextField: FC<CommandFieldProps> = ({
return value
}
}
console.log(
languageMap.commandMap[command.command][fieldName as LocatorFields]
?.description,
command
)
// 一定会使用languageMap.commandMap,其实是为了兼容参数commands
const fullNote =
note ||
intl.formatMessage({
id: languageMap.commandMap[command.command][fieldName as LocatorFields]
?.description,
id: `commandMap.${command.command}.${fieldName}.description`,
})
const label = fullNote
? handleLabel(FieldName) + ' - ' + fullNote
Expand All @@ -51,11 +61,7 @@ const CommandTextField: FC<CommandFieldProps> = ({
disabled={disabled}
id={`${fieldName}-${command.id}`}
label={label}
InputLabelProps={{
sx: {
textOverflow: 'ellipsis',
},
}}
InputLabelProps={inputLabelProps}
name={fieldName}
onChange={updateText(testID, command.id)}
onContextMenu={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { context as testsContext } from 'browser/contexts/tests'
import { context as testResultsContext } from 'browser/contexts/playback-test-results'
import { FormattedMessage, useIntl } from 'react-intl'
import languageMap from 'browser/I18N/keys'
import { QuestionAnswer } from '@mui/icons-material'

const {
state: { setActiveTest: setSelected, setActiveSuite },
Expand Down Expand Up @@ -60,7 +61,13 @@ const TestsDrawer: FC = () => {
)
}
}
/>
>
<Tooltip
title={<FormattedMessage id={languageMap.testsTab.tooltip} />}
>
<QuestionAnswer />
</Tooltip>
</EditorToolbar>
<FormControl size="small">
<Select
MenuProps={{
Expand Down Expand Up @@ -96,22 +103,17 @@ const TestsDrawer: FC = () => {
.map(({ id, name }) => {
const testState = testResults[id]?.state
return (
<Tooltip
title={<FormattedMessage id={languageMap.testsTab.tooltip} />}
>
<RenamableListItem
id={id}
key={id}
name={name}
onContextMenu={() => {
window.sideAPI.menus.open('testManager', [id])
}}
rename={rename}
selected={id === activeTestID}
setSelected={setSelected}
state={testState}
/>
</Tooltip>
<RenamableListItem
id={id}
name={name}
onContextMenu={() => {
window.sideAPI.menus.open('testManager', [id])
}}
rename={rename}
selected={id === activeTestID}
setSelected={setSelected}
state={testState}
/>
)
})}
</List>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,54 @@ export const commands: MenuComponent = (session: Session) => () =>
label: 'Selenium IDE',
submenu: [
{
label: session.store.get('languageMap').electronMenuTree.about,
label: session.system.languageMap.electronMenuTree.about,
role: 'about',
},
{ type: 'separator' },
{
label: session.store.get('languageMap').electronMenuTree.services,
label: session.system.languageMap.electronMenuTree.services,
role: 'services',
},
{ type: 'separator' },
{
label: session.store.get('languageMap').electronMenuTree.hideElectron,
label: session.system.languageMap.electronMenuTree.hideElectron,
role: 'hide',
},
{
label: session.store.get('languageMap').electronMenuTree.hideOthers,
label: session.system.languageMap.electronMenuTree.hideOthers,
role: 'hideOthers',
},
{
label: session.store.get('languageMap').electronMenuTree.showAll,
label: session.system.languageMap.electronMenuTree.showAll,
role: 'unhide',
},
{ type: 'separator' },
{
accelerator: platform() === 'win32' ? 'Alt+F4' : 'CommandOrControl+Q',
label: session.store.get('languageMap').electronMenuTree.quit,
label: session.system.languageMap.electronMenuTree.quit,
click: async () => {
await session.system.quit()
},
},
],
},
{
label: session.store.get('languageMap').windowTab.file,
label: session.system.languageMap.windowTab.file,
submenu: projectEditorCommands(session)(),
},
{
label: session.store.get('languageMap').windowTab.edit,
label: session.system.languageMap.windowTab.edit,
submenu: [
...editBasicsCommands(session)(),
...testEditorCommands(session)(),
],
},
{
label: session.store.get('languageMap').windowTab.view,
label: session.system.languageMap.windowTab.view,
submenu: projectViewCommands(session)(),
},
{
label: session.store.get('languageMap').windowTab.help,
label: session.system.languageMap.windowTab.help,
submenu: helpMenuCommands(session)(),
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ export const commands: MenuComponent = (session) => () =>
accelerator: 'CommandOrControl+Z',
click: () => session.api.state.undo(),
enabled: session.state.prevHistory.length !== 0,
label: session.store.get('languageMap').editMenuTree.undo,
label: session.system.languageMap.editMenuTree.undo,
},
{
accelerator: 'CommandOrControl+Shift+Z',
click: () => session.api.state.redo(),
enabled: session.state.nextHistory.length !== 0,
label: session.store.get('languageMap').editMenuTree.redo,
label: session.system.languageMap.editMenuTree.redo,
},
{ type: 'separator' },
{ label: session.store.get('languageMap').editMenuTree.cut, role: 'cut' },
{ label: session.store.get('languageMap').editMenuTree.copy, role: 'copy' },
{ label: session.system.languageMap.editMenuTree.cut, role: 'cut' },
{ label: session.system.languageMap.editMenuTree.copy, role: 'copy' },
{
label: session.store.get('languageMap').editMenuTree.paste,
label: session.system.languageMap.editMenuTree.paste,
role: 'paste',
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const commands: MenuComponent = (session) => () =>
click: async () => {
await session.system.dumpSession()
},
label: session.store.get('languageMap').helpMenuTree.dumpSession,
label: session.system.languageMap.helpMenuTree.dumpSession,
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export const commands: MenuComponent = (session) => () =>
[
{
accelerator: 'CommandOrControl+N',
label: session.store.get('languageMap').fileMenuTree.newProject,
label: session.system.languageMap.fileMenuTree.newProject,
click: async () => {
await session.api.projects.new()
},
},
{ type: 'separator' },
{
accelerator: 'CommandOrControl+O',
label: session.store.get('languageMap').fileMenuTree.loadProject,
label: session.system.languageMap.fileMenuTree.loadProject,
click: async () => {
const response = await session.dialogs.open()
if (response.canceled) return
Expand All @@ -22,7 +22,7 @@ export const commands: MenuComponent = (session) => () =>
},
{
accelerator: 'CommandOrControl+R',
label: session.store.get('languageMap').fileMenuTree.recentProjects,
label: session.system.languageMap.fileMenuTree.recentProjects,
click: async () => {
await session.projects.showRecents()
},
Expand All @@ -36,15 +36,15 @@ export const commands: MenuComponent = (session) => () =>
{ type: 'separator' },
{
accelerator: 'CommandOrControl+S',
label: session.store.get('languageMap').fileMenuTree.saveProject,
label: session.system.languageMap.fileMenuTree.saveProject,
click: async () => {
await session.projects.save(session.projects.filepath as string)
},
enabled: Boolean(session.projects.filepath),
},
{
accelerator: 'CommandOrControl+Shift+S',
label: session.store.get('languageMap').fileMenuTree.saveProjectAs,
label: session.system.languageMap.fileMenuTree.saveProjectAs,
click: async () => {
const response = await session.dialogs.openSave()
if (response.canceled) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ export const commands: MenuComponent = (session) => () =>
const window = BrowserWindow.getFocusedWindow()
window?.webContents.openDevTools()
},
label: session.store.get('languageMap').viewMenuTree.showDevTools,
label: session.system.languageMap.viewMenuTree.showDevTools,
}
),
{
accelerator: 'CommandOrControl+P',
click: async () => {
await session.windows.initializePlaybackWindow()
},
label: session.store.get('languageMap').viewMenuTree.resetPlaybackWindows,
label: session.system.languageMap.viewMenuTree.resetPlaybackWindows,
},
{
accelerator: 'CommandOrControl+R',
label: session.store.get('languageMap').viewMenuTree.refreshPlaybackWindow,
label: session.system.languageMap.viewMenuTree.refreshPlaybackWindow,
click: async () => {
const window = await session.windows.getActivePlaybackWindow()
if (window) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { menuFactoryFromCommandFactory } from '../utils'

export const commands: MenuComponent<[string[]]> = (session) => (suiteIDs) => {
const outputFormats = session.outputFormats.getFormats()
const languageMap = session.store.get('languageMap')
const languageMap = session.system.languageMap
return [
{
accelerator: 'CommandOrControl+Shift+Delete',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const commandList: MenuComponent = (session) => () => {
const editorState = sessionData.state.editor
const copiedCommandCount = editorState.copiedCommands.length
const selectedCommandCount = editorState.selectedCommandIndexes.length
const languageMap = session.store.get('languageMap')
const languageMap = session.system.languageMap
return [
{
accelerator: 'CommandOrControl+Shift+X',
Expand Down Expand Up @@ -130,7 +130,7 @@ export const commandList: MenuComponent = (session) => () => {
export const recorderList = (session: Session) => () => {
const selectedCommandCount =
session.state.state.editor.selectedCommandIndexes.length
const languageMap = session.store.get('languageMap')
const languageMap = session.system.languageMap
return [
{
accelerator: 'CommandOrControl+R',
Expand All @@ -147,7 +147,7 @@ export const playbackList: MenuComponent =
(session) => (_commandID?: string) => {
const selectedCommandCount =
session.state.state.editor.selectedCommandIndexes.length
const languageMap = session.store.get('languageMap')
const languageMap = session.system.languageMap
return [
{
click: async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { menuFactoryFromCommandFactory } from '../utils'

export const commands: MenuComponent<[string[]]> = (session) => (testIDs) => {
const outputFormats = session.outputFormats.getFormats()
const languageMap = session.store.get('languageMap')
const languageMap = session.system.languageMap
return [
{
accelerator: 'CommandOrControl+Shift+Delete',
Expand Down
Loading

0 comments on commit 8687c90

Please sign in to comment.