Files
myeasycms-v2/packages/i18n/src/i18n-provider.tsx
giancarlo c92e65b1ec 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.
2024-03-28 22:28:09 +08:00

42 lines
882 B
TypeScript

'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);
}