Skip to content

Commit

Permalink
fix: correct imports
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsdaniels committed Sep 26, 2023
1 parent 2953b14 commit bea4425
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 45 deletions.
8 changes: 6 additions & 2 deletions packages/react-dictionary/components/DictionaryProvider.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
40 changes: 39 additions & 1 deletion packages/react-dictionary/contexts/dictionaryContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
import { createContext } from "react";
import { DictionaryKey, Locale } from "@codedazur/react-dictionary";

export type Dictionaries = ReadonlyMap<Locale | null, Dictionary>;
export type Dictionary = ReadonlyMap<DictionaryKey, string>;

/**
* 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;
Expand Down
3 changes: 1 addition & 2 deletions packages/react-dictionary/hooks/useDictionary.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dictionary/hooks/useTranslation.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/react-dictionary/index.ts
Original file line number Diff line number Diff line change
@@ -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";
17 changes: 0 additions & 17 deletions packages/react-dictionary/types/DictionaryKey.ts

This file was deleted.

20 changes: 0 additions & 20 deletions packages/react-dictionary/types/Locale.ts

This file was deleted.

0 comments on commit bea4425

Please sign in to comment.