Skip to content

Commit

Permalink
[fix] language pack loading bug
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Nov 27, 2023
1 parent 62f0106 commit 6f372d5
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 48 deletions.
10 changes: 5 additions & 5 deletions packages/xgen/components/base/Filter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getLocale, useSearchParams } from '@umijs/max'
import Actions from './components/Actions'
import { useCalcLayout, useVisibleMore } from './hooks'
import styles from './index.less'
import locales from './locales'
import { Message } from './locales'

import type { IPropsFilter, IPropsActions } from './types'

Expand Down Expand Up @@ -41,8 +41,8 @@ const Index = (props: IPropsFilter) => {
if (!Object.keys(search_params).length) return

setFieldsValue(search_params)
}, [ parent, params ])
}, [parent, params])

if (!columns.length && !actions?.length) return null

const onReset = () => {
Expand Down Expand Up @@ -87,15 +87,15 @@ const Index = (props: IPropsFilter) => {
type='primary'
htmlType='submit'
>
{locales[locale].search}
{Message(locale).search}
</Button>
</Col>
<Col>
<Button
className='btn_filter_action flex justify_center align_center'
htmlType='reset'
>
{locales[locale].reset}
{Message(locale).reset}
</Button>
</Col>
</When>
Expand Down
10 changes: 8 additions & 2 deletions packages/xgen/components/base/Filter/locales.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Locale } from './types'
import type { Locale, LocaleFilter } from './types'

export default {
const locale = {
'zh-CN': {
search: '搜索',
reset: '重置'
Expand All @@ -10,3 +10,9 @@ export default {
reset: 'Reset'
}
} as Locale

export default locale

export const Message = (key: any): LocaleFilter => {
return locale[key] || locale['en-US']
}
10 changes: 6 additions & 4 deletions packages/xgen/components/base/Filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export interface IPropsActions {
query: any
}

export interface LocaleFilter {
search: string
reset: string
}

export interface Locale {
[key: string]: {
search: string
reset: string
}
[key: string]: LocaleFilter
}
18 changes: 9 additions & 9 deletions packages/xgen/components/base/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Anchor from './components/Anchor'
import Breadcrumb from './components/Breadcrumb'
import { useHooks, usePageTitle } from './hooks'
import styles from './index.less'
import locales from './locales'
import { Message } from './locales'
import Model from './model'

import type { Component } from '@/types'
Expand All @@ -23,19 +23,19 @@ const Index = (props: Component.FormComponent) => {
const { parent, parentNamespace, model, id, form, onBack } = props
const [x] = useState(() => container.resolve(Model))
const locale = getLocale()
const page_title_prefix = usePageTitle(locales[locale], id!, form!.type)
const page_title_prefix = usePageTitle(Message(locale), id!, form!.type)
const hooks = useHooks(toJS(x.setting.hooks!), toJS(x.setting.fields), toJS(x.data))
const ref_container = useRef<HTMLDivElement>(null)
const [is_fullscreen, { toggleFullscreen }] = useFullscreen(ref_container)

const title = useMemo(() => {
if (x.setting?.config?.viewTitle && x.type === 'view') {
return x.setting.config.viewTitle
}
const title = useMemo(() => {
if (x.setting?.config?.viewTitle && x.type === 'view') {
return x.setting.config.viewTitle
}

if (x.setting?.config?.editTitle && x.type === 'edit') {
return x.setting.config.editTitle
}
if (x.setting?.config?.editTitle && x.type === 'edit') {
return x.setting.config.editTitle
}

return page_title_prefix + x.setting.name
}, [page_title_prefix, x.setting.name, x.type, x.setting?.config?.viewTitle, x.setting?.config?.editTitle])
Expand Down
10 changes: 8 additions & 2 deletions packages/xgen/components/base/Form/locales.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Locale } from './types'
import type { Locale, LocaleForm } from './types'

export default {
const locale = {
'zh-CN': {
page: {
title: {
Expand All @@ -20,3 +20,9 @@ export default {
}
}
} as Locale

export default locale

export const Message = (key: any): LocaleForm => {
return locale[key] || locale['en-US']
}
18 changes: 10 additions & 8 deletions packages/xgen/components/base/Form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ export interface IPropsAnchorItem {
item: FormType.Column
}

export interface Locale {
[key: string]: {
page: {
title: {
add: string
view: string
edit: string
}
export interface LocaleForm {
page: {
title: {
add: string
view: string
edit: string
}
}
}

export interface Locale {
[key: string]: LocaleForm
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { X } from '@/components'
import { Card } from '@/widgets'
import { useIntl } from '@umijs/max'

import locales from '../locales'
import { Message } from '../locales'
import ChartLink from './ChartLink'

import type { IPropsChartItem } from '../types'
Expand All @@ -13,7 +13,7 @@ const Index = (props: IPropsChartItem) => {
const { item, data } = props
const { cardStyle, ...view_props } = item.view.props
const { locale } = useIntl()
const locale_messages = locales[locale]
const locale_messages = Message(locale)

return (
<Col span={item.width}>
Expand Down
10 changes: 8 additions & 2 deletions packages/xgen/components/base/PureChart/locales.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { Locale } from './types'
import type { Locale, LocalePureChart } from './types'

export default {
const locale = {
'zh-CN': {
link_tooltip: '查看更多数据'
},
'en-US': {
link_tooltip: 'Check more data'
}
} as Locale

export default locale

export const Message = (key: any): LocalePureChart => {
return locale[key] || locale['en-US']
}
8 changes: 5 additions & 3 deletions packages/xgen/components/base/PureChart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export interface IPropsChartLink {
link: string
}

export interface LocalePureChart {
link_tooltip: string
}

export interface Locale {
[key: string]: {
link_tooltip: string
}
[key: string]: LocalePureChart
}
4 changes: 2 additions & 2 deletions packages/xgen/components/base/PureTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useLayoutEffect, useMemo } from 'react'
import { getLocale } from '@umijs/max'

import { useColumns } from './hooks'
import locales from './locales'
import { Message } from './locales'

import type { TablePaginationConfig } from 'antd'
import type { IPropsPureTable } from './types'
Expand Down Expand Up @@ -41,7 +41,7 @@ const Index = (props: IPropsPureTable) => {
showSizeChanger: true,
showTotal: useMemoizedFn(
(total: number) =>
locales[locale].pagination.total.before + total + locales[locale].pagination.total.after
Message(locale).pagination.total.before + total + Message(locale).pagination.total.after
)
}

Expand Down
10 changes: 8 additions & 2 deletions packages/xgen/components/base/PureTable/locales.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Locale } from './types'
import type { Locale, LocalePureTable } from './types'

export default {
const locale = {
'zh-CN': {
pagination: {
total: {
Expand All @@ -18,3 +18,9 @@ export default {
}
}
} as Locale

export default locale

export const Message = (key: any): LocalePureTable => {
return locale[key] || locale['en-US']
}
16 changes: 9 additions & 7 deletions packages/xgen/components/base/PureTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ export interface IPropsActions {
data_item: any
}

export interface Locale {
[key: string]: {
pagination: {
total: {
before: string
after: string
}
export interface LocalePureTable {
pagination: {
total: {
before: string
after: string
}
}
}

export interface Locale {
[key: string]: LocalePureTable
}

0 comments on commit 6f372d5

Please sign in to comment.