All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.bower_components.cldrjs.src.item.lookup.js Maven / Gradle / Ivy

There is a newer version: 0.66.0.1
Show newest version
define([
    "../bundle/parent_lookup",
    "../path/normalize",
    "../resource/get",
    "../resource/set",
    "../util/json/merge"
], function (bundleParentLookup, pathNormalize, resourceGet, resourceSet, jsonMerge) {

    var lookup;

    lookup = function (Cldr, locale, path, attributes, childLocale) {
        var normalizedPath, parent, value;

        // 1: Finish recursion
        // 2: Avoid infinite loop
        if (typeof locale === "undefined" /* 1 */ || locale === childLocale /* 2 */) {
            return;
        }

        // Resolve path
        normalizedPath = pathNormalize(path, attributes);

        // Check resolved (cached) data first
        // 1: Due to #16, never use the cached resolved non-leaf nodes. It may not
        //    represent its leafs in its entirety.
        value = resourceGet(Cldr._resolved, normalizedPath);
        if (value && typeof value !== "object" /* 1 */) {
            return value;
        }

        // Check raw data
        value = resourceGet(Cldr._raw, normalizedPath);

        if (!value) {
            // Or, lookup at parent locale
            parent = bundleParentLookup(Cldr, locale);
            value = lookup(Cldr, parent, path, jsonMerge(attributes, {bundle: parent}), locale);
        }

        if (value) {
            // Set resolved (cached)
            resourceSet(Cldr._resolved, normalizedPath, value);
        }

        return value;
    };

    return lookup;

});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy