What is @formatjs/intl-localematcher?
The @formatjs/intl-localematcher package is designed to help with locale matching based on the Best Fit Matcher algorithm as specified by the ECMAScript Internationalization API. It allows developers to determine the best available locale for their application based on a list of desired locales and a list of supported locales. This can be particularly useful in internationalization (i18n) efforts where applications need to gracefully handle multiple languages and regional differences.
Locale Matching
This feature allows you to match a list of desired locales against a list of supported locales to find the best match. It uses the Best Fit Matcher algorithm to determine the most appropriate locale for the user.
"use strict";
const {getCanonicalLocales, match} = require('@formatjs/intl-localematcher');
const supportedLocales = ['en-US', 'fr-FR', 'es-ES'];
const desiredLocales = ['en-GB', 'en'];
const bestMatch = match(desiredLocales, supportedLocales);
console.log(bestMatch); // 'en-US'