next-international icon indicating copy to clipboard operation
next-international copied to clipboard

Fallback Locale with App Router

Open zfm-lucaschultz opened this issue 1 year ago • 3 comments

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.

zfm-lucaschultz avatar Feb 20 '24 14:02 zfm-lucaschultz

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

QuiiBz avatar Feb 20 '24 16:02 QuiiBz

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

zfm-lucaschultz avatar Feb 20 '24 16:02 zfm-lucaschultz

+1 for a better documentation.

madfcat avatar Nov 18 '24 15:11 madfcat