Skip to content

Commit

Permalink
Address @zbraniecki's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stasm committed Aug 17, 2018
1 parent 9f3daab commit 4084703
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions fluent-dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DOMLocalization } from 'fluent-dom'
const l10n = new DOMLocalization(MutationObserver, [
'/browser/main.ftl',
'/toolkit/menu.ftl'
], generateMessages);
], generateBundles);

l10n.connectRoot(document.documentElement);

Expand All @@ -47,15 +47,15 @@ class that provides just the API needed to format messages in the running code.
```javascript
import { Localization } from 'fluent-dom'

function *generateMessages() {
function *generateBundles() {
// Some lazy logic for yielding FluentBundles.
yield *[bundle1, bundle2];
}

const l10n = new Localization(document, [
'/browser/main.ftl',
'/toolkit/menu.ftl'
], generateMessages);
], generateBundles);

async function main() {
const msg = await l10n.formatValue('welcome', { name: 'Anna' });
Expand Down
10 changes: 5 additions & 5 deletions fluent-dom/src/dom_localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const L10N_ELEMENT_QUERY = `[${L10NID_ATTR_NAME}]`;
*/
export default class DOMLocalization extends Localization {
/**
* @param {Array<String>} resourceIds - List of resource IDs
* @param {Function} generateMessages - Function that returns a
* generator over FluentBundles
* @param {Array<String>} resourceIds - List of resource IDs
* @param {Function} generateBundles - Function that returns a
* generator over FluentBundles
* @returns {DOMLocalization}
*/
constructor(resourceIds, generateMessages) {
super(resourceIds, generateMessages);
constructor(resourceIds, generateBundles) {
super(resourceIds, generateBundles);

// A Set of DOM trees observed by the `MutationObserver`.
this.roots = new Set();
Expand Down
14 changes: 7 additions & 7 deletions fluent-dom/src/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import { CachedAsyncIterable } from "cached-iterable";
*/
export default class Localization {
/**
* @param {Array<String>} resourceIds - List of resource IDs
* @param {Function} generateMessages - Function that returns a
* generator over FluentBundles
* @param {Array<String>} resourceIds - List of resource IDs
* @param {Function} generateBundles - Function that returns a
* generator over FluentBundles
*
* @returns {Localization}
*/
constructor(resourceIds = [], generateMessages) {
constructor(resourceIds = [], generateBundles) {
this.resourceIds = resourceIds;
this.generateMessages = generateMessages;
this.generateBundles = generateBundles;
this.bundles = CachedAsyncIterable.from(
this.generateMessages(this.resourceIds));
this.generateBundles(this.resourceIds));
}

addResourceIds(resourceIds) {
Expand Down Expand Up @@ -155,7 +155,7 @@ export default class Localization {
*/
onChange() {
this.bundles = CachedAsyncIterable.from(
this.generateMessages(this.resourceIds));
this.generateBundles(this.resourceIds));
this.bundles.touchNext(2);
}
}
Expand Down
4 changes: 2 additions & 2 deletions fluent-gecko/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ PACKAGE := fluent-gecko

include ../common.mk

build: FluentBundle.jsm Localization.jsm DOMLocalization.jsm l10n.js
build: Fluent.jsm Localization.jsm DOMLocalization.jsm l10n.js

FluentBundle.jsm: $(SOURCES)
Fluent.jsm: $(SOURCES)
@rollup $(CURDIR)/src/message_context.js \
--config ./xpcom_config.js \
--output.file ./dist/$@
Expand Down
6 changes: 3 additions & 3 deletions fluent-gecko/src/dom_localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import DOMLocalization from "../../fluent-dom/src/dom_localization";
* with a different negotitation strategy to allow for the module to
* be localized into a different language - for example DevTools.
*/
function defaultGenerateMessages(resourceIds) {
function defaultGenerateBundles(resourceIds) {
const requestedLocales = Services.locale.getRequestedLocales();
const availableLocales = L10nRegistry.getAvailableLocales();
const defaultLocale = Services.locale.defaultLocale;
Expand All @@ -25,9 +25,9 @@ class GeckoDOMLocalization extends DOMLocalization {
constructor(
windowElement,
resourceIds,
generateMessages = defaultGenerateMessages
generateBundles = defaultGenerateBundles
) {
super(windowElement, resourceIds, generateMessages);
super(windowElement, resourceIds, generateBundles);
}
}

Expand Down
6 changes: 3 additions & 3 deletions fluent-gecko/src/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Localization from "../../fluent-dom/src/localization";
* with a different negotitation strategy to allow for the module to
* be localized into a different language - for example DevTools.
*/
function defaultGenerateMessages(resourceIds) {
function defaultGenerateBundles(resourceIds) {
const requestedLocales = Services.locale.getRequestedLocales();
const availableLocales = L10nRegistry.getAvailableLocales();
const defaultLocale = Services.locale.defaultLocale;
Expand All @@ -35,8 +35,8 @@ function defaultGenerateMessages(resourceIds) {
}

class GeckoLocalization extends Localization {
constructor(resourceIds, generateMessages = defaultGenerateMessages) {
super(resourceIds, generateMessages);
constructor(resourceIds, generateBundles = defaultGenerateBundles) {
super(resourceIds, generateBundles);
}
}

Expand Down
22 changes: 11 additions & 11 deletions fluent-sequence/test/fallback_async_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,41 @@ import FluentBundle from './bundle_stub';
import {mapBundleAsync} from '../src/index';

suite('Async Fallback — single id', function() {
let bundle1, bundle2, generateMessages;
let bundle1, bundle2, generateBundles;

suiteSetup(function() {
bundle1 = new FluentBundle();
bundle1._setMessages(['bar']);
bundle2 = new FluentBundle();
bundle2._setMessages(['foo', 'bar']);

generateMessages = async function *generateMessages() {
generateBundles = async function *generateBundles() {
yield *[bundle1, bundle2];
}
});

test('eager iterable', async function() {
const bundles = new CachedAsyncIterable(generateMessages());
const bundles = new CachedAsyncIterable(generateBundles());
assert.equal(await mapBundleAsync(bundles, 'foo'), bundle2);
assert.equal(await mapBundleAsync(bundles, 'bar'), bundle1);
});

test('eager iterable works more than once', async function() {
const bundles = new CachedAsyncIterable(generateMessages());
const bundles = new CachedAsyncIterable(generateBundles());
assert.equal(await mapBundleAsync(bundles, 'foo'), bundle2);
assert.equal(await mapBundleAsync(bundles, 'bar'), bundle1);
assert.equal(await mapBundleAsync(bundles, 'foo'), bundle2);
assert.equal(await mapBundleAsync(bundles, 'bar'), bundle1);
});

test('lazy iterable', async function() {
const bundles = new CachedAsyncIterable(generateMessages());
const bundles = new CachedAsyncIterable(generateBundles());
assert.equal(await mapBundleAsync(bundles, 'foo'), bundle2);
assert.equal(await mapBundleAsync(bundles, 'bar'), bundle1);
});

test('lazy iterable works more than once', async function() {
const bundles = new CachedAsyncIterable(generateMessages());
const bundles = new CachedAsyncIterable(generateBundles());
assert.equal(await mapBundleAsync(bundles, 'foo'), bundle2);
assert.equal(await mapBundleAsync(bundles, 'bar'), bundle1);
assert.equal(await mapBundleAsync(bundles, 'foo'), bundle2);
Expand All @@ -48,37 +48,37 @@ suite('Async Fallback — single id', function() {
});

suite('Async Fallback — multiple ids', async function() {
let bundle1, bundle2, generateMessages;
let bundle1, bundle2, generateBundles;

suiteSetup(function() {
bundle1 = new FluentBundle();
bundle1._setMessages(['foo', 'bar']);
bundle2 = new FluentBundle();
bundle2._setMessages(['foo', 'bar', 'baz']);

generateMessages = async function *generateMessages() {
generateBundles = async function *generateBundles() {
yield *[bundle1, bundle2];
}
});

test('existing translations', async function() {
const bundles = new CachedAsyncIterable(generateMessages());
const bundles = new CachedAsyncIterable(generateBundles());
assert.deepEqual(
await mapBundleAsync(bundles, ['foo', 'bar']),
[bundle1, bundle1]
);
});

test('fallback translations', async function() {
const bundles = new CachedAsyncIterable(generateMessages());
const bundles = new CachedAsyncIterable(generateBundles());
assert.deepEqual(
await mapBundleAsync(bundles, ['foo', 'bar', 'baz']),
[bundle1, bundle1, bundle2]
);
});

test('missing translations', async function() {
const bundles = new CachedAsyncIterable(generateMessages());
const bundles = new CachedAsyncIterable(generateBundles());
assert.deepEqual(
await mapBundleAsync(bundles, ['foo', 'bar', 'baz', 'qux']),
[bundle1, bundle1, bundle2, null]
Expand Down
8 changes: 4 additions & 4 deletions fluent-sequence/test/fallback_sync_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ suite('Sync Fallback — single id', function() {
});

test('lazy iterable', function() {
function *generateMessages() {
function *generateBundles() {
yield *[bundle1, bundle2];
}

const bundles = new CachedSyncIterable(generateMessages());
const bundles = new CachedSyncIterable(generateBundles());
assert.equal(mapBundleSync(bundles, 'foo'), bundle2);
assert.equal(mapBundleSync(bundles, 'bar'), bundle1);
});

test('lazy iterable works more than once', function() {
function *generateMessages() {
function *generateBundles() {
yield *[bundle1, bundle2];
}

const bundles = new CachedSyncIterable(generateMessages());
const bundles = new CachedSyncIterable(generateBundles());
assert.equal(mapBundleSync(bundles, 'foo'), bundle2);
assert.equal(mapBundleSync(bundles, 'bar'), bundle1);
assert.equal(mapBundleSync(bundles, 'foo'), bundle2);
Expand Down

0 comments on commit 4084703

Please sign in to comment.