QuiiBz / next-international

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

feat(next-international): improve middleware API #115

Closed QuiiBz closed 1 year ago

QuiiBz commented 1 year ago

Improved Middleware API

⚠️ BREAKING

Improve the middleware API for the App Router by using a single object argument and removing the need for as const for the locales:

Before:

const I18nMiddleware = createI18nMiddleware(['en', 'fr'] as const, 'fr')

// With all options:
const I18nMiddleware = createI18nMiddleware(['en', 'fr'] as const, 'fr', {
  urlMappingStrategy: 'rewrite',
  resolveLocaleFromRequest: request => {
    // Do your logic here to resolve the locale
    return 'fr'
  }
})

After:

const I18nMiddleware = createI18nMiddleware({
  locales: ['en', 'fr'],
  defaultLocale: 'en'
})

// With all options:
const I18nMiddleware = createI18nMiddleware({
  locales: ['en', 'fr'],
  defaultLocale: 'en',
  urlMappingStrategy: 'rewrite',
  resolveLocaleFromRequest: request => {
    // Do your logic here to resolve the locale
    return 'fr'
  }
})