CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-formatjs--intl-localematcher

Intl.LocaleMatcher ponyfill providing comprehensive locale matching algorithms with support for 'lookup' and 'best fit' strategies

94

1.09x
Overview
Eval results
Files

task.mdevals/scenario-1/

Locale Availability Checker

Build a locale availability checker that determines which user-preferred locales are actually supported by an application.

Requirements

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:

  • Accept an array of user-preferred locale strings (e.g., ['en-US', 'fr-CA', 'de'])
  • Accept an array of application-supported locale strings (e.g., ['en', 'fr', 'es'])
  • Return an array of supported locale strings that match the user's preferences
  • Support progressive fallback matching (e.g., en-US can match en)
  • Handle locale canonicalization automatically
  • Strip Unicode extensions before matching

Implementation

@generates

API

/**
 * 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 };

Test Cases

  • When user requests ['en-US'] and app supports ['en', 'fr'], it returns ['en'] @test
  • When user requests ['fr-CA', 'en'] and app supports ['en', 'fr', 'de'], it returns ['fr', 'en'] @test
  • When user requests ['zh-Hans-CN'] and app supports ['zh-Hans', 'en'], it returns ['zh-Hans'] @test
  • When user requests ['de-AT'] and app supports ['en', 'fr'], it returns [] @test

Dependencies { .dependencies }

@formatjs/intl-localematcher { .dependency }

Provides locale matching and resolution capabilities.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-formatjs--intl-localematcher

tile.json