fix: canonicalize widget date locales
This commit is contained in:
1 parent
2efa6bcd4c
commit
25b835dca9
9 files changed
+39
-11
No files matched your search
@@ -6,7 +6,7 @@ import type { SupportedLanguage } from "../config";
|
||||
import type englishTranslation from "../lang/en.json";
|
||||
|
||||
export { useChangeLocale } from "./use-change-locale";
|
||||
export { useCurrentLocale } from "./use-current-locale";
|
||||
export { useCurrentIntlLocale, useCurrentLocale } from "./use-current-locale";
|
||||
|
||||
declare module "next-intl" {
|
||||
interface AppConfig {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { useLocale } from "next-intl";
|
||||
|
||||
import { getIntlLocale } from "../config";
|
||||
|
||||
export const useCurrentLocale = useLocale;
|
||||
|
||||
export const useCurrentIntlLocale = () => getIntlLocale(useLocale());
|
||||
@@ -0,0 +1,16 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getIntlLocale } from "./config";
|
||||
|
||||
describe("getIntlLocale", () => {
|
||||
it("maps Homarr-specific locale keys to canonical Intl locales", () => {
|
||||
expect(getIntlLocale("cn")).toBe("zh-CN");
|
||||
expect(getIntlLocale("zh")).toBe("zh-TW");
|
||||
expect(getIntlLocale("cr")).toBe("en");
|
||||
});
|
||||
|
||||
it("preserves locale keys that Intl already understands", () => {
|
||||
expect(getIntlLocale("fr")).toBe("fr");
|
||||
expect(getIntlLocale("de-CH")).toBe("de-CH");
|
||||
});
|
||||
});
|
||||
@@ -438,5 +438,13 @@ export type LanguageIconDefinition =
|
||||
|
||||
export { fallbackLocale } from "./languages";
|
||||
|
||||
const intlLocaleOverrides: Partial<Record<SupportedLanguage, string>> = {
|
||||
cn: "zh-CN",
|
||||
cr: "en",
|
||||
zh: "zh-TW",
|
||||
};
|
||||
|
||||
export const getIntlLocale = (locale: SupportedLanguage): string => intlLocaleOverrides[locale] ?? locale;
|
||||
|
||||
export const isLocaleRTL = (locale: SupportedLanguage) =>
|
||||
"isRTL" in localeConfigurations[locale] && localeConfigurations[locale].isRTL;
|
||||
Reference in new issue
Block a user