New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-precomputed compound units throw in languages without "one" unit properties #849

Closed
willsp opened this Issue Dec 16, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@willsp
Copy link
Contributor

willsp commented Dec 16, 2018

When using non-precomputed compound units, in languages without a "one" property on their units, globalize throws. The following example illustrates this behavior:

Cldr.load( jaUnits );
Cldr.load( likelySubtags );

globalize = new Globalize( "ja" );
cldr = globalize.cldr;

QUnit.module( "Unit Format - Compound Form with no one property in cldr" );

function oneOrOtherPluralGenerator() {
        return "other";
}

function stubNumberFormatter( number ) {
        return number.toString();
}

QUnit.assert.unitFormatJa = function ( value, unit, options, expected ) {
        var unitProps = unitProperties( unit, options.form, cldr );

        this.equal(
                formatUnit( value, options.numberFormatter || stubNumberFormatter, oneOrOtherPluralGenerator, unitProps ),
                expected
        );
};

QUnit.test( "Compound form (without precomputed)", function ( assert ) {
        assert.unitFormatJa( 1, "length-foot-per-second", { form: "long" }, "1 フィート毎秒" );
        assert.unitFormatJa( 100, "length-foot-per-second", { form: "long" }, "100 フィート毎秒" );
        assert.unitFormatJa( 1, "megabyte-per-second", { form: "narrow" }, "1MB/秒" );
        assert.unitFormatJa( 100, "megabyte-per-second", { form: "narrow" }, "100MB/秒" );

        assert.unitFormatJa( 1.2345678910, "megabyte-per-second",
                { form: "narrow", numberFormatter: function (number) { return number.toFixed(1); }},
                "1.2MB/秒" );
});
/* Throws:
>> Unit Format - Compound Form with no one property in cldr - Compound form (without precomputed)
>> Message: Died on test #1 http://localhost:9001/unit/unit/format-ja.js:37:11
>> execCb@http://localhost:9001/external/requirejs/require.js:1678:38
>> check@http://localhost:9001/external/requirejs/require.js:873:61
>> http://localhost:9001/external/requirejs/require.js:1128:39
>> http://localhost:9001/external/requirejs/require.js:131:28
>> http://localhost:9001/external/requirejs/require.js:1178:23
>> each@http://localhost:9001/external/requirejs/require.js:56:35
>> emit@http://localhost:9001/external/requirejs/require.js:1177:21
>> check@http://localhost:9001/external/requirejs/require.js:929:34
>> http://localhost:9001/external/requirejs/require.js:1128:39
>> http://localhost:9001/external/requirejs/require.js:131:28
>> http://localhost:9001/external/requirejs/require.js:1178:23
>> each@http://localhost:9001/external/requirejs/require.js:56:35
>> emit@http://localhost:9001/external/requirejs/require.js:1177:21
>> check@http://localhost:9001/external/requirejs/require.js:929:34
>> http://localhost:9001/external/requirejs/require.js:1128:39
>> http://localhost:9001/external/requirejs/require.js:131:28
>> http://localhost:9001/external/requirejs/require.js:1178:23
>> each@http://localhost:9001/external/requirejs/require.js:56:35
>> emit@http://localhost:9001/external/requirejs/require.js:1177:21
>> check@http://localhost:9001/external/requirejs/require.js:929:34
>> http://localhost:9001/external/requirejs/require.js:1128:39
>> http://localhost:9001/external/requirejs/require.js:131:28
>> http://localhost:9001/external/requirejs/require.js:1178:23
>> each@http://localhost:9001/external/requirejs/require.js:56:35
>> emit@http://localhost:9001/external/requirejs/require.js:1177:21
>> check@http://localhost:9001/external/requirejs/require.js:929:34
>> enable@http://localhost:9001/external/requirejs/require.js:1165:27
>> init@http://localhost:9001/external/requirejs/require.js:783:32
>> callGetModule@http://localhost:9001/external/requirejs/require.js:1192:67
>> completeLoad@http://localhost:9001/external/requirejs/require.js:1571:34
>> onScriptLoad@http://localhost:9001/external/requirejs/require.js:1699:41: undefined is not an object (evaluating 'message.replace')
>> Actual: null
>> Expected: undefined
>> http://localhost:9001/src/common/format-message.js:26:19
>> http://localhost:9001/src/unit/format.js:40:26
>> unitFormatJa@http://localhost:9001/unit/unit/format-ja.js:32:13
>> http://localhost:9001/unit/unit/format-ja.js:38:21
>> run@http://localhost:9001/external/qunit/qunit/qunit.js:895:32
>> http://localhost:9001/external/qunit/qunit/qunit.js:1024:14
>> process@http://localhost:9001/external/qunit/qunit/qunit.js:583:24
>> begin@http://localhost:9001/external/qunit/qunit/qunit.js:628:9
>> http://localhost:9001/external/qunit/qunit/qunit.js:644:9
*/
@tyskelvin

This comment has been minimized.

Copy link

tyskelvin commented Dec 18, 2018

on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment