Intl.LocaleMatcher ponyfill providing comprehensive locale matching algorithms with support for 'lookup' and 'best fit' strategies
94
Build a high-performance locale matching system that can efficiently match user-requested locales against a large set of available locales (500+ locales). The system must handle exact matches, fallback scenarios, and cross-locale matching while maintaining sub-5ms performance.
Your implementation should:
zh-TW should match zh-Hant-TW)['en-US'] and available locales ['en-US', 'fr-FR', 'de-DE'], it returns 'en-US' @test['zh-TW'] and available locales ['zh-Hant-TW', 'zh-Hans-CN', 'en-US'], it returns 'zh-Hant-TW' @test['fr-CA', 'en-GB'] and available locales ['en-US', 'fr-FR', 'de-DE'], it returns 'fr-FR' with preference to the first requested locale @test@generates
/**
* Matches the best available locale based on user preferences.
*
* @param {string[]} requestedLocales - Array of user-requested locales in order of preference
* @param {string[]} availableLocales - Array of locales available in the application
* @param {Object} [options] - Optional configuration
* @param {string} [options.defaultLocale='en'] - Default locale to return if no match found
* @returns {string} The best matching locale from availableLocales
*/
function matchLocale(requestedLocales, availableLocales, options) {
// IMPLEMENTATION HERE
}
module.exports = {
matchLocale
};Provides sophisticated locale resolution and matching algorithms with three-tier optimization for high-performance matching.
Install with Tessl CLI
npx tessl i tessl/npm-formatjs--intl-localematcherdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10