From ad539e4cabbc93f02b32307be1f8694809cc3b76 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 27 Nov 2025 11:22:52 +0000 Subject: [PATCH] Add the file --- .../src/utils/i18nContext.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 packages/shared-components/src/utils/i18nContext.ts diff --git a/packages/shared-components/src/utils/i18nContext.ts b/packages/shared-components/src/utils/i18nContext.ts new file mode 100644 index 0000000000..7be4693b25 --- /dev/null +++ b/packages/shared-components/src/utils/i18nContext.ts @@ -0,0 +1,22 @@ +/* +Copyright 2025 Element Creations Ltd. + +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial +Please see LICENSE files in the repository root for full details. +*/ + +import { createContext, useContext } from "react"; +import { type I18nApi } from "@element-hq/element-web-module-api"; + +export const I18nContext = createContext(null); +I18nContext.displayName = "I18nContext"; + +export function useI18n(): I18nApi { + const i18n = useContext(I18nContext); + + if (!i18n) { + throw new Error("useI18n must be used within an I18nContext.Provider"); + } + + return i18n; +}