Skip to content

Commit

Permalink
Merge pull request #1 from dream-num/fix/fix-variable-name
Browse files Browse the repository at this point in the history
fix: fix variable name
  • Loading branch information
jikkai authored Feb 26, 2024
2 parents 1997984 + d86e4a2 commit b0b8320
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ describe('export-virtual-locales-module', () => {
const outputCode = exportVirtualLocalesModule()

const expectedStatement = new RegExp(
`import { en-US as [a-zA-Z]{10}-US } from '@univerjs/ui';\n`
+ `import { zh-CN as [a-zA-Z]{10}-CN } from '@univerjs/ui';\n`
+ `export const en-US = {...[a-zA-Z]{10}-US,\n`
`import { en_US as [a-zA-Z]{10}_US } from '@univerjs/ui';\n`
+ `import { zh_CN as [a-zA-Z]{10}_CN } from '@univerjs/ui';\n`
+ `export const en_US = {...[a-zA-Z]{10}_US,\n`
+ `};\n`
+ `export const zh-CN = {...[a-zA-Z]{10}-CN,\n`
+ `export const zh_CN = {...[a-zA-Z]{10}_CN,\n`
+ `};`,
)

Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/export-virtual-locales-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export function exportVirtualLocalesModule() {
const langPath = path.resolve('node_modules', packageName, 'lib/types/locale', `${lang}.d.ts`)

if (fs.existsSync(langPath)) {
const key = `${generateRandomString(8)}${lang}`
importStatement += `import { ${lang} as ${key} } from '${packageName}';\n`
const langVar = `${lang.replace('-', '_')}`
const key = `${generateRandomString(8)}${langVar}`
importStatement += `import { ${langVar} as ${key} } from '${packageName}';\n`
languages[lang].add(key)
}
})
Expand All @@ -42,8 +43,10 @@ export function exportVirtualLocalesModule() {
}

Object.keys(languages).forEach((lang) => {
const langVar = `${lang.replace('-', '_')}`

if (languages[lang].size > 0) {
exportStatement += `export const ${lang} = {`
exportStatement += `export const ${langVar} = {`

languages[lang].forEach((key) => {
exportStatement += `...${key},\n`
Expand Down

0 comments on commit b0b8320

Please sign in to comment.