Skip to content

Commit

Permalink
feat(v2): remove I18nProvider (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz authored Mar 3, 2024
1 parent 1c69c87 commit 78ff1ae
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 33 deletions.
6 changes: 2 additions & 4 deletions examples/app/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { I18nProvider, generateI18nStaticParams } from '@/locales';
import { generateI18nStaticParams } from '@/locales';
import React from 'react';

export const dynamicParams = false;
Expand All @@ -15,9 +15,7 @@ export default function RootLayout({
}>) {
return (
<html lang={locale}>
<body>
<I18nProvider locale={locale}>{children}</I18nProvider>
</body>
<body>{children}</body>
</html>
);
}
4 changes: 0 additions & 4 deletions packages/next-international/src/app/app/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
UseLocale,
UseScopedI18n,
} from './types';
import { createI18nProvider } from './provider';
import { SEGMENT_NAME } from './constants';
import { useParams, useRouter } from 'next/navigation';

Expand Down Expand Up @@ -43,8 +42,6 @@ export function createI18n<Locales extends LocalesObject, Locale extends LocaleT
};
};

const I18nProvider = createI18nProvider<Locale>();

const generateI18nStaticParams: GenerateI18nStaticParams = () => {
return Object.keys(locales).map(locale => ({ [config.segmentName ?? SEGMENT_NAME]: locale }));
};
Expand All @@ -68,7 +65,6 @@ export function createI18n<Locales extends LocalesObject, Locale extends LocaleT
return {
useI18n,
useScopedI18n,
I18nProvider,
generateI18nStaticParams,
useLocale,
useChangeLocale,
Expand Down
12 changes: 0 additions & 12 deletions packages/next-international/src/app/app/provider.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions packages/next-international/src/app/app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
UseLocale,
UseScopedI18n,
} from './types';
import { createI18nProvider } from './provider';
import { SEGMENT_NAME } from './constants';
// @ts-expect-error - no types
import { cache } from 'react';
Expand Down Expand Up @@ -60,8 +59,6 @@ export function createI18n<Locales extends LocalesObject, Locale extends LocaleT
};
};

const I18nProvider = createI18nProvider<Locale>();

const generateI18nStaticParams: GenerateI18nStaticParams = () => {
return Object.keys(locales).map(locale => ({ [config.segmentName ?? SEGMENT_NAME]: locale }));
};
Expand All @@ -79,7 +76,6 @@ export function createI18n<Locales extends LocalesObject, Locale extends LocaleT
return {
useI18n,
useScopedI18n,
I18nProvider,
generateI18nStaticParams,
useLocale,
useChangeLocale,
Expand Down
9 changes: 0 additions & 9 deletions packages/next-international/src/app/app/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Keys, LocaleType, LocalesObject, Params, Scopes } from 'international-types';
import type { ReactNode } from 'react';

export type UseI18n<Locale extends LocaleType> = () => <Key extends Keys<Locale>>(
key: Key,
Expand All @@ -10,13 +9,6 @@ export type UseScopedI18n<Locale extends LocaleType> = <Scope extends Scopes<Loc
scope: Scope,
) => <Key extends Keys<Locale, Scope>>(key: Key, ...params: Params<Locale, Scope, Key>) => string;

export type I18nProviderProps<Locale extends LocaleType> = {
locale: string;
children: ReactNode;
};

export type I18nProvider<Locale extends LocaleType> = (props: I18nProviderProps<Locale>) => ReactNode;

export type GenerateI18nStaticParams = () => Array<Record<string, string>>;

export type UseLocale<Locales extends LocalesObject> = () => keyof Locales;
Expand All @@ -26,7 +18,6 @@ export type UseChangeLocale<Locales extends LocalesObject> = () => (locale: keyo
export type CreateI18n<Locales extends LocalesObject, Locale extends LocaleType> = {
useI18n: UseI18n<Locale>;
useScopedI18n: UseScopedI18n<Locale>;
I18nProvider: I18nProvider<Locale>;
generateI18nStaticParams: GenerateI18nStaticParams;
useLocale: UseLocale<Locales>;
useChangeLocale: UseChangeLocale<Locales>;
Expand Down

0 comments on commit 78ff1ae

Please sign in to comment.