Skip to content

How to fallback to generic locale if country-specific is not available? #1371

Closed Answered by amannn
empz asked this question in Q&A
Discussion options

You must be logged in to vote

next-intl reads the accept-language header and uses that to negotiate a matching locale. Did you check the value of the header in your case?

Based on your outcome, I'd assume that en is also in your list (even if secondary).

next-intl uses @formatjs/intl-localematcher under the hood for this matching.

Example:

import {match} from '@formatjs/intl-localematcher';

const requestedLocales = ['es-AR', 'en'];
const availableLocales = ['es', 'en'];
const defaultLocale = 'en';

// 'en', since 'en' is a supported language (even if ordered after 'es')
match(requestedLocales, availableLocales, defaultLocale)

However:

const requestedLocales = ['es-AR', 'de']; // Note that `en` is no longer requested
c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@empz
Comment options

Answer selected by empz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants