Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Calendar): change locale from method to string #6276

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/calendar/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useConfig } from '../config-provider'
import isoWeek from 'dayjs/plugin/isoWeek'
import { useUpdateEffect } from 'ahooks'
import { usePropsValue } from '../../utils/use-props-value'
import { replaceMessage } from '../../utils/replace-message'
import {
convertValueToRange,
convertPageToDayjs,
Expand Down Expand Up @@ -171,10 +172,10 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
{props.prevMonthButton}
</a>
<div className={`${classPrefix}-title`}>
{locale.Calendar.renderYearAndMonth(
current.year(),
current.month() + 1
)}
{replaceMessage(locale.Calendar.yearAndMonth, {
year: current.year().toString(),
month: (current.month() + 1).toString(),
})}
</div>
<a
className={classNames(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8618,7 +8618,7 @@ exports[`ConfigProvider should display the text as ja-JP 1`] = `
<div
class="adm-calendar-title"
>
2022年3月
2022年3月
</div>
<a
class="adm-calendar-arrow-button adm-calendar-arrow-button-right adm-calendar-arrow-button-right-month"
Expand Down
2 changes: 1 addition & 1 deletion src/locales/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const base = {
},
Calendar: {
markItems: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
renderYearAndMonth: (year: number, month: number) => `${year}/${month}`,
yearAndMonth: '${year}/${month}',
},
Cascader: {
placeholder: 'Selecting',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/da-DK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const daDK = mergeLocale(base, {
},
Calendar: {
markItems: ['ma', 'ti', 'on', 'to', 'fr', 'lø', 'sø'],
renderYearAndMonth: (year: number, month: number) => `${month}.${year}`,
yearAndMonth: '${month}.${year}',
},
Cascader: {
placeholder: 'Vælger',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/es-ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const esES = mergeLocale(base, {
},
Calendar: {
markItems: ['Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab', 'Dom'],
renderYearAndMonth: (year: number, month: number) => `${year}/${month}`,
yearAndMonth: '${year}/${month}',
},
Cascader: {
placeholder: 'Seleccionando',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/fa-IR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const faIR = mergeLocale(base, {
'پنج‌نشبه',
'جمعه',
],
renderYearAndMonth: (year: number, month: number) => `${year}/${month}`,
yearAndMonth: '${year}/${month}',
},
Cascader: {
placeholder: 'انتخاب کنید',
Expand Down
3 changes: 1 addition & 2 deletions src/locales/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const frFR = mergeLocale(base, {
},
Calendar: {
markItems: ['un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept'],
renderYearAndMonth: (year: number, month: number) =>
`${year}Année ${month}Mois`,
yearAndMonth: '${year}Année ${month}Mois',
},
Cascader: {
placeholder: 'Veuillez sélectionner',
Expand Down
3 changes: 1 addition & 2 deletions src/locales/id-ID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const idID = mergeLocale(base, {
},
Calendar: {
markItems: ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu'],
renderYearAndMonth: (year: number, month: number) =>
`${year} Tahun ${month} Bulan`,
yearAndMonth: '${year} Tahun ${month} Bulan',
},
Cascader: {
placeholder: 'Silahkan Pilih',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/it-IT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const itIT = mergeLocale(base, {
},
Calendar: {
markItems: ['lun', 'mar', 'mer', 'gio', 'ven', 'sab', 'dom'],
renderYearAndMonth: (year: number, month: number) => `${month}/${year}`,
yearAndMonth: '${month}/${year}',
},
Cascader: {
placeholder: 'Si prega di selezionare',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/ja-JP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const jaJP = mergeLocale(base, {
},
Calendar: {
markItems: ['月', '火', '水', '木', '金', '土', '日'],
renderYearAndMonth: (year: number, month: number) => ` ${year}年${month}月`,
yearAndMonth: '${year}年${month}月',
},
Cascader: {
placeholder: '選択下さい',
Expand Down
3 changes: 1 addition & 2 deletions src/locales/kk-KZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const kkKZ = mergeLocale(base, {
},
Calendar: {
markItems: ['Дү', 'Се', 'Сә', 'Бе', 'Жұ', 'Се', 'Же'],
renderYearAndMonth: (year: number, month: number) =>
`${year}жыл${month}-ші ай`,
yearAndMonth: '${year}жыл${month}-ші ай',
},
Cascader: {
placeholder: 'Таңдаңыз',
Expand Down
3 changes: 1 addition & 2 deletions src/locales/ko-KR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const koKR = mergeLocale(base, {
},
Calendar: {
markItems: ['월', '화', '수', '목', '금', '토', '일'],
renderYearAndMonth: (year: number, month: number) => `${year}년 ${month}월`,
yearAndMonth: '${year}년 ${month}월',
},
Cascader: {
placeholder: '선택됨',
Expand Down Expand Up @@ -132,7 +132,6 @@ const koKR = mergeLocale(base, {
Switch: {
name: '스위치',
},

})

export default koKR
2 changes: 1 addition & 1 deletion src/locales/nb-NO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const nbNO = mergeLocale(base, {
},
Calendar: {
markItems: ['Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør', 'Søn'],
renderYearAndMonth: (year: number, month: number) => `${month}.${year}`,
yearAndMonth: '${month}.${year}',
},
Cascader: {
placeholder: 'Velg',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/nl-NL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const nlNL = mergeLocale(base, {
},
Calendar: {
markItems: ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'],
renderYearAndMonth: (year: number, month: number) => `${month}-${year}`,
yearAndMonth: '${month}-${year}',
},
Cascader: {
placeholder: 'Selecteren',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ruRU = mergeLocale(base, {
},
Calendar: {
markItems: ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'],
renderYearAndMonth: (year: number, month: number) => `${year}/${month}`,
yearAndMonth: '${year}/${month}',
},
Cascader: {
placeholder: 'Выбор',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const zhCN = mergeLocale(base, {
},
Calendar: {
markItems: ['一', '二', '三', '四', '五', '六', '日'],
renderYearAndMonth: (year: number, month: number) => `${year}年${month}月`,
yearAndMonth: '${year}年${month}月',
},
Cascader: {
placeholder: '请选择',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/zh-HK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const zhHK = mergeLocale(base, {
},
Calendar: {
markItems: ['一', '二', '三', '四', '五', '六', '日'],
renderYearAndMonth: (year: number, month: number) => `${year}年${month}月`,
yearAndMonth: '${year}年${month}月',
},
Cascader: {
placeholder: '請選擇',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const zhTW = mergeLocale(base, {
},
Calendar: {
markItems: ['一', '二', '三', '四', '五', '六', '日'],
renderYearAndMonth: (year: number, month: number) => `${year}年${month}月`,
yearAndMonth: '${year}年${month}月',
},
Cascader: {
placeholder: '請選擇',
Expand Down
10 changes: 10 additions & 0 deletions src/utils/replace-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 移植自 field-form https://github.com/react-component/field-form/blob/master/src/utils/validateUtil.ts#L21
export function replaceMessage(
template: string,
kv: Record<string, string>
): string {
return template.replace(/\$\{\w+\}/g, (str: string) => {
const key = str.slice(2, -1)
return kv[key]
})
}
Loading