Skip to content

Commit 7a773ab

Browse files
author
Zibi Braniecki
committed
fluent-web 0.1.0
1 parent d745807 commit 7a773ab

File tree

5 files changed

+38
-27
lines changed

5 files changed

+38
-27
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
"extends": "airbnb-base"
3+
};

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## fluent-web 0.1.0
6+
7+
- Update to Fluent 0.10.0
8+
- Update to FluentDOM 0.4.1
59
- Drop support for IE and old evergreen browsers. (#133)
610

711
Currently supported are: Firefox 52+, Chrome 55+, Edge 15+, Safari 10.1+,

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ git clone https://github.com/projectfluent/fluent-web
2424
cd fluent-web
2525
npm install
2626
npm start
27+
open http://127.0.0.1:8080/examples/simple.html
2728
```
2829

2930

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "fluent-web",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Drop-in localization framework for HTML documents",
55
"repository": {
66
"type": "git",
7-
"url": "https://github.com/projectfluent/fluent.js.git"
7+
"url": "https://github.com/projectfluent/fluent-web.git"
88
},
99
"author": "Mozilla <[email protected]>",
10+
"homepage": "http://projectfluent.org",
1011
"license": "Apache-2.0",
1112
"contributors": [
1213
{
@@ -39,16 +40,19 @@
3940
"node": ">=8.9.0"
4041
},
4142
"scripts": {
42-
"start": "make -f makefile build & npx http-server ./examples"
43+
"start": "make -f makefile build & npx http-server ./"
4344
},
4445
"dependencies": {
45-
"fluent": "~0.8.1",
46-
"fluent-langneg": "~0.1.0",
47-
"fluent-dom": "~0.4.0",
48-
"cached-iterable": "~0.2.1"
46+
"cached-iterable": "^0.3.0",
47+
"fluent": "^0.10.0",
48+
"fluent-dom": "^0.4.1",
49+
"fluent-langneg": "~0.1.0"
4950
},
5051
"devDependencies": {
51-
"rollup": "~0.66.3",
52-
"rollup-plugin-node-resolve": "^3.4.0"
52+
"eslint": "^5.11.1",
53+
"eslint-config-airbnb-base": "^13.1.0",
54+
"eslint-plugin-import": "^2.14.0",
55+
"rollup": "^1.0.1",
56+
"rollup-plugin-node-resolve": "^4.0.0"
5357
}
5458
}

src/index.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
/* eslint-env browser */
22

3-
import { negotiateLanguages } from "fluent-langneg";
4-
import { FluentBundle } from "fluent";
5-
import { DOMLocalization } from "fluent-dom";
6-
import { CachedAsyncIterable } from "cached-iterable";
3+
import { negotiateLanguages } from 'fluent-langneg';
4+
import { FluentBundle } from 'fluent';
5+
import { DOMLocalization } from 'fluent-dom';
76

87
function documentReady() {
98
const rs = document.readyState;
10-
if (rs === "interactive" || rs === "completed") {
9+
if (rs === 'interactive' || rs === 'completed') {
1110
return Promise.resolve();
1211
}
1312

1413
return new Promise(
1514
resolve => document.addEventListener(
16-
"readystatechange", resolve, { once: true }
17-
)
15+
'readystatechange', resolve, { once: true },
16+
),
1817
);
1918
}
2019

2120
function getMeta(elem) {
2221
return {
2322
available: elem.querySelector('meta[name="availableLanguages"]')
24-
.getAttribute("content")
25-
.split(",").map(s => s.trim()),
23+
.getAttribute('content')
24+
.split(',').map(s => s.trim()),
2625
default: elem.querySelector('meta[name="defaultLanguage"]')
27-
.getAttribute("content"),
26+
.getAttribute('content'),
2827
};
2928
}
3029

3130
function getResourceLinks(elem) {
3231
return Array.prototype.map.call(
3332
elem.querySelectorAll('link[rel="localization"]'),
34-
el => el.getAttribute("href")
33+
el => el.getAttribute('href'),
3534
);
3635
}
3736

3837
async function fetchResource(locale, id) {
39-
const url = id.replace("{locale}", locale);
38+
const url = id.replace('{locale}', locale);
4039
const response = await fetch(url);
4140
return response.text();
4241
}
@@ -46,7 +45,7 @@ async function createContext(locale, resourceIds) {
4645

4746
// First fetch all resources
4847
const resources = await Promise.all(
49-
resourceIds.map(id => fetchResource(locale, id))
48+
resourceIds.map(id => fetchResource(locale, id)),
5049
);
5150

5251
// Then apply them preserving order
@@ -63,19 +62,19 @@ async function* generateMessages(resourceIds) {
6362
navigator.languages,
6463
meta.available,
6564
{
66-
defaultLocale: meta.default
67-
}
65+
defaultLocale: meta.default,
66+
},
6867
);
6968
for (const locale of locales) {
70-
yield await createContext(locale, resourceIds);
69+
yield createContext(locale, resourceIds);
7170
}
7271
}
7372

7473
const resourceIds = getResourceLinks(document.head);
7574
document.l10n = new DOMLocalization(
76-
resourceIds, generateMessages
75+
resourceIds, generateMessages,
7776
);
78-
window.addEventListener("languagechange", document.l10n);
77+
window.addEventListener('languagechange', document.l10n);
7978

8079
document.l10n.ready = documentReady().then(() => {
8180
document.l10n.connectRoot(document.documentElement);

0 commit comments

Comments
 (0)