In the current API there's a set of methods that are related to language tag operations and language negotiation. They're all hidden within Intl API and not accessible from the outside.
I believe it's worth discussing an option of not only making them public, but also moving them out of an Intl object because although they are used by Intl, they are not Intl specific and are useful for other APIs as well. Three APIs that I see specifically are:
*) L10n libraries
*) Keyboards/Dictionaries/Speech-data packs etc.
*) Vanilla language selectors (for when the l10n happens on the server side)
I suggest separating them out in form of a new Locale object that will, initially have the following methods:
1) IsStructurallyValidLanguageTag(string)
Tests if the string is a valid language tag
2) CanonicalizeLocaleList(array)
Creates a valid normalized list of language tags out of an array of strings
3) SupportedLocales(availableLocales, requestedLocales, options)
Returns the subset of requestedLocales for which availableLocales has a matching locale.
4) PrioritizeAvailableLocales(availableLocales, requestedLocales, [defaultLocale], options)
Returns the subset of availableLocales, that match any of the locales in requestedLocales ordered by the requestedLocales list.
If defaultLocale is provided and is not present in the requestedLocales, it is added at the end of the list.
The last method is basically what l10n needs for language negotiation. It has a set of resources for a number of locales (example: ['fr', 'de', 'it', 'en-US'])
and it has to negotiate it against languages requested by the user (example: ['pl', 'de', 'fr']).
The result of that operation should be a list of available locales in prioritized by requestedLocales (example: ['de', 'fr']). This is the fallback chain that will be used by the localization library to load
its resources. defaultLocale may serve as a last resort in case no locales overlap between available and requested or for another reason loading resources in all other languages fails.
Thoughts?
zb.
Ecma issue: https://github.com/tc39/ecma402/issues/5