Skip to content
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
7 changes: 5 additions & 2 deletions packages/eagle/src/core/ConfigProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -63,16 +64,18 @@ export const ConfigProvider: React.FC<React.PropsWithChildren<ConfigProps>> = ({
}, [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 (
<ConfigProviderContext.Provider value={config}>
Expand Down
34 changes: 34 additions & 0 deletions packages/eagle/src/hooks/__tests__/useAntdPatchJaLocales.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
24 changes: 24 additions & 0 deletions packages/eagle/src/hooks/useAntdPatchJaLocales.ts
Original file line number Diff line number Diff line change
@@ -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 = <T,>(jaLocale: T): T =>
merge({}, jaLocale, PatchJaDatePickerLocale);

export const useAntdPatchJaLocales = <T,>(jaLocale: T) => {
return useMemo(() => patchJaDatePickerLocale(jaLocale), [jaLocale]);
};
Loading