diff --git a/packages/eagle/src/core/ConfigProvider/index.tsx b/packages/eagle/src/core/ConfigProvider/index.tsx index 7cfecd0da..ae5662eb0 100644 --- a/packages/eagle/src/core/ConfigProvider/index.tsx +++ b/packages/eagle/src/core/ConfigProvider/index.tsx @@ -5,6 +5,7 @@ import "moment/locale/zh-cn"; import { ParrotLngs } from "@cloudtower/parrot"; import { useAntdPatchEnLocales } from "@src/hooks/useAntdPatchEnLocales"; +import { useAntdPatchJaLocales } from "@src/hooks/useAntdPatchJaLocales"; import useParrotTranslation from "@src/hooks/useParrotTranslation"; import { ConfigProvider as Antd4ConfigProvider } from "antd"; import { ConfigProviderProps } from "antd/lib/config-provider"; @@ -63,16 +64,18 @@ export const ConfigProvider: React.FC> = ({ }, [i18n]); const patchEnLocale = useAntdPatchEnLocales(enUS); + const patchAntd4JaLocale = useAntdPatchJaLocales(jaJP); + const patchAntd5JaLocale = useAntdPatchJaLocales(antd5jaJP); const lng = i18n.language as ParrotLngs; const antd5Locales = { [ParrotLngs.zh]: antd5zhCN, [ParrotLngs.en]: antd5enUS, - [ParrotLngs.ja]: antd5jaJP, + [ParrotLngs.ja]: patchAntd5JaLocale, }; const antd4Locales = { [ParrotLngs.zh]: zhCN, [ParrotLngs.en]: patchEnLocale, - [ParrotLngs.ja]: jaJP, + [ParrotLngs.ja]: patchAntd4JaLocale, }; return ( diff --git a/packages/eagle/src/hooks/__tests__/useAntdPatchJaLocales.test.ts b/packages/eagle/src/hooks/__tests__/useAntdPatchJaLocales.test.ts new file mode 100644 index 000000000..31f2c8a16 --- /dev/null +++ b/packages/eagle/src/hooks/__tests__/useAntdPatchJaLocales.test.ts @@ -0,0 +1,34 @@ +import antd4JaJP from "antd/lib/locale/ja_JP"; +import antd5JaJP from "antd5/lib/locale/ja_JP"; +import { describe, expect, it } from "vitest"; + +import { patchJaDatePickerLocale } from "../useAntdPatchJaLocales"; + +type PatchedLocale = { + DatePicker?: { lang: { rangePlaceholder?: string[]; ok?: string } }; + Calendar?: { lang: { ok?: string } }; +}; + +describe("patchJaDatePickerLocale", () => { + it("updates Japanese date range picker copy for antd4", () => { + const locale = patchJaDatePickerLocale(antd4JaJP) as PatchedLocale; + + expect(locale.DatePicker?.lang.rangePlaceholder).toEqual([ + "開始時刻", + "終了時刻", + ]); + expect(locale.DatePicker?.lang.ok).toBe("OK"); + expect(locale.Calendar?.lang.ok).toBe("OK"); + }); + + it("updates Japanese date range picker copy for antd5", () => { + const locale = patchJaDatePickerLocale(antd5JaJP) as PatchedLocale; + + expect(locale.DatePicker?.lang.rangePlaceholder).toEqual([ + "開始時刻", + "終了時刻", + ]); + expect(locale.DatePicker?.lang.ok).toBe("OK"); + expect(locale.Calendar?.lang.ok).toBe("OK"); + }); +}); diff --git a/packages/eagle/src/hooks/useAntdPatchJaLocales.ts b/packages/eagle/src/hooks/useAntdPatchJaLocales.ts new file mode 100644 index 000000000..af7a6b3ae --- /dev/null +++ b/packages/eagle/src/hooks/useAntdPatchJaLocales.ts @@ -0,0 +1,24 @@ +import merge from "lodash/merge"; +import { useMemo } from "react"; + +const PatchJaDatePickerLocale = { + DatePicker: { + lang: { + rangePlaceholder: ["開始時刻", "終了時刻"], + ok: "OK", + }, + }, + Calendar: { + lang: { + rangePlaceholder: ["開始時刻", "終了時刻"], + ok: "OK", + }, + }, +}; + +export const patchJaDatePickerLocale = (jaLocale: T): T => + merge({}, jaLocale, PatchJaDatePickerLocale); + +export const useAntdPatchJaLocales = (jaLocale: T) => { + return useMemo(() => patchJaDatePickerLocale(jaLocale), [jaLocale]); +};