diff --git a/packages/react-dictionary/components/DictionaryProvider.tsx b/packages/react-dictionary/components/DictionaryProvider.tsx index 1f7ce958..24c49ea2 100644 --- a/packages/react-dictionary/components/DictionaryProvider.tsx +++ b/packages/react-dictionary/components/DictionaryProvider.tsx @@ -1,6 +1,10 @@ import { FunctionComponent, ReactNode, useMemo } from "react"; -import { Dictionary, dictionaryContext } from "../contexts/dictionaryContext"; -import { DictionaryKey, Locale } from "@codedazur/react-dictionary"; +import { + Dictionary, + DictionaryKey, + Locale, + dictionaryContext, +} from "../contexts/dictionaryContext"; export interface DictionaryProviderProps { locale?: Locale; diff --git a/packages/react-dictionary/contexts/dictionaryContext.ts b/packages/react-dictionary/contexts/dictionaryContext.ts index 14df6f15..f2462cff 100644 --- a/packages/react-dictionary/contexts/dictionaryContext.ts +++ b/packages/react-dictionary/contexts/dictionaryContext.ts @@ -1,9 +1,47 @@ import { createContext } from "react"; -import { DictionaryKey, Locale } from "@codedazur/react-dictionary"; export type Dictionaries = ReadonlyMap; export type Dictionary = ReadonlyMap; +/** + * This type can be overridden using module augmentation. + * + * @example + * // dictionary.d.ts + * + * import "@codedazur/react-dictionary"; + * + * declare module "@codedazur/react-dictionary" { + * export enum DictionaryKey { + * "foo", + * "bar", + * "baz", + * } + * } + */ +export enum DictionaryKey {} + +/** + * This enum can be overridden using module augmentation. + * + * @example + * // dictionary.d.ts + * + * import "@codedazur/react-dictionary"; + * + * declare module "@codedazur/react-dictionary" { + * export enum Locale { + * en_US = "en_US", + * en_GB = "en_GB", + * } + * } + */ +export enum Locale { + en_US = "en_US", +} + +export const DefaultLocale = Locale.en_US; + export interface DictionaryContext { locale: Locale | null; entries: Dictionaries; diff --git a/packages/react-dictionary/hooks/useDictionary.ts b/packages/react-dictionary/hooks/useDictionary.ts index 02a18f45..2b681db2 100644 --- a/packages/react-dictionary/hooks/useDictionary.ts +++ b/packages/react-dictionary/hooks/useDictionary.ts @@ -1,6 +1,5 @@ import { useContext } from "react"; -import { dictionaryContext } from "../contexts/dictionaryContext"; -import { Locale } from "@codedazur/react-dictionary"; +import { Locale, dictionaryContext } from "../contexts/dictionaryContext"; export const useDictionary = (locale?: Locale) => { const { entries, locale: currentLocale } = useContext(dictionaryContext); diff --git a/packages/react-dictionary/hooks/useTranslation.ts b/packages/react-dictionary/hooks/useTranslation.ts index 987d5470..94c476eb 100644 --- a/packages/react-dictionary/hooks/useTranslation.ts +++ b/packages/react-dictionary/hooks/useTranslation.ts @@ -1,4 +1,4 @@ -import { DictionaryKey, Locale } from "@codedazur/react-dictionary"; +import { DictionaryKey, Locale } from "../contexts/dictionaryContext"; import { useDictionary } from "./useDictionary"; export const useTranslation = (key: DictionaryKey, locale?: Locale) => { diff --git a/packages/react-dictionary/index.ts b/packages/react-dictionary/index.ts index 5f7c0f10..4fffcc3c 100644 --- a/packages/react-dictionary/index.ts +++ b/packages/react-dictionary/index.ts @@ -1,5 +1,4 @@ export * from "./components/DictionaryProvider"; export * from "./contexts/dictionaryContext"; export * from "./hooks/useDictionary"; -export * from "./types/DictionaryKey"; -export * from "./types/Locale"; +export * from "./hooks/useTranslation"; diff --git a/packages/react-dictionary/types/DictionaryKey.ts b/packages/react-dictionary/types/DictionaryKey.ts deleted file mode 100644 index 66a626b3..00000000 --- a/packages/react-dictionary/types/DictionaryKey.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * This type can be overridden using module augmentation. - * - * @example - * // dictionary.d.ts - * - * import "@codedazur/react-dictionary"; - * - * declare module "@codedazur/react-dictionary" { - * export enum DictionaryKey { - * "foo", - * "bar", - * "baz", - * } - * } - */ -export enum DictionaryKey {} diff --git a/packages/react-dictionary/types/Locale.ts b/packages/react-dictionary/types/Locale.ts deleted file mode 100644 index aa48975c..00000000 --- a/packages/react-dictionary/types/Locale.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** - * This enum can be overridden using module augmentation. - * - * @example - * // dictionary.d.ts - * - * import "@codedazur/react-dictionary"; - * - * declare module "@codedazur/react-dictionary" { - * export enum Locale { - * en_US = "en_US", - * en_GB = "en_GB", - * } - * } - */ -export enum Locale { - en_US = "en_US", -} - -export const DefaultLocale = Locale.en_US;