Skip to content

Commit

Permalink
feat: support fa-IR
Browse files Browse the repository at this point in the history
  • Loading branch information
jikkai committed Oct 15, 2024
1 parent 8ecbb75 commit 4487c66
Show file tree
Hide file tree
Showing 23 changed files with 3,324 additions and 2,882 deletions.
3 changes: 1 addition & 2 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ runs:
using: composite
steps:
- name: Setup pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8
run_install: false

- name: Setup Node.js
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ jobs:
ref: ${{ github.ref_name }}

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false

- name: Install Node.js
Expand Down
3 changes: 1 addition & 2 deletions examples/esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { univerPlugin } from '@univerjs/esbuild-plugin'
import esbuild from 'esbuild'
import stylePlugin from 'esbuild-style-plugin'
import { univerPlugin } from '@univerjs/esbuild-plugin'

const ctx = await esbuild.context({
bundle: true,
Expand All @@ -20,5 +20,4 @@ await ctx.serve({
port: 3010,
})

// eslint-disable-next-line no-console
console.log(`Local server: http://localhost:3010`)
36 changes: 18 additions & 18 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@
"build": "tsc && vite build"
},
"dependencies": {
"@univerjs/core": "0.1.15",
"@univerjs/design": "0.1.15",
"@univerjs/docs": "0.1.15",
"@univerjs/docs-ui": "0.1.15",
"@univerjs/engine-formula": "0.1.15",
"@univerjs/engine-numfmt": "0.1.15",
"@univerjs/engine-render": "0.1.15",
"@univerjs/sheets": "0.1.15",
"@univerjs/sheets-formula": "0.1.15",
"@univerjs/sheets-numfmt": "0.1.15",
"@univerjs/sheets-ui": "0.1.15",
"@univerjs/sheets-zen-editor": "0.1.15",
"@univerjs/ui": "0.1.15"
"@univerjs/core": "0.4.0-alpha.1",
"@univerjs/design": "0.4.0-alpha.1",
"@univerjs/docs": "0.4.0-alpha.1",
"@univerjs/docs-ui": "0.4.0-alpha.1",
"@univerjs/engine-formula": "0.4.0-alpha.1",
"@univerjs/engine-numfmt": "0.4.0-alpha.1",
"@univerjs/engine-render": "0.4.0-alpha.1",
"@univerjs/sheets": "0.4.0-alpha.1",
"@univerjs/sheets-formula": "0.4.0-alpha.1",
"@univerjs/sheets-numfmt": "0.4.0-alpha.1",
"@univerjs/sheets-ui": "0.4.0-alpha.1",
"@univerjs/sheets-zen-editor": "0.4.0-alpha.1",
"@univerjs/ui": "0.4.0-alpha.1"
},
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"@univerjs/esbuild-plugin": "file:../packages/esbuild-plugin",
"@univerjs/vite-plugin": "file:../packages/vite-plugin",
"@univerjs/webpack-plugin": "file:../packages/webpack-plugin",
"css-loader": "^6.10.0",
"esbuild": "^0.21.5",
"esbuild": "^0.24.0",
"esbuild-style-plugin": "^1.6.3",
"html-webpack-plugin": "^5.6.0",
"style-loader": "^3.3.4",
"ts-loader": "^9.5.1",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"webpack": "^5.92.0",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
"webpack-dev-server": "^5.1.0"
}
}
6 changes: 3 additions & 3 deletions examples/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import './style.css'

import { LocaleType, LogLevel, Univer, UniverInstanceType } from '@univerjs/core'

import { defaultTheme } from '@univerjs/design'
import { UniverDocsPlugin } from '@univerjs/docs'
import { UniverDocsUIPlugin } from '@univerjs/docs-ui'
Expand All @@ -11,11 +10,12 @@ import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula'
import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt'
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui'
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor'

import { UniverUIPlugin } from '@univerjs/ui'

import { enUS } from 'univer:locales'

import './style.css'

