From 645933becefa5ad9699e54178214c0a2e76e325a Mon Sep 17 00:00:00 2001 From: Petar Todorovic Date: Tue, 8 Apr 2025 21:43:25 +0200 Subject: [PATCH] feat(widget): add customTranslations prop to extend translations --- .changeset/tender-insects-fix.md | 6 ++++++ packages/widget/src/providers/settings.tsx | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/tender-insects-fix.md diff --git a/.changeset/tender-insects-fix.md b/.changeset/tender-insects-fix.md new file mode 100644 index 00000000..15994ec2 --- /dev/null +++ b/.changeset/tender-insects-fix.md @@ -0,0 +1,6 @@ +--- +"with-vite-bundled": minor +"@stakekit/widget": patch +--- + +add `customTranslations` prop to extend translations diff --git a/packages/widget/src/providers/settings.tsx b/packages/widget/src/providers/settings.tsx index 5b67737d..366c60b7 100644 --- a/packages/widget/src/providers/settings.tsx +++ b/packages/widget/src/providers/settings.tsx @@ -1,4 +1,5 @@ -import type { Languages } from "@sk-widget/translation"; +import type { Languages, localResources } from "@sk-widget/translation"; +import type { RecursivePartial } from "@sk-widget/types"; import type { PropsWithChildren, ReactNode } from "react"; import { createContext, useContext, useLayoutEffect } from "react"; import { useTranslation } from "react-i18next"; @@ -42,6 +43,7 @@ export type SettingsProps = { isSafe?: boolean; disableInjectedProviderDiscovery?: boolean; mapWalletFn?: Parameters[0]["mapWalletFn"]; + customTranslations?: RecursivePartial; }; export type SettingsContextType = SettingsProps & VariantProps; @@ -66,6 +68,14 @@ export const SettingsContextProvider = ({ } }, [rest.language, i18n]); + useLayoutEffect(() => { + if (rest.customTranslations) { + Object.entries(rest.customTranslations).forEach(([lng, val]) => { + i18n.addResourceBundle(lng, "translation", val.translation, true, true); + }); + } + }, [rest.customTranslations, i18n]); + return ( {children} );