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

META-INF.resources.bower_components.globalize.src.message.formatter-runtime-bind.js Maven / Gradle / Ivy

There is a newer version: 1.2.2.1-jre17
Show newest version
define(function () {

    return function (cldr, messageformatter) {
        var locale = cldr.locale,
            origToString = messageformatter.toString;

        messageformatter.toString = function () {
            var argNames, argValues, output,
                args = {};

            // Properly adjust SlexAxton/messageformat.js compiled variables with Globalize variables:
            output = origToString.call(messageformatter);

            if (/number\(/.test(output)) {
                args.number = "messageFormat.number";
            }

            if (/plural\(/.test(output)) {
                args.plural = "messageFormat.plural";
            }

            if (/select\(/.test(output)) {
                args.select = "messageFormat.select";
            }

            output.replace(/pluralFuncs(\[([^\]]+)\]|\.([a-zA-Z]+))/, function (match) {
                args.pluralFuncs = "{" +
                    "\"" + locale + "\": Globalize(\"" + locale + "\").pluralGenerator()" +
                    "}";
                return match;
            });

            argNames = Object.keys(args).join(", ");
            argValues = Object.keys(args).map(function (key) {
                return args[key];
            }).join(", ");

            return "(function( " + argNames + " ) {\n" +
                "  return " + output + "\n" +
                "})(" + argValues + ")";
        };

        return messageformatter;
    };

});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy