Skip to content

Commit

Permalink
feat(ui/locale): export zh-CN en-US language
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq authored and BeADre committed Sep 18, 2022
1 parent a2d621a commit e4eecf0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/varlet-ui/src/locale/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ The `Locale` component is introduced to realize multi-language switching, and `L
```js
// playground-ignore
import { Locale } from '@varlet/ui'
import enUS from '@varlet/ui/es/locale/en-US'

Locale.add('en-US', enUS)
Locale.add('en-US', Locale.enUS)
```

Use `Locale.use` to switch languages.
Expand Down
3 changes: 1 addition & 2 deletions packages/varlet-ui/src/locale/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
```js
// playground-ignore
import { Locale } from '@varlet/ui'
import enUS from '@varlet/ui/es/locale/en-US'

Locale.add('en-US', enUS)
Locale.add('en-US', Locale.enUS)
```

使用 `Locale.use` 进行切换语言
Expand Down
7 changes: 5 additions & 2 deletions packages/varlet-ui/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ref } from 'vue'
import type { Ref } from 'vue'
import type { Month, Week } from '../date-picker/props'
import zhCN from './zh-CN'
import enUS from './en-US'

export type Pack = {
// Dialog
Expand Down Expand Up @@ -73,11 +74,13 @@ const { packs, pack, add, use, merge } = useLocale()
add('zh-CN', zhCN)
use('zh-CN')

export { packs, pack, add, use, merge, useLocale }
export { zhCN, enUS, packs, pack, add, use, merge, useLocale }

export const _LocaleComponent = { packs, pack, add, use, merge, useLocale }
export const _LocaleComponent = { zhCN, enUS, packs, pack, add, use, merge, useLocale }

export default {
zhCN,
enUS,
packs,
pack,
add,
Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare module 'vue' {
VarLoading: typeof import('@varlet/ui')['_LoadingComponent']
VarLocale: typeof import('@varlet/ui')['_LocaleComponent']
VarMenu: typeof import('@varlet/ui')['_MenuComponent']
VarMenuV2: typeof import('@varlet/ui')['_MenuV2Component']
VarOption: typeof import('@varlet/ui')['_OptionComponent']
VarPagination: typeof import('@varlet/ui')['_PaginationComponent']
VarPicker: typeof import('@varlet/ui')['_PickerComponent']
Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export * from './list'
export * from './loading'
export * from './locale'
export * from './menu'
export * from './menuV2'
export * from './option'
export * from './pagination'
export * from './picker'
Expand Down
3 changes: 3 additions & 0 deletions packages/varlet-ui/types/locale.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ export type Pack = {
}

interface Locale {
zhCN: Pack
enUS: Pack
packs: Record<string, Partial<Pack>>
pack: Ref<Partial<Pack>>
add(lang: string, pack: Partial<Pack>): void
use(lang: string): void
merge(lang: string, pack: Partial<Pack>): void

useLocale<T = Pack>(): {
packs: Record<string, Partial<T>>
pack: Ref<Partial<T>>
Expand Down

0 comments on commit e4eecf0

Please sign in to comment.