Update next-themes version and refactored filename
The commit includes updating the version of 'next-themes' from 0.2.1 to 0.3.0. Also, it refactors the filename in 'packages/i18n/package.json' from 'I18nProvider.tsx' to 'i18n-provider.tsx' following better naming convention and readability. It consolidates a few other version changes in 'pnpm-lock.yaml' to maintain the package dependencies updated and correct.
This commit is contained in:
41
packages/i18n/src/i18n-provider.tsx
Normal file
41
packages/i18n/src/i18n-provider.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
'use client';
|
||||
|
||||
import type { i18n } from 'i18next';
|
||||
|
||||
let client: i18n;
|
||||
|
||||
type Resolver = (
|
||||
lang: string,
|
||||
namespace: string,
|
||||
) => Promise<Record<string, string>>;
|
||||
|
||||
export function I18nProvider({
|
||||
lang,
|
||||
children,
|
||||
resolver,
|
||||
}: React.PropsWithChildren<{
|
||||
lang: string;
|
||||
resolver: Resolver;
|
||||
}>) {
|
||||
if (!client) {
|
||||
throw withI18nClient(lang, resolver);
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
async function withI18nClient(lang: string, resolver: Resolver) {
|
||||
if (typeof window !== 'undefined') {
|
||||
client = await loadClientI18n(lang, resolver);
|
||||
} else {
|
||||
const { initializeServerI18n } = await import('./i18n.server');
|
||||
|
||||
client = await initializeServerI18n(lang, resolver);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadClientI18n(lang: string | undefined, resolver: Resolver) {
|
||||
const { initializeI18nClient } = await import('./i18n.client');
|
||||
|
||||
return initializeI18nClient(lang, resolver);
|
||||
}
|
||||
Reference in New Issue
Block a user