Skip to content

Commit e168c8d

Browse files
committed
Drop intl-pluralrules as unnecessary in modern environments
1 parent 33058c7 commit e168c8d

File tree

3 files changed

+66
-74
lines changed

3 files changed

+66
-74
lines changed

package-lock.json

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"@fluent/dedent": "^0.1.0",
1313
"@fluent/syntax": "0.14.0",
1414
"brace": "^0.11.1",
15-
"intl-pluralrules": "^1.0.3",
1615
"react": "^16.8.6",
1716
"react-ace": "^7.0.2",
1817
"react-dom": "^16.8.6"

src/fluent.js

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,89 @@
11
// vim: ts=4 et sts=4 sw=4
22

3-
import 'intl-pluralrules';
4-
import { FluentBundle, FluentResource } from '@fluent/bundle/compat';
5-
import { FluentParser, lineOffset, columnOffset, Resource }
6-
from '@fluent/syntax/compat';
3+
import { FluentBundle, FluentResource } from "@fluent/bundle/compat";
4+
import {
5+
FluentParser,
6+
lineOffset,
7+
columnOffset,
8+
Resource,
9+
} from "@fluent/syntax/compat";
710

811
const fluent_parser = new FluentParser();
912

1013
export function annotation_display(source, junk, annot) {
11-
const { code, message, span: { start } } = annot;
14+
const {
15+
code,
16+
message,
17+
span: { start },
18+
} = annot;
1219

13-
const slice = source.substring(junk.span.start, junk.span.end);
14-
const line_offset = lineOffset(source, start);
15-
const column_offset = columnOffset(source, start);
16-
const span_offset = lineOffset(source, junk.span.start);
17-
const head_len = line_offset - span_offset + 1;
18-
const lines = slice.split('\n');
19-
const head = lines.slice(0, head_len).join('\n') + '\n';
20-
const tail = lines.slice(head_len).join('\n');
20+
const slice = source.substring(junk.span.start, junk.span.end);
21+
const line_offset = lineOffset(source, start);
22+
const column_offset = columnOffset(source, start);
23+
const span_offset = lineOffset(source, junk.span.start);
24+
const head_len = line_offset - span_offset + 1;
25+
const lines = slice.split("\n");
26+
const head = lines.slice(0, head_len).join("\n") + "\n";
27+
const tail = lines.slice(head_len).join("\n");
2128

22-
return {
23-
code,
24-
message,
25-
line_offset,
26-
column_offset,
27-
head,
28-
tail
29-
}
29+
return {
30+
code,
31+
message,
32+
line_offset,
33+
column_offset,
34+
head,
35+
tail,
36+
};
3037
}
3138

3239
export function parse_translations(translations) {
33-
try {
34-
var res = fluent_parser.parse(translations);
35-
} catch (err) {
36-
console.error(err);
37-
return [
38-
new Resource([]),
39-
[]
40-
];
41-
}
40+
try {
41+
var res = fluent_parser.parse(translations);
42+
} catch (err) {
43+
console.error(err);
44+
return [new Resource([]), []];
45+
}
4246

43-
const junks = res.body.filter(entry => entry.type === "Junk");
44-
const annotations = junks.reduce(
45-
(annots, junk) => annots.concat(
46-
junk.annotations.map(
47-
annot => annotation_display(translations, junk, annot)
48-
)
49-
),
50-
[]
51-
);
52-
return [res, annotations];
47+
const junks = res.body.filter((entry) => entry.type === "Junk");
48+
const annotations = junks.reduce(
49+
(annots, junk) =>
50+
annots.concat(
51+
junk.annotations.map((annot) =>
52+
annotation_display(translations, junk, annot)
53+
)
54+
),
55+
[]
56+
);
57+
return [res, annotations];
5358
}
5459

5560
export function create_bundle(locale, translations) {
56-
const bundle = new FluentBundle(locale);
57-
bundle.addResource(new FluentResource(translations));
58-
return bundle;
61+
const bundle = new FluentBundle(locale);
62+
bundle.addResource(new FluentResource(translations));
63+
return bundle;
5964
}
6065

6166
export function format_messages(ast, bundle, externals) {
62-
const outputs = new Map();
63-
const errors = [];
64-
for (let entry of ast.body) {
65-
if (entry.type !== 'Message') {
66-
continue;
67-
}
68-
const id = entry.id.name;
69-
const message = bundle.getMessage(id);
70-
if (message.value) {
71-
let output = bundle.formatPattern(message.value, externals, errors);
72-
outputs.set(id, output);
73-
}
67+
const outputs = new Map();
68+
const errors = [];
69+
for (let entry of ast.body) {
70+
if (entry.type !== "Message") {
71+
continue;
7472
}
75-
return [outputs, errors];
73+
const id = entry.id.name;
74+
const message = bundle.getMessage(id);
75+
if (message.value) {
76+
let output = bundle.formatPattern(message.value, externals, errors);
77+
outputs.set(id, output);
78+
}
79+
}
80+
return [outputs, errors];
7681
}
7782

7883
export function parse_externals(externals) {
79-
try {
80-
return [JSON.parse(externals), []];
81-
} catch (err) {
82-
return [{}, [err]];
83-
}
84+
try {
85+
return [JSON.parse(externals), []];
86+
} catch (err) {
87+
return [{}, [err]];
88+
}
8489
}

0 commit comments

Comments
 (0)