@phensley/cldr-core
Version:
Core library for @phensley/cldr
35 lines • 1.33 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var autogen_aliases_1 = require("./autogen.aliases");
var buildTerritoryAliasMap = function () {
return autogen_aliases_1.territoryAliasRaw.split('|').reduce(function (o, e) {
var _a = e.split(':'), k = _a[0], v = _a[1];
var regions = v.split(/\s+/g);
o[k] = regions;
return o;
}, {});
};
var TERRITORY_ALIAS_MAP = buildTerritoryAliasMap();
/**
* Helper for the language tag parser to fix overlong region fields that may
* or may not be variants.
*/
exports.replaceRegion = function (region) {
var aliases = TERRITORY_ALIAS_MAP[region];
return aliases === undefined ? undefined : aliases[0];
};
/**
* Substitute territory subtag aliases, if any.
*/
exports.substituteRegionAliases = function (dst) {
var region = dst[2 /* REGION */];
var replacement = region === 2 /* REGION */ ? undefined : TERRITORY_ALIAS_MAP[region];
if (replacement === undefined) {
return;
}
// Hack: for now we just use the first region in the list.
dst[2 /* REGION */] = replacement[0];
// TODO: get the best regions for this language / script combiantion, and if
// one is found in the replacement set, use it. Otherwise use the first in the list.
};
//# sourceMappingURL=util.js.map
;