@micromag/intl 0.3.541 → 0.3.548
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/locale/en.js +534 -2169
- package/locale/en.json +534 -3248
- package/locale/fr.js +533 -2165
- package/locale/fr.json +533 -3242
- package/package.json +5 -8
- package/lib/index.js +0 -121
- package/locale/en.cjs.js +0 -2537
- package/locale/fr.cjs.js +0 -2533
- package/scripts/build-intl.sh +0 -21
- package/scripts/compile.js +0 -33
- package/scripts/config.js +0 -3
- package/scripts/extract.js +0 -29
- package/scripts/json2po.js +0 -27
- package/scripts/lib/POFile.js +0 -100
- package/scripts/po2json.js +0 -19
package/scripts/build-intl.sh
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
export NODE_ENV=production
|
|
3
|
-
|
|
4
|
-
languages=$(jq -r '.supportedLocales | join(" ")' ./package.json)
|
|
5
|
-
languages_pattern=$(jq -r '.supportedLocales | join("|")' ./package.json)
|
|
6
|
-
|
|
7
|
-
echo "Building intl..."
|
|
8
|
-
|
|
9
|
-
./scripts/extract.js '../../!(node_modules)/!(intl)/src/**/*.+(js|jsx)' ./lang/messages.json
|
|
10
|
-
|
|
11
|
-
for lang in $languages
|
|
12
|
-
do
|
|
13
|
-
if [ "$lang" = "en" ]; then
|
|
14
|
-
./scripts/json2po.js --default ./lang/messages.json ./lang/$lang.po
|
|
15
|
-
else
|
|
16
|
-
./scripts/json2po.js ./lang/messages.json ./lang/$lang.po
|
|
17
|
-
fi
|
|
18
|
-
./scripts/po2json.js ./lang/$lang.po ./lang/$lang.json
|
|
19
|
-
done
|
|
20
|
-
|
|
21
|
-
./scripts/compile.js --ast "./lang/+($languages_pattern).json" ./locale
|
package/scripts/compile.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { program } = require('commander');
|
|
4
|
-
const { sync: globSync } = require('glob');
|
|
5
|
-
const { compileAndWrite } = require('@formatjs/cli');
|
|
6
|
-
const { idInterpolationPattern } = require('./config');
|
|
7
|
-
|
|
8
|
-
let srcPath;
|
|
9
|
-
let destPath;
|
|
10
|
-
program
|
|
11
|
-
.arguments('<src> <dest>')
|
|
12
|
-
.option('-a, --ast', 'With ast')
|
|
13
|
-
.action((src, dest) => {
|
|
14
|
-
srcPath = src;
|
|
15
|
-
destPath = dest;
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
program.parse(process.argv);
|
|
19
|
-
|
|
20
|
-
const options = program.opts();
|
|
21
|
-
|
|
22
|
-
globSync(srcPath, {
|
|
23
|
-
nodir: true,
|
|
24
|
-
cwd: process.cwd(),
|
|
25
|
-
}).forEach((file) => {
|
|
26
|
-
compileAndWrite([path.join(process.cwd(), file)], {
|
|
27
|
-
ast: options.ast,
|
|
28
|
-
skipErrors: false,
|
|
29
|
-
// format: 'crowdin',
|
|
30
|
-
idInterpolationPattern,
|
|
31
|
-
outFile: path.join(process.cwd(), destPath, path.basename(file)),
|
|
32
|
-
});
|
|
33
|
-
});
|
package/scripts/config.js
DELETED
package/scripts/extract.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { program } = require('commander');
|
|
4
|
-
const { sync: globSync } = require('glob');
|
|
5
|
-
const { extractAndWrite } = require('@formatjs/cli');
|
|
6
|
-
const { idInterpolationPattern } = require('./config');
|
|
7
|
-
|
|
8
|
-
let srcPath;
|
|
9
|
-
let destPath;
|
|
10
|
-
program.arguments('<src> <dest>').action((src, dest) => {
|
|
11
|
-
srcPath = src;
|
|
12
|
-
destPath = dest;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
program.parse(process.argv);
|
|
16
|
-
|
|
17
|
-
const files = globSync(srcPath, {
|
|
18
|
-
nodir: true,
|
|
19
|
-
cwd: process.cwd(),
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
extractAndWrite(files, {
|
|
23
|
-
throws: false,
|
|
24
|
-
// format: 'crowdin',
|
|
25
|
-
idInterpolationPattern,
|
|
26
|
-
// extractSourceLocation: true,
|
|
27
|
-
outFile: path.join(process.cwd(), destPath),
|
|
28
|
-
// extractFromFormatMessageCall: true,
|
|
29
|
-
});
|
package/scripts/json2po.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const { program } = require('commander');
|
|
3
|
-
const fsExtra = require('fs-extra');
|
|
4
|
-
|
|
5
|
-
const POFile = require('./lib/POFile');
|
|
6
|
-
|
|
7
|
-
let srcPath;
|
|
8
|
-
let destPath;
|
|
9
|
-
program
|
|
10
|
-
.arguments('<src> <dest>')
|
|
11
|
-
.option('-d, --default', 'Is default language')
|
|
12
|
-
.action((src, dest) => {
|
|
13
|
-
srcPath = src;
|
|
14
|
-
destPath = dest;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
program.parse(process.argv);
|
|
18
|
-
|
|
19
|
-
const options = program.opts();
|
|
20
|
-
|
|
21
|
-
const messages = fsExtra.readJsonSync(srcPath);
|
|
22
|
-
|
|
23
|
-
const poFile = new POFile(destPath, {
|
|
24
|
-
useDefaultMessage: options.default || false,
|
|
25
|
-
});
|
|
26
|
-
poFile.update(messages);
|
|
27
|
-
poFile.save();
|
package/scripts/lib/POFile.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const fsExtra = require('fs-extra');
|
|
3
|
-
const gettextParser = require('gettext-parser');
|
|
4
|
-
const isEmpty = require('lodash/isEmpty');
|
|
5
|
-
|
|
6
|
-
class POFile {
|
|
7
|
-
static parse(filePath) {
|
|
8
|
-
const input = fs.readFileSync(filePath);
|
|
9
|
-
const po = gettextParser.po.parse(input);
|
|
10
|
-
return Object.keys(po.translations).reduce(
|
|
11
|
-
(allTranslations, ctx) =>
|
|
12
|
-
Object.keys(po.translations[ctx]).reduce((currentTranslations, msg) => {
|
|
13
|
-
const translation = po.translations[ctx][msg] || null;
|
|
14
|
-
return translation !== null && translation.msgid.length > 0 ? [
|
|
15
|
-
...currentTranslations,
|
|
16
|
-
translation
|
|
17
|
-
] : currentTranslations;
|
|
18
|
-
}, allTranslations),
|
|
19
|
-
[],
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
constructor(filePath, opts = {}) {
|
|
24
|
-
this.options = {
|
|
25
|
-
useDefaultMessage: false,
|
|
26
|
-
...opts,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
this.path = filePath;
|
|
30
|
-
this.headers = {
|
|
31
|
-
'Project-Id-Version': 'PACKAGE VERSION',
|
|
32
|
-
'Report-Msgid-Bugs-To': '',
|
|
33
|
-
'POT-Creation-Date': '2020-12-14 14:06-0400',
|
|
34
|
-
'PO-Revision-Date': 'YEAR-MO-DA HO:MI+ZONE',
|
|
35
|
-
'Last-Translator': 'FULL NAME <EMAIL@ADDRESS>',
|
|
36
|
-
'Language-Team': 'LANGUAGE <LL@li.org>',
|
|
37
|
-
'MIME-Version': '1.0',
|
|
38
|
-
'Content-Type': 'text/plain; charset=UTF-8',
|
|
39
|
-
'Content-Transfer-Encoding': '8bit',
|
|
40
|
-
'X-Generator': 'Translate Toolkit 3.2.0',
|
|
41
|
-
};
|
|
42
|
-
this.translations = fs.existsSync(filePath) ? POFile.parse(filePath) : [];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
update(messages) {
|
|
46
|
-
const { useDefaultMessage } = this.options;
|
|
47
|
-
const newTranslations = Object.keys(messages).map((id) => {
|
|
48
|
-
const { defaultMessage, description } = messages[id];
|
|
49
|
-
const currentTranslation =
|
|
50
|
-
this.translations.find(({ comments: { reference }, msgctxt = null }) => (msgctxt || reference) === id) || null;
|
|
51
|
-
const defaultValue = useDefaultMessage ? [defaultMessage] : [];
|
|
52
|
-
return {
|
|
53
|
-
msgctxt: id,
|
|
54
|
-
msgid: defaultMessage,
|
|
55
|
-
msgstr:
|
|
56
|
-
currentTranslation !== null && !isEmpty(currentTranslation.msgstr.join(''))
|
|
57
|
-
? currentTranslation.msgstr
|
|
58
|
-
: defaultValue,
|
|
59
|
-
comments: {
|
|
60
|
-
translator: description,
|
|
61
|
-
reference: id,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
this.translations = newTranslations;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
save() {
|
|
70
|
-
const outputBuf = gettextParser.po.compile({
|
|
71
|
-
charset: 'utf-8',
|
|
72
|
-
headers: this.headers,
|
|
73
|
-
translations: {
|
|
74
|
-
'': this.translations.reduce((map, translation) => ({
|
|
75
|
-
...map,
|
|
76
|
-
[translation.msgctxt]: translation,
|
|
77
|
-
}), {}),
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
fsExtra.outputFileSync(this.path, outputBuf);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
toJSON() {
|
|
85
|
-
return this.translations.reduce(
|
|
86
|
-
(map, { comments: { reference }, msgstr, msgctxt = null }) =>
|
|
87
|
-
msgstr.length > 0 && !isEmpty(msgstr[0])
|
|
88
|
-
? {
|
|
89
|
-
...map,
|
|
90
|
-
[msgctxt || reference]: {
|
|
91
|
-
defaultMessage: msgstr[0],
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
: map,
|
|
95
|
-
{},
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
module.exports = POFile;
|
package/scripts/po2json.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const { program } = require('commander');
|
|
3
|
-
const fsExtra = require('fs-extra');
|
|
4
|
-
|
|
5
|
-
const POFile = require('./lib/POFile');
|
|
6
|
-
|
|
7
|
-
let srcPath;
|
|
8
|
-
let destPath;
|
|
9
|
-
program.arguments('<src> <dest>').action((src, dest) => {
|
|
10
|
-
srcPath = src;
|
|
11
|
-
destPath = dest;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
program.parse(process.argv);
|
|
15
|
-
|
|
16
|
-
const poFile = new POFile(srcPath);
|
|
17
|
-
fsExtra.outputJsonSync(destPath, poFile.toJSON(), {
|
|
18
|
-
spaces: 4,
|
|
19
|
-
});
|