Intl.LocaleMatcher ponyfill providing comprehensive locale matching algorithms with support for 'lookup' and 'best fit' strategies
94
Build a locale availability checker that determines which user-preferred locales are actually supported by an application.
Your task is to implement a function that takes a list of user-preferred locales and a list of application-supported locales, and returns which of the user's preferred locales are actually available.
The checker should:
['en-US', 'fr-CA', 'de'])['en', 'fr', 'es'])en-US can match en)@generates
/**
* Checks which user-preferred locales are supported by the application
* @param {string[]} userLocales - Array of user-preferred locale identifiers
* @param {string[]} appLocales - Array of application-supported locale identifiers
* @returns {string[]} Array of supported locale identifiers from appLocales that match userLocales
*/
function checkAvailableLocales(userLocales, appLocales) {
// IMPLEMENTATION HERE
}
module.exports = { checkAvailableLocales };['en-US'] and app supports ['en', 'fr'], it returns ['en'] @test['fr-CA', 'en'] and app supports ['en', 'fr', 'de'], it returns ['fr', 'en'] @test['zh-Hans-CN'] and app supports ['zh-Hans', 'en'], it returns ['zh-Hans'] @test['de-AT'] and app supports ['en', 'fr'], it returns [] @testProvides locale matching and resolution capabilities.
@satisfied-by
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