mirror of
https://github.com/vector-im/element-web.git
synced 2025-11-29 14:31:22 +01:00
Add the file
This commit is contained in:
parent
0adc803684
commit
ad539e4cab
22
packages/shared-components/src/utils/i18nContext.ts
Normal file
22
packages/shared-components/src/utils/i18nContext.ts
Normal file
@ -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<I18nApi | null>(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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user