Skip to content

Commit

Permalink
refactor: Update error message for clarity on defined locales (#252)
Browse files Browse the repository at this point in the history
Co-authored-by: QuiiBz <tom.lienrd@gmail.com>
  • Loading branch information
ichiwa and QuiiBz authored Oct 23, 2023
1 parent 548dff9 commit fc4e60f
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { notFound } from 'next/navigation';
import type { BaseLocale, ImportedLocales } from 'international-types';
import type { Context, ReactNode } from 'react';
import React, { Suspense, use, useMemo } from 'react';
import { flattenLocale } from '../../common/flatten-locale';
import { error } from '../../helpers/log';
import type { LocaleContext } from '../../types';

type I18nProviderProps = Omit<I18nProviderWrapperProps, 'fallback'>;
Expand All @@ -23,7 +25,14 @@ export function createI18nProviderClient<Locale extends BaseLocale>(
let clientLocale: any = localesCache.get(locale);

if (!clientLocale) {
clientLocale = use(locales[locale as keyof typeof locales]()).default;
const newLocale = locales[locale as keyof typeof locales];

if (!newLocale) {
error(`The locale '${locale}' is not supported. Defined locales are: [${Object.keys(locales).join(', ')}].`);
notFound();
}

clientLocale = use(newLocale()).default;
localesCache.set(locale, clientLocale);
}

Expand Down

0 comments on commit fc4e60f

Please sign in to comment.