Skip to content

Commit c00c007

Browse files
authored
Merge @fluent/bundle 0.14 release branch
2 parents 7ce60b1 + 91256b4 commit c00c007

File tree

160 files changed

+5677
-3788
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+5677
-3788
lines changed

fluent-dedent/test/blank_test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ftl from "../src/index";
55

66
suite("blank lines", function() {
77
test("leading", function() {
8-
assert.equal(
8+
assert.strictEqual(
99
ftl`
1010
1111
foo
@@ -15,7 +15,7 @@ suite("blank lines", function() {
1515
});
1616

1717
test("middle", function() {
18-
assert.equal(
18+
assert.strictEqual(
1919
ftl`
2020
foo
2121
@@ -26,7 +26,7 @@ suite("blank lines", function() {
2626
});
2727

2828
test("trailing", function() {
29-
assert.equal(
29+
assert.strictEqual(
3030
ftl`
3131
foo
3232
@@ -36,7 +36,7 @@ suite("blank lines", function() {
3636
});
3737

3838
test("containing the same amount of spaces as the common indent", function() {
39-
assert.equal(
39+
assert.strictEqual(
4040
ftl`
4141
4242
`,
@@ -54,7 +54,7 @@ suite("blank lines", function() {
5454
});
5555

5656
test("containing too many spaces", function() {
57-
assert.equal(
57+
assert.strictEqual(
5858
ftl`
5959
6060
`,

fluent-dedent/test/content_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ftl from "../src/index";
55

66
suite("content lines", function() {
77
test("no indent", function () {
8-
assert.equal(
8+
assert.strictEqual(
99
ftl`
1010
foo
1111
bar
@@ -15,7 +15,7 @@ bar
1515
});
1616

1717
test("zero indent", function () {
18-
assert.equal(
18+
assert.strictEqual(
1919
ftl`
2020
foo
2121
bar
@@ -25,7 +25,7 @@ bar
2525
});
2626

2727
test("small indent", function () {
28-
assert.equal(
28+
assert.strictEqual(
2929
ftl`
3030
foo
3131
bar
@@ -35,7 +35,7 @@ bar
3535
});
3636

3737
test("same indent", function () {
38-
assert.equal(
38+
assert.strictEqual(
3939
ftl`
4040
foo
4141
bar

fluent-dedent/test/eol_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ suite("EOL at extremes", function () {
2828
});
2929

3030
test("two EOLs", function () {
31-
assert.equal(
31+
assert.strictEqual(
3232
ftl`
3333
foo
3434
`,

fluent-dedent/test/interpolation_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ftl from "../src/index";
55

66
suite("interpolation", function() {
77
test("single", function() {
8-
assert.equal(
8+
assert.strictEqual(
99
ftl`
1010
foo ${"bar"}
1111
`,
@@ -14,7 +14,7 @@ suite("interpolation", function() {
1414
});
1515

1616
test("multiple", function() {
17-
assert.equal(
17+
assert.strictEqual(
1818
ftl`
1919
foo ${"bar"}${"baz"}
2020
`,
@@ -23,7 +23,7 @@ suite("interpolation", function() {
2323
});
2424

2525
test("on separate lines", function() {
26-
assert.equal(
26+
assert.strictEqual(
2727
ftl`
2828
${"foo"}
2929
${"bar"}

fluent-dedent/test/mixed_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ftl from "../src/index";
55

66
suite("mixed indent", function() {
77
test("same amount", function() {
8-
assert.equal(
8+
assert.strictEqual(
99
ftl`
1010
\t foo
1111
\t `,
@@ -14,7 +14,7 @@ suite("mixed indent", function() {
1414
});
1515

1616
test("larger than common", function() {
17-
assert.equal(
17+
assert.strictEqual(
1818
ftl`
1919
\t foo
2020
\t `,

fluent-dedent/test/tabs_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ftl from "../src/index";
55

66
suite("tab indent", function() {
77
test("same amount", function() {
8-
assert.equal(
8+
assert.strictEqual(
99
ftl`
1010
\t\tfoo
1111
\t\t`,
@@ -14,7 +14,7 @@ suite("tab indent", function() {
1414
});
1515

1616
test("larger than common", function() {
17-
assert.equal(
17+
assert.strictEqual(
1818
ftl`
1919
\t\t\tfoo
2020
\t\t`,

fluent-dom/src/localization.js

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export default class Localization {
7171
/**
7272
* Format translations into {value, attributes} objects.
7373
*
74-
* The fallback logic is the same as in `formatValues` but the argument type
75-
* is stricter (an array of arrays) and it returns {value, attributes}
76-
* objects which are suitable for the translation of DOM elements.
74+
* The fallback logic is the same as in `formatValues` but it returns {value,
75+
* attributes} objects which are suitable for the translation of DOM
76+
* elements.
7777
*
7878
* docL10n.formatMessages([
7979
* {id: 'hello', args: { who: 'Mary' }},
@@ -101,8 +101,8 @@ export default class Localization {
101101
/**
102102
* Retrieve translations corresponding to the passed keys.
103103
*
104-
* A generalized version of `DOMLocalization.formatValue`. Keys can
105-
* either be simple string identifiers or `[id, args]` arrays.
104+
* A generalized version of `DOMLocalization.formatValue`. Keys must
105+
* be `{id, args}` objects.
106106
*
107107
* docL10n.formatValues([
108108
* {id: 'hello', args: { who: 'Mary' }},
@@ -164,26 +164,26 @@ export default class Localization {
164164
}
165165

166166
/**
167-
* Format the value of a message into a string.
167+
* Format the value of a message into a string or `null`.
168168
*
169169
* This function is passed as a method to `keysFromBundle` and resolve
170170
* a value of a single L10n Entity using provided `FluentBundle`.
171171
*
172-
* If the function fails to retrieve the entity, it will return an ID of it.
173-
* If formatting fails, it will return a partially resolved entity.
174-
*
175-
* In both cases, an error is being added to the errors array.
172+
* If the message doesn't have a value, return `null`.
176173
*
177174
* @param {FluentBundle} bundle
178-
* @param {Array<Error>} errors
179-
* @param {string} id
180-
* @param {Object} args
181-
* @returns {string}
175+
* @param {Array<Error>} errors
176+
* @param {Object} message
177+
* @param {Object} args
178+
* @returns {string|null}
182179
* @private
183180
*/
184-
function valueFromBundle(bundle, errors, id, args) {
185-
const msg = bundle.getMessage(id);
186-
return bundle.format(msg, args, errors);
181+
function valueFromBundle(bundle, errors, message, args) {
182+
if (message.value) {
183+
return bundle.formatPattern(message.value, args, errors);
184+
}
185+
186+
return null;
187187
}
188188

189189
/**
@@ -195,34 +195,29 @@ function valueFromBundle(bundle, errors, id, args) {
195195
* The function will return an object with a value and attributes of the
196196
* entity.
197197
*
198-
* If the function fails to retrieve the entity, the value is set to the ID of
199-
* an entity, and attributes to `null`. If formatting fails, it will return
200-
* a partially resolved value and attributes.
201-
*
202-
* In both cases, an error is being added to the errors array.
203-
*
204198
* @param {FluentBundle} bundle
205-
* @param {Array<Error>} errors
206-
* @param {String} id
207-
* @param {Object} args
199+
* @param {Array<Error>} errors
200+
* @param {Object} message
201+
* @param {Object} args
208202
* @returns {Object}
209203
* @private
210204
*/
211-
function messageFromBundle(bundle, errors, id, args) {
212-
const msg = bundle.getMessage(id);
213-
205+
function messageFromBundle(bundle, errors, message, args) {
214206
const formatted = {
215-
value: bundle.format(msg, args, errors),
207+
value: null,
216208
attributes: null,
217209
};
218210

219-
if (msg.attrs) {
220-
formatted.attributes = [];
221-
for (const [name, attr] of Object.entries(msg.attrs)) {
222-
const value = bundle.format(attr, args, errors);
223-
if (value !== null) {
224-
formatted.attributes.push({name, value});
225-
}
211+
if (message.value) {
212+
formatted.value = bundle.formatPattern(message.value, args, errors);
213+
}
214+
215+
let attrNames = Object.keys(message.attributes);
216+
if (attrNames.length > 0) {
217+
formatted.attributes = new Array(attrNames.length);
218+
for (let [i, name] of attrNames.entries()) {
219+
let value = bundle.formatPattern(message.attributes[name], args, errors);
220+
formatted.attributes[i] = {name, value};
226221
}
227222
}
228223

@@ -270,9 +265,10 @@ function keysFromBundle(method, bundle, keys, translations) {
270265
return;
271266
}
272267

273-
if (bundle.hasMessage(id)) {
268+
let message = bundle.getMessage(id);
269+
if (message) {
274270
messageErrors.length = 0;
275-
translations[i] = method(bundle, messageErrors, id, args);
271+
translations[i] = method(bundle, messageErrors, message, args);
276272
// XXX: Report resolver errors
277273
} else {
278274
missingIds.add(id);

fluent-dom/test/dom_localization_test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import assert from "assert";
2-
import { FluentBundle } from "../../fluent/src/index";
2+
import { FluentBundle, FluentResource } from "../../fluent/src/index";
33
import DOMLocalization from "../src/dom_localization";
44

55
async function* mockGenerateMessages(resourceIds) {
66
const bundle = new FluentBundle(["en-US"]);
7-
bundle.addMessages("key1 = Key 1");
7+
const resource = new FluentResource("key1 = Key 1");
8+
bundle.addResource(resource);
89
yield bundle;
910
}
1011

@@ -19,7 +20,7 @@ suite("translateFragment", function() {
1920

2021
await domLoc.translateFragment(frag);
2122

22-
assert.equal(elem.textContent, "Key 1");
23+
assert.strictEqual(elem.textContent, "Key 1");
2324
});
2425

2526
test("does not inject content into a node with missing translation", async function() {
@@ -33,7 +34,7 @@ suite("translateFragment", function() {
3334

3435
await domLoc.translateFragment(frag);
3536

36-
assert.equal(elem.textContent, "Original Value");
37+
assert.strictEqual(elem.textContent, "Original Value");
3738
});
3839

3940
});

fluent-dom/test/extra_text_markup_test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ suite('Localized text markup', function() {
1111
};
1212

1313
translateElement(element, translation);
14-
assert.equal(element.innerHTML, 'FOO <em>BAR</em> BAZ');
14+
assert.strictEqual(element.innerHTML, 'FOO <em>BAR</em> BAZ');
1515
});
1616

1717
test('forbidden element', function() {
@@ -22,7 +22,7 @@ suite('Localized text markup', function() {
2222
};
2323

2424
translateElement(element, translation);
25-
assert.equal(element.innerHTML, 'FOO ');
25+
assert.strictEqual(element.innerHTML, 'FOO ');
2626
});
2727

2828
test('forbidden element with text', function() {
@@ -33,7 +33,7 @@ suite('Localized text markup', function() {
3333
};
3434

3535
translateElement(element, translation);
36-
assert.equal(element.innerHTML, 'FOO BUTTON');
36+
assert.strictEqual(element.innerHTML, 'FOO BUTTON');
3737
});
3838

3939
test('nested HTML is forbidden', function() {
@@ -44,7 +44,7 @@ suite('Localized text markup', function() {
4444
};
4545

4646
translateElement(element, translation);
47-
assert.equal(element.innerHTML, 'FOO <em>BAR</em> BAZ');
47+
assert.strictEqual(element.innerHTML, 'FOO <em>BAR</em> BAZ');
4848
});
4949
});
5050

@@ -57,7 +57,7 @@ suite('Attributes of localized text markup', function() {
5757
};
5858

5959
translateElement(element, translation);
60-
assert.equal(element.innerHTML,
60+
assert.strictEqual(element.innerHTML,
6161
'FOO <em title="BAR">BAR</em>');
6262
});
6363

@@ -69,7 +69,7 @@ suite('Attributes of localized text markup', function() {
6969
};
7070

7171
translateElement(element, translation);
72-
assert.equal(element.innerHTML,
72+
assert.strictEqual(element.innerHTML,
7373
'FOO <em title="BAR">BAR</em>');
7474
});
7575

@@ -82,7 +82,7 @@ suite('Attributes of localized text markup', function() {
8282
};
8383

8484
translateElement(element, translation);
85-
assert.equal(element.innerHTML,
85+
assert.strictEqual(element.innerHTML,
8686
'<em>FOO</em>');
8787
});
8888

@@ -98,10 +98,10 @@ suite('Attributes of localized text markup', function() {
9898
};
9999

100100
translateElement(element, translationA);
101-
assert.equal(element.innerHTML,
101+
assert.strictEqual(element.innerHTML,
102102
'<em title="FOO A">FOO A</em>');
103103
translateElement(element, translationB);
104-
assert.equal(element.innerHTML,
104+
assert.strictEqual(element.innerHTML,
105105
'<em>FOO B</em>');
106106
});
107107
});

0 commit comments

Comments
 (0)