Skip to content

Commit fe16255

Browse files
committed
feat(i18n): add support for Chinese JSON schema in Monaco setup
- Updated configuration to include a Chinese JSON schema URL. - Modified MonacoSetupFeature to dynamically select the schema based on the current language. - Enhanced ConfigEditorWidget to pass the current language to the setup function.
1 parent e1a4020 commit fe16255

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,5 @@ build.info.json
141141

142142
public/wasm_exec.js
143143
public/xray.schema.json
144-
public/main.wasm
144+
public/main.wasm
145+
public/xray.schema.cn.json

src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const app = {
88
configEditor: {
99
wasmUrl: '/main.wasm',
1010
wasmJsUrl: '/wasm_exec.js',
11-
jsonSchemaUrl: '/xray.schema.json'
11+
jsonSchemaUrl: '/xray.schema.json',
12+
jsonSchemaCnUrl: '/xray.schema.cn.json'
1213
}
1314
}

src/features/dashboard/config-profiles/monaco-setup/monaco-setup.feature.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ import axios from 'axios'
55
import { app } from 'src/config'
66

77
export const MonacoSetupFeature = {
8-
setup: async (monaco: Monaco) => {
8+
setup: async (monaco: Monaco, currentLanguage: string) => {
99
try {
10-
const response = await axios.get(app.configEditor.jsonSchemaUrl)
10+
let { jsonSchemaUrl } = app.configEditor
11+
switch (currentLanguage) {
12+
case 'zh':
13+
jsonSchemaUrl = app.configEditor.jsonSchemaCnUrl
14+
break
15+
default:
16+
jsonSchemaUrl = app.configEditor.jsonSchemaUrl
17+
}
18+
19+
const response = await axios.get(jsonSchemaUrl)
20+
1121
const schema = await response.data
1222

1323
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({

src/widgets/dashboard/config-profiles/config-editor/config-editor.widget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import styles from './ConfigEditor.module.css'
1212
import { IProps } from './interfaces'
1313

1414
export function ConfigEditorWidget(props: IProps) {
15-
const { t } = useTranslation()
15+
const { t, i18n } = useTranslation()
1616

1717
const { configProfile } = props
1818
const [result, setResult] = useState('')
@@ -23,8 +23,8 @@ export function ConfigEditorWidget(props: IProps) {
2323

2424
useEffect(() => {
2525
if (!monacoRef.current) return
26-
MonacoSetupFeature.setup(monacoRef.current as Monaco)
27-
}, [monacoRef.current])
26+
MonacoSetupFeature.setup(monacoRef.current as Monaco, i18n.language)
27+
}, [monacoRef.current, i18n.language])
2828

2929
const handleEditorDidMount = (monaco: Monaco) => {
3030
monaco.editor.defineTheme('GithubDark', {

0 commit comments

Comments
 (0)