Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Update error message for clarity on defined locales #252

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert the deletion of empty lines? It makes it harder to read the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, it seems the formatter ran automatically. I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by 860e13c

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