@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.
@@ -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
@@ -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
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- idInterpolationPattern: '[sha512:contenthash:base64:6]'
3
- };
@@ -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
- });
@@ -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();
@@ -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;
@@ -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
- });