Skip to content

Commit ef5d04f

Browse files
authored
feat: suppot v0.5.0+ locale path (#19)
* chore: update locale path * chore: fix typo * chore: fix in vite * refactor: optimized logic * test: update test
1 parent cb88b3d commit ef5d04f

File tree

5 files changed

+524
-204
lines changed

5 files changed

+524
-204
lines changed

examples/package.json

+14-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
"build": "tsc && vite build"
1111
},
1212
"dependencies": {
13-
"@univerjs/core": "0.4.0-alpha.1",
14-
"@univerjs/design": "0.4.0-alpha.1",
15-
"@univerjs/docs": "0.4.0-alpha.1",
16-
"@univerjs/docs-ui": "0.4.0-alpha.1",
17-
"@univerjs/engine-formula": "0.4.0-alpha.1",
18-
"@univerjs/engine-numfmt": "0.4.0-alpha.1",
19-
"@univerjs/engine-render": "0.4.0-alpha.1",
20-
"@univerjs/sheets": "0.4.0-alpha.1",
21-
"@univerjs/sheets-formula": "0.4.0-alpha.1",
22-
"@univerjs/sheets-numfmt": "0.4.0-alpha.1",
23-
"@univerjs/sheets-ui": "0.4.0-alpha.1",
24-
"@univerjs/sheets-zen-editor": "0.4.0-alpha.1",
25-
"@univerjs/ui": "0.4.0-alpha.1"
13+
"@univerjs/core": "0.5.0-alpha.0",
14+
"@univerjs/design": "0.5.0-alpha.0",
15+
"@univerjs/docs": "0.5.0-alpha.0",
16+
"@univerjs/docs-ui": "0.5.0-alpha.0",
17+
"@univerjs/engine-formula": "0.5.0-alpha.0",
18+
"@univerjs/engine-numfmt": "0.5.0-alpha.0",
19+
"@univerjs/engine-render": "0.5.0-alpha.0",
20+
"@univerjs/sheets": "0.5.0-alpha.0",
21+
"@univerjs/sheets-formula": "0.5.0-alpha.0",
22+
"@univerjs/sheets-formula-ui": "0.5.0-alpha.0",
23+
"@univerjs/sheets-numfmt": "0.5.0-alpha.0",
24+
"@univerjs/sheets-ui": "0.5.0-alpha.0",
25+
"@univerjs/sheets-zen-editor": "0.5.0-alpha.0",
26+
"@univerjs/ui": "0.5.0-alpha.0"
2627
},
2728
"devDependencies": {
2829
"@types/react": "^18.3.11",

examples/src/main.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'
77
import { UniverRenderEnginePlugin } from '@univerjs/engine-render'
88
import { UniverSheetsPlugin } from '@univerjs/sheets'
99
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula'
10+
import { UniverSheetsFormulaUIPlugin } from '@univerjs/sheets-formula-ui'
1011
import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt'
1112
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui'
1213
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor'
@@ -25,20 +26,22 @@ const univer = new Univer({
2526
},
2627
})
2728

28-
univer.registerPlugin(UniverDocsPlugin, {
29-
hasScroll: false,
30-
})
31-
univer.registerPlugin(UniverDocsUIPlugin)
3229
univer.registerPlugin(UniverRenderEnginePlugin)
3330
univer.registerPlugin(UniverUIPlugin, {
3431
container: 'app',
3532
})
33+
univer.registerPlugin(UniverDocsPlugin, {
34+
hasScroll: false,
35+
})
36+
univer.registerPlugin(UniverDocsUIPlugin)
37+
3638
univer.registerPlugin(UniverSheetsPlugin)
3739
univer.registerPlugin(UniverSheetsUIPlugin)
3840

3941
univer.registerPlugin(UniverSheetsNumfmtPlugin)
4042
univer.registerPlugin(UniverFormulaEnginePlugin)
4143
univer.registerPlugin(UniverSheetsFormulaPlugin)
44+
univer.registerPlugin(UniverSheetsFormulaUIPlugin)
4245
univer.registerPlugin(UniverSheetsZenEditorPlugin)
4346

