QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.28k stars 59 forks source link

Fallback Locale with App Router #364

Open zfm-lucaschultz opened 7 months ago

zfm-lucaschultz commented 7 months ago

Is your feature request related to a problem? Please describe. I would like to add a fallback locale when using the I18nProviderClient with the app router. The documentation only mentions a fallbackLocale prop for the I18nProvider with the page router. While there is a fallbackLocale config option for createI18nClient and createI18nServer, I'm either using it incorrectly or it doesn't work.

'use client';

import { createI18nClient } from 'next-international/client';

export const {
  useI18n,
  useScopedI18n,
  I18nProviderClient,
  useCurrentLocale,
  useChangeLocale,
} = createI18nClient(
  {
    de: () => import('./locales/de'),
    en: () => import('./locales/en'),
  },
  {
    fallbackLocale: {
      en: 'de',
    },
  },
);

Either way, it might be good to add documentation for this.

Describe the solution you'd like Add a fallback locale when using the app router and/or add documentation for it.

Describe alternatives you've considered I had a look at the code, but it wasn't immediately clear how to use the fallback locale.

Additional context None.

QuiiBz commented 7 months ago

Indeed the documentation is missing this option, but we'll update and improve it with #359

Looking at your example code, it looks incorrect. You have to pass a locale object, see the example: https://github.com/QuiiBz/next-international/blob/a049386f43bf2c42a2b3ed9b8d3e82b42ff9eebe/examples/next-app/locales/server.ts#L13

zfm-lucaschultz commented 7 months ago

@QuiiBzI figured out how to use the fallback correctly, but thank you for the quick clarification. 👍 Still, adding documentation for this would be nice.