76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
<<<<<<< HEAD
|
|
define([
|
|
"../core/likely_subtags",
|
|
"../core/remove_likely_subtags",
|
|
"../core/subtags",
|
|
], function( coreLikelySubtags, coreRemoveLikelySubtags, coreSubtags ) {
|
|
=======
|
|
import coreLikelySubtags from "../core/likely_subtags";
|
|
import coreRemoveLikelySubtags from "../core/remove_likely_subtags";
|
|
import coreSubtags from "../core/subtags";
|
|
import arrayForEach from "../util/array/for_each";
|
|
>>>>>>> a11141a... Bundle: Enhcance bundleMapQueue logic (amend)
|
|
|
|
/**
|
|
* bundleLookup( minLanguageId )
|
|
*
|
|
* @Cldr [Cldr class]
|
|
*
|
|
* @cldr [Cldr instance]
|
|
*
|
|
* @minLanguageId [String] requested languageId after applied remove likely subtags.
|
|
*/
|
|
return function( Cldr, cldr, minLanguageId ) {
|
|
var availableBundleMap = Cldr._availableBundleMap,
|
|
availableBundleMapQueue = Cldr._availableBundleMapQueue;
|
|
|
|
<<<<<<< HEAD
|
|
if (availableBundleMapQueue.length) {
|
|
while (availableBundleMapQueue.length > 0) {
|
|
const bundle = availableBundleMapQueue.shift();
|
|
if (!bundle) {
|
|
break;
|
|
}
|
|
|
|
var existing, maxBundle, minBundle, subtags;
|
|
subtags = coreSubtags(bundle);
|
|
maxBundle = coreLikelySubtags(Cldr, cldr, subtags);
|
|
if (typeof maxBundle === "undefined") {
|
|
throw new Error(`Could not find likelySubtags for ${bundle}`);
|
|
}
|
|
|
|
minBundle = coreRemoveLikelySubtags(Cldr, cldr, maxBundle);
|
|
minBundle = minBundle.join(Cldr.localeSep);
|
|
existing = availableBundleMap[minBundle];
|
|
if (existing && existing.length < bundle.length) {
|
|
return;
|
|
}
|
|
availableBundleMap[minBundle] = bundle;
|
|
}
|
|
}
|
|
=======
|
|
if (availableBundleMapQueue.length) {
|
|
arrayForEach(availableBundleMapQueue, function(bundle, i) {
|
|
var existing, maxBundle, minBundle, subtags;
|
|
subtags = coreSubtags(bundle);
|
|
maxBundle = coreLikelySubtags(Cldr, cldr, subtags);
|
|
if (maxBundle === undefined) {
|
|
availableBundleMapQueue.splice(i, 1);
|
|
throw new Error(`Could not find likelySubtags for ${bundle}`);
|
|
}
|
|
minBundle = coreRemoveLikelySubtags(Cldr, cldr, maxBundle);
|
|
minBundle = minBundle.join(Cldr.localeSep);
|
|
existing = availableBundleMap[minBundle];
|
|
if (existing && existing.length < bundle.length) {
|
|
return;
|
|
}
|
|
availableBundleMap[minBundle] = bundle;
|
|
});
|
|
Cldr._availableBundleMapQueue = [];
|
|
}
|
|
>>>>>>> a11141a... Bundle: Enhcance bundleMapQueue logic (amend)
|
|
|
|
return availableBundleMap[ minLanguageId ] || null;
|
|
};
|
|
|
|
});
|