4447
univer.createUnit(UniverInstanceType.UNIVER_SHEET, {})

packages/core/src/__tests__/export-virtual-locales-module.ts.spec.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ describe('export-virtual-locales-module', () => {
88
'node_modules/@univerjs/ui/lib/types/locale/en-US.d.ts': '/* en-US locale */',
99
'node_modules/@univerjs/ui/lib/types/locale/zh-CN.d.ts': '/* zh-CN locale */',
1010
'node_modules/@univerjs/ui/lib/types/locale/ru-RU.d.ts': '/* ru-RU locale */',
11+
'node_modules/@univerjs/design/lib/types/locale/vi-VN.d.ts': '/* vi-VN locale */',
12+
13+
'node_modules/@univerjs/ui/lib/es/locale/en-US.js': '/* en-US locale */',
14+
'node_modules/@univerjs/ui/lib/es/locale/zh-CN.js': '/* zh-CN locale */',
15+
'node_modules/@univerjs/ui/lib/es/locale/ru-RU.js': '/* ru-RU locale */',
16+
'node_modules/@univerjs/ui/lib/locale/ru-RU.json': '/* ru-RU locale */',
17+
'node_modules/@univerjs/design/lib/locale/vi-VN.json': '/* vi-VN locale */',
18+
1119
'node_modules/@univerjs/design/lib/index.css': '/* univerjs design css */',
1220
})
1321
})
@@ -20,9 +28,10 @@ describe('export-virtual-locales-module', () => {
2028
const outputCode = exportVirtualLocalesModule()
2129

2230
expect(outputCode).toMatch(/import { Tools as _Tools } from '@univerjs\/core';/)
23-
expect(outputCode).toMatch(/import [a-zA-Z]{8}enUS from '@univerjs\/ui\/lib\/locale\/en-US';/)
24-
expect(outputCode).toMatch(/import [a-zA-Z]{8}ruRU from '@univerjs\/ui\/lib\/locale\/ru-RU';/)
25-
expect(outputCode).toMatch(/import [a-zA-Z]{8}zhCN from '@univerjs\/ui\/lib\/locale\/zh-CN';/)
31+
expect(outputCode).toMatch(/import [a-zA-Z]{8}enUS from '@univerjs\/ui\/lib\/es\/locale\/en-US.js';/)
32+
expect(outputCode).toMatch(/import [a-zA-Z]{8}ruRU from '@univerjs\/ui\/lib\/es\/locale\/ru-RU.js';/)
33+
expect(outputCode).toMatch(/import [a-zA-Z]{8}zhCN from '@univerjs\/ui\/lib\/es\/locale\/zh-CN.js';/)
34+
expect(outputCode).toMatch(/import [a-zA-Z]{8}viVN from '@univerjs\/design\/lib\/locale\/vi-VN.json';/)
2635

2736
expect(outputCode).toMatch(/export const enUS = _Tools.deepMerge\([a-zA-Z]{8}enUS,\n\);/)
2837
expect(outputCode).toMatch(/export const ruRU = _Tools.deepMerge\([a-zA-Z]{8}ruRU,\n\);/)

packages/core/src/export-virtual-locales-module.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ export function exportVirtualLocalesModule() {
3333

3434
if (fs.existsSync(langPath)) {
3535
const langVar = `${lang.replace('-', '')}`
36-
3736
const key = `${generateRandomString(8)}${langVar}`
38-
importStatement += `import ${key} from '${packageName}/lib/locale/${lang}';\n`
39-
languages[lang].add(key)
37+
const langFiles = [
38+
// if version is greater than 0.5.0, use lib/es/locale
39+
`${packageName}/lib/es/locale/${lang}.js`,
40+
`${packageName}/lib/locale/${lang}.json`,
41+
]
42+
const langFile = langFiles.find(file => fs.existsSync(path.resolve('node_modules', file)))
43+
if (langFile) {
44+
importStatement += `import ${key} from '${langFile}';\n`
45+
languages[lang].add(key)
46+
}
4047
}
4148
})
4249
}

0 commit comments

Comments
 (0)