Skip to content

Commit

Permalink
feat:update univer version & add TW and VN i18n support (#83)
Browse files Browse the repository at this point in the history
* feat:update the version of univer

* feat:add TW & VN into univer

* chore: cleanup pr

---------

Co-authored-by: karl <255775675@qq.com>
Co-authored-by: 白熱 <sonne@asaki.me>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent b5602b4 commit 44c1348
Show file tree
Hide file tree
Showing 15 changed files with 800 additions and 744 deletions.
71 changes: 41 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,48 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@univerjs/core": "^0.2.3",
"@univerjs/data-validation": "^0.2.3",
"@univerjs/design": "^0.2.3",
"@univerjs/docs": "^0.2.3",
"@univerjs/docs-drawing-ui": "^0.2.3",
"@univerjs/docs-hyper-link-ui": "^0.2.3",
"@univerjs/docs-thread-comment-ui": "^0.2.3",
"@univerjs/docs-ui": "^0.2.3",
"@univerjs/engine-formula": "^0.2.3",
"@univerjs/engine-render": "^0.2.3",
"@univerjs/facade": "^0.2.3",
"@univerjs/find-replace": "^0.2.3",
"@univerjs/core": "^0.2.7",
"@univerjs/data-validation": "^0.2.7",
"@univerjs/design": "^0.2.7",
"@univerjs/docs": "^0.2.7",
"@univerjs/docs-drawing": "^0.2.7",
"@univerjs/docs-drawing-ui": "^0.2.7",
"@univerjs/docs-hyper-link": "^0.2.7",
"@univerjs/docs-hyper-link-ui": "^0.2.7",
"@univerjs/docs-thread-comment-ui": "^0.2.7",
"@univerjs/docs-ui": "^0.2.7",
"@univerjs/drawing": "^0.2.7",
"@univerjs/drawing-ui": "^0.2.7",
"@univerjs/engine-formula": "^0.2.7",
"@univerjs/engine-numfmt": "^0.2.7",
"@univerjs/engine-render": "^0.2.7",
"@univerjs/facade": "^0.2.7",
"@univerjs/find-replace": "^0.2.7",
"@univerjs/icons": "^0.1.57",
"@univerjs/network": "^0.2.7",
"@univerjs/protocol": "^0.1.37",
"@univerjs/rpc": "^0.2.3",
"@univerjs/sheets": "^0.2.3",
"@univerjs/sheets-conditional-formatting-ui": "^0.2.3",
"@univerjs/sheets-data-validation": "^0.2.3",
"@univerjs/sheets-drawing-ui": "^0.2.3",
"@univerjs/sheets-filter": "^0.2.3",
"@univerjs/sheets-find-replace": "^0.2.3",
"@univerjs/sheets-formula": "^0.2.3",
"@univerjs/sheets-hyper-link-ui": "^0.2.3",
"@univerjs/sheets-numfmt": "^0.2.3",
"@univerjs/sheets-sort-ui": "^0.2.3",
"@univerjs/sheets-thread-comment": "^0.2.3",
"@univerjs/sheets-ui": "^0.2.3",
"@univerjs/sheets-zen-editor": "^0.2.3",
"@univerjs/thread-comment-ui": "^0.2.3",
"@univerjs/ui": "^0.2.3",
"@wendellhu/redi": "0.16.0",
"@univerjs/rpc": "^0.2.7",
"@univerjs/sheets": "^0.2.7",
"@univerjs/sheets-conditional-formatting": "^0.2.7",
"@univerjs/sheets-conditional-formatting-ui": "^0.2.7",
"@univerjs/sheets-data-validation": "^0.2.7",
"@univerjs/sheets-drawing": "^0.2.7",
"@univerjs/sheets-drawing-ui": "^0.2.7",
"@univerjs/sheets-filter": "^0.2.7",
"@univerjs/sheets-find-replace": "^0.2.7",
"@univerjs/sheets-formula": "^0.2.7",
"@univerjs/sheets-hyper-link": "^0.2.7",
"@univerjs/sheets-hyper-link-ui": "^0.2.7",
"@univerjs/sheets-numfmt": "^0.2.7",
"@univerjs/sheets-sort": "^0.2.7",
"@univerjs/sheets-sort-ui": "^0.2.7",
"@univerjs/sheets-thread-comment": "^0.2.7",
"@univerjs/sheets-thread-comment-base": "^0.2.7",
"@univerjs/sheets-ui": "^0.2.7",
"@univerjs/sheets-zen-editor": "^0.2.7",
"@univerjs/thread-comment": "^0.2.7",
"@univerjs/thread-comment-ui": "^0.2.7",
"@univerjs/ui": "^0.2.7",
"defu": "^6.1.4",
"jszip": "^3.10.1",
"rxjs": "^7.8.1",
Expand All @@ -65,7 +76,7 @@
"@antfu/eslint-config": "^2.22.2",
"@release-it/conventional-changelog": "^8.0.1",
"@types/node": "^20.14.5",
"@univerjs/vite-plugin": "^0.4.4",
"@univerjs/vite-plugin": "^0.5.0",
"builtin-modules": "^3.3.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
Expand Down
1,389 changes: 694 additions & 695 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/modals/chooseType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class ChooseTypeModal extends Modal {
}

onClose(): void {
// 清空 contentEl 元素的内容
this.contentEl.empty()
}

Expand All @@ -76,6 +77,22 @@ export class ChooseTypeModal extends Modal {
excelBtn: 'Excel',
}
}
else if (this.settings.language === 'TW') {
return {
title: '請選擇要建立的文件類型',
docBtn: 'Univer 文檔',
sheetBtn: 'Univer 表格',
excelBtn: 'Excel',
}
}
else if (this.settings.language === 'VN') {
return {
title: 'Vui lòng chọn loại tệp bạn muốn tạo',
docBtn: 'Univer Tài liệu',
sheetBtn: 'Univer Bảng',
excelBtn: 'Excel',
}
}
else {
return {
title: 'Please choose the type of file you want to create',
Expand Down
4 changes: 3 additions & 1 deletion src/modals/settingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export class SettingTab extends PluginSettingTab {
EN: 'English',
ZH: '简体中文',
RU: 'Русский',
VN: 'Tiếng Việt',
TW: '繁體中文',
})
.setValue(this.plugin.settings.language)
.onChange(async (value: 'ZH' | 'EN' | 'RU') => {
.onChange(async (value: 'ZH' | 'EN' | 'RU' | 'TW' | 'VN') => {
this.plugin.settings.language = value
await this.plugin.saveSettings()
})
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/ExchangePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import type { Dependency } from '@univerjs/core'
import {
Inject,
Injector,
LocaleService,
Plugin,
UniverInstanceType,
} from '@univerjs/core'

import type { Dependency } from '@wendellhu/redi'
import { Inject, Injector } from '@wendellhu/redi'
import { ExchangeController } from './controllers/exchange.controller'
import { ExchangeService, IExchangeService } from './services/exchange.service'
import { enUS, ruRU, zhCN } from './locale/index'
import { enUS, ruRU, viVN, zhCN, zhTW } from './locale/index'

export class ExchangePlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_SHEET
Expand All @@ -25,6 +26,8 @@ export class ExchangePlugin extends Plugin {
zhCN,
enUS,
ruRU,
viVN,
zhTW,
})

const dependencies: Dependency[] = [
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/commands/exchange.operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
* limitations under the License.
*/

import type { ICommand } from '@univerjs/core'
import type { IAccessor, ICommand } from '@univerjs/core'
import { CommandType } from '@univerjs/core'
import type { IAccessor } from '@wendellhu/redi'
import { getUploadXlsxFile } from '@/utils/file'
import { IExchangeService } from '@/plugins/services/exchange.service'

export const ExchangeClientUploadJsonOperation: ICommand = {
id: 'exchange-client.operation.upload-json',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor) => {
const exchangeService = accessor.get(IExchangeService)
const exchangeService = accessor.get(IExchangeService) as any

const file = await getUploadXlsxFile()

Expand All @@ -40,7 +39,8 @@ export const ExchangeClientDownloadJsonOperation: ICommand = {
id: 'exchange-client.operation.download-json',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor) => {
const exchangeService = accessor.get(IExchangeService)
const exchangeService = accessor.get(IExchangeService) as any

exchangeService.downloadJson()
return true
},
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/controllers/exchange.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core'
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core'
import type { IMenuItemFactory } from '@univerjs/ui'
import { IMenuService } from '@univerjs/ui'
import { Inject, Injector } from '@wendellhu/redi'
import { ExchangeClientDownloadJsonOperation, ExchangeClientUploadJsonOperation } from '../commands/exchange.operation'
import { ExchangeDownloadJsonMenuItemFactory, ExchangeMenuItemFactory, ExchangeUploadJsonMenuItemFactory } from './menu'

Expand Down Expand Up @@ -32,7 +31,7 @@ export class ExchangeController extends Disposable {
ExchangeUploadJsonMenuItemFactory,
ExchangeDownloadJsonMenuItemFactory,
] as IMenuItemFactory[]).forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)))
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), {}))
})
}
}
2 changes: 1 addition & 1 deletion src/plugins/controllers/menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui'
import { MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui'
import type { IAccessor } from '@wendellhu/redi'
import type { IAccessor } from '@univerjs/core'
import { ExchangeClientDownloadJsonOperation, ExchangeClientUploadJsonOperation } from '@/plugins/commands/exchange.operation'

const EXCHANGE_OPERATION_ID = 'exchange-client.operation.exchange'
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/locale/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { default as zhTW } from './zh-TW'
export { default as enUS } from './en-US'
export { default as zhCN } from './zh-CN'
export { default as ruRU } from './ru-RU'
export { default as viVN } from './vi-VN'
9 changes: 9 additions & 0 deletions src/plugins/locale/vi-VN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
exchange: {
uploadJson: 'Mở (Tệp)',
downloadJson: 'Lưu dưới dạng',
uploadError: 'Mở thất bại',
uploading: 'Đang tải lên, vui lòng đợi...',
file: 'Tệp',
},
}
9 changes: 9 additions & 0 deletions src/plugins/locale/zh-TW.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
exchange: {
uploadJson: '打開(文件)',
downloadJson: '保存到本地',
uploadError: '打開失敗',
uploading: '正在上傳,請稍後...',
file: '文件',
},
}
8 changes: 3 additions & 5 deletions src/plugins/services/exchange.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable ts/no-redeclare */
import type { Workbook } from '@univerjs/core'
import { IUniverInstanceService, LocaleService, Tools, UniverInstanceType } from '@univerjs/core'
import type { IDisposable, Workbook } from '@univerjs/core'
import { IUniverInstanceService, Inject, LocaleService, Tools, UniverInstanceType, createIdentifier, generateRandomId } from '@univerjs/core'
import { IMessageService } from '@univerjs/ui'
import type { IDisposable } from '@wendellhu/redi'
import { Inject, createIdentifier } from '@wendellhu/redi'
import { MessageType } from '@univerjs/design'
import { fillDefaultSheetBlock, transformSnapshotJsonToWorkbookData, transformWorkbookDataToSnapshotJson } from '@/utils/snapshot'
import { downLoadExcel, readFileHandler, transformToExcelBuffer } from '@/utils/file'
Expand Down Expand Up @@ -42,7 +40,7 @@ export class ExchangeService implements IExchangeService, IDisposable {
return

if (!excel2WorkbookData.id)
excel2WorkbookData.id = Tools.generateRandomId(6)
excel2WorkbookData.id = generateRandomId(6)

const workbookData = fillDefaultSheetBlock(excel2WorkbookData)
const previousSheetBarCount = document.querySelectorAll('.univer-sheet-bar').length
Expand Down
2 changes: 1 addition & 1 deletion src/types/setting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface UniverPluginSettings {
language: 'ZH' | 'EN' | 'RU'
language: 'ZH' | 'EN' | 'RU' | 'VN' | 'TW'
isSupportXlsx: boolean
}
1 change: 1 addition & 0 deletions src/univer/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'
import { UniverDocsThreadCommentUIPlugin } from '@univerjs/docs-thread-comment-ui'
import { UniverDocsHyperLinkUIPlugin } from '@univerjs/docs-hyper-link-ui'
import type { IUniverUIConfig } from '@univerjs/ui/lib/types/controllers/ui/ui.controller'
// import { UniverDocsDrawingUIPlugin } from '@univerjs/docs-drawing-ui'
import { getLanguage, univerLocales } from '@/utils/common'
import type { UniverPluginSettings } from '@/types/setting'

Expand Down
8 changes: 7 additions & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { LocaleType } from '@univerjs/core'
import { enUS, ruRU, zhCN } from 'univer:locales'
import { enUS, ruRU, viVN, zhCN, zhTW } from 'univer:locales'
import type { UniverPluginSettings } from '@/types/setting'

export const univerLocales = {
[LocaleType.EN_US]: enUS,
[LocaleType.ZH_CN]: zhCN,
[LocaleType.RU_RU]: ruRU,
[LocaleType.ZH_TW]: zhTW,
[LocaleType.VI_VN]: viVN,
}

export const univerIconSvg = `
Expand Down Expand Up @@ -34,6 +36,10 @@ export function getLanguage(setting: UniverPluginSettings) {
return LocaleType.ZH_CN
case 'RU':
return LocaleType.RU_RU
case 'VN':
return LocaleType.VI_VN
case 'TW':
return LocaleType.ZH_TW
default:
return LocaleType.EN_US
}
Expand Down

0 comments on commit 44c1348

Please sign in to comment.