const univer = new Univer({
theme: defaultTheme,
locale: LocaleType.EN_US,
Expand Down
2 changes: 1 addition & 1 deletion examples/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vite'
import { univerPlugin } from '@univerjs/vite-plugin'
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion examples/webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('node:path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { UniverPlugin } = require('@univerjs/webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
// You'll need to find a webpack plugin equivalent for univerPlugin or adapt it if it's already compatible.
// const UniverWebpackPlugin = require('@univerjs/webpack-plugin');

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"type": "module",
"version": "0.5.0",
"private": true,
"packageManager": "[email protected]",
"author": "DreamNum Inc. <[email protected]>",
"license": "Apache-2.0",
"engines": {
"node": ">=18.0.0"
"node": ">=18",
"pnpm": ">=9"
},
"scripts": {
"prepare": "simple-git-hooks",
Expand All @@ -17,12 +19,12 @@
"release": "release-it"
},
"devDependencies": {
"@antfu/eslint-config": "^2.21.1",
"@antfu/eslint-config": "^3.7.3",
"@release-it-plugins/workspaces": "^4.2.0",
"@release-it/conventional-changelog": "^8.0.1",
"eslint": "^9.5.0",
"lint-staged": "^15.2.7",
"release-it": "^17.3.0",
"@release-it/conventional-changelog": "^9.0.0",
"eslint": "^9.12.0",
"lint-staged": "^15.2.10",
"release-it": "^17.9.0",
"simple-git-hooks": "^2.11.1"
},
"simple-git-hooks": {
Expand Down
14 changes: 5 additions & 9 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=8.0.0"
},
"scripts": {
"test": "jest"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.14.5",
"@types/jest": "^29.5.13",
"@types/node": "^22.7.5",
"jest": "^29.7.0",
"mock-fs": "^5.2.0",
"ts-jest": "^29.1.5",
"typescript": "^5.4.5"
"mock-fs": "^5.4.0",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/core/src/export-virtual-locales-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const virtualLocalesModuleId = 'univer:locales'
export function exportVirtualLocalesModule() {
const scopes = ['@univerjs', '@univerjs-pro']

const languages = ['en-US', 'ru-RU', 'zh-CN', 'vi-VN', 'zh-TW'].reduce((acc, lang) => {
const languages = ['en-US', 'ru-RU', 'zh-CN', 'vi-VN', 'zh-TW', 'fa-IR'].reduce((acc, lang) => {
acc[lang] = new Set()
return acc
}, {})
Expand Down
61 changes: 61 additions & 0 deletions packages/core/src/export-virtual-presets-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import fs from 'node:fs'
import path from 'node:path'
import { generateRandomString } from './utils'

Check warning on line 3 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

export const virtualLocalesModuleId = 'univer:locales'

Check warning on line 5 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L5

Added line #L5 was not covered by tests

/**
* Generates a virtual module that exports all the locales from `@univerjs` and `@univerjs-pro`.
*
* @returns {string} A string containing the import and export statements for all the locales from `@univerjs` and `@univerjs-pro`.
*/
export function exportVirtualLocalesModule() {
const scopes = ['@univerjs', '@univerjs-pro']

Check warning on line 13 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L12-L13

Added lines #L12 - L13 were not covered by tests

const languages = ['en-US', 'ru-RU', 'zh-CN', 'vi-VN', 'zh-TW', 'fa-IR'].reduce((acc, lang) => {
acc[lang] = new Set()
return acc

Check warning on line 17 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L15-L17

Added lines #L15 - L17 were not covered by tests
}, {})

let importStatement = `import { Tools as _Tools } from '@univerjs/core';\n`
let exportStatement = ''

Check warning on line 21 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L20-L21

Added lines #L20 - L21 were not covered by tests

for (const scope of scopes) {
const scopePath = path.resolve('node_modules', scope)

Check warning on line 24 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L23-L24

Added lines #L23 - L24 were not covered by tests
if (fs.existsSync(scopePath)) {
const packagePaths = fs.readdirSync(scopePath)

Check warning on line 26 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L26

Added line #L26 was not covered by tests

for (const packagePath of packagePaths) {
const packageName = `${scope}/${packagePath}`

Check warning on line 29 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L28-L29

Added lines #L28 - L29 were not covered by tests

Object.keys(languages).forEach((lang) => {
const langPath = path.resolve('node_modules', packageName, 'lib/types/locale', `${lang}.d.ts`)

Check warning on line 32 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L31-L32

Added lines #L31 - L32 were not covered by tests

if (fs.existsSync(langPath)) {
const langVar = `${lang.replace('-', '')}`

Check warning on line 35 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L35

Added line #L35 was not covered by tests

const key = `${generateRandomString(8)}${langVar}`
importStatement += `import ${key} from '${packageName}/lib/locale/${lang}';\n`
languages[lang].add(key)

Check warning on line 39 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L37-L39

Added lines #L37 - L39 were not covered by tests
}
})
}
}
}

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

Check warning on line 47 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L46-L47

Added lines #L46 - L47 were not covered by tests

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

Check warning on line 50 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L50

Added line #L50 was not covered by tests

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

Check warning on line 53 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L52-L53

Added lines #L52 - L53 were not covered by tests
})

exportStatement += `);\n`

Check warning on line 56 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L56

Added line #L56 was not covered by tests
}
})

return importStatement + exportStatement

Check warning on line 60 in packages/core/src/export-virtual-presets-module.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/export-virtual-presets-module.ts#L60

Added line #L60 was not covered by tests
}
5 changes: 3 additions & 2 deletions packages/esbuild-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ npm install @univerjs/esbuild-plugin
If you are using the `esbuild` API, you can add the plugin to your build configuration:

```typescript
import esbuild from 'esbuild'
import { UniverPlugin } from '@univerjs/esbuild-plugin'
import esbuild from 'esbuild'

esbuild.build({
plugins: [
Expand Down Expand Up @@ -44,7 +44,7 @@ The plugin provides a virtual module `univer:locales`, which simplifies the impo
```typescript
import { LocaleType } from '@univerjs/core'

import { enUS, ruRU, viVN, zhCN, zhTW } from 'univer:locales'
import { enUS, faIR, ruRU, viVN, zhCN, zhTW } from 'univer:locales'

new Univer({
locales: {
Expand All @@ -53,6 +53,7 @@ new Univer({
[LocaleType.RU_RU]: ruRU,
[LocaleType.VI_VN]: viVN,
[LocaleType.ZH_TW]: zhTW,
[LocaleType.FA_IR]: faIR,
}
})
```
Expand Down
10 changes: 3 additions & 7 deletions packages/esbuild-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=8.0.0"
},
"scripts": {
"build": "tsc && node ./esbuild.config.js"
},
"devDependencies": {
"@types/node": "^20.14.5",
"@types/node": "^22.7.5",
"@univerjs/plugin-core": "workspace:*",
"esbuild": "^0.21.5",
"typescript": "^5.4.5"
"esbuild": "^0.24.0",
"typescript": "^5.6.3"
}
}
1 change: 1 addition & 0 deletions packages/esbuild-plugin/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ declare module 'univer:locales' {
export const ruRU: { [key: string]: string }
export const viVN: { [key: string]: string }
export const zhTW: { [key: string]: string }
export const faIR: { [key: string]: string }
}
5 changes: 3 additions & 2 deletions packages/vite-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ npm install @univerjs/vite-plugin
Add the plugin to your `vite.config.ts`:

```typescript
import { defineConfig } from 'vite'
import { univerPlugin } from '@univerjs/vite-plugin'
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [
Expand Down Expand Up @@ -44,7 +44,7 @@ The plugin provides a virtual module `univer:locales`, which simplifies the impo
```typescript
import { LocaleType } from '@univerjs/core'

import { enUS, ruRU, viVN, zhCN, zhTW } from 'univer:locales'
import { enUS, faIR, ruRU, viVN, zhCN, zhTW } from 'univer:locales'

new Univer({
locales: {
Expand All @@ -53,6 +53,7 @@ new Univer({
[LocaleType.RU_RU]: ruRU,
[LocaleType.VI_VN]: viVN,
[LocaleType.ZH_TW]: zhTW,
[LocaleType.FA_IR]: faIR,
}
})
```
Expand Down
12 changes: 4 additions & 8 deletions packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=8.0.0"
},
"scripts": {
"build": "tsc && node ./esbuild.config.js"
},
"devDependencies": {
"@types/node": "^20.14.5",
"@types/node": "^22.7.5",
"@univerjs/plugin-core": "workspace:*",
"esbuild": "^0.21.5",
"typescript": "^5.4.5",
"vite": "^5.3.1"
"esbuild": "^0.24.0",
"typescript": "^5.6.3",
"vite": "^5.4.9"
}
}
1 change: 1 addition & 0 deletions packages/vite-plugin/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ declare module 'univer:locales' {
export const ruRU: { [key: string]: string }
export const viVN: { [key: string]: string }
export const zhTW: { [key: string]: string }
export const faIR: { [key: string]: string }
}
3 changes: 2 additions & 1 deletion packages/webpack-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The plugin provides a virtual module `univer:locales`, which simplifies the impo
```typescript
import { LocaleType } from '@univerjs/core'

import { enUS, ruRU, viVN, zhCN, zhTW } from 'univer:locales'
import { enUS, faIR, ruRU, viVN, zhCN, zhTW } from 'univer:locales'

new Univer({
locales: {
Expand All @@ -52,6 +52,7 @@ new Univer({
[LocaleType.RU_RU]: ruRU,
[LocaleType.VI_VN]: viVN,
[LocaleType.ZH_TW]: zhTW,
[LocaleType.FA_IR]: faIR,
}
})
```
Expand Down
Loading

0 comments on commit 4487c66

Please sign in to comment.