@lingui/format-csv 4.0.0-next.2
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/README.md +43 -0
- package/dist/csv.cjs +42 -0
- package/dist/csv.d.ts +5 -0
- package/dist/csv.mjs +40 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[![License][badge-license]][license]
|
|
2
|
+
[![Version][badge-version]][package]
|
|
3
|
+
[![Downloads][badge-downloads]][package]
|
|
4
|
+
|
|
5
|
+
# @lingui/format-csv
|
|
6
|
+
|
|
7
|
+
> Read and write message catalogs in CSV
|
|
8
|
+
|
|
9
|
+
`@lingui/format-csv` is part of [LinguiJS][linguijs]. See the
|
|
10
|
+
[documentation][documentation] for all information, tutorials and examples.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install --save-dev @lingui/format-csv
|
|
16
|
+
# yarn add --dev @lingui/format-csv
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// lingui.config.{js,ts}
|
|
23
|
+
import {formatter} from "@lingui/format-csv"
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
[...]
|
|
27
|
+
format: formatter(),
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This formatter has no options.
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
This package is licensed under [MIT][license] license.
|
|
36
|
+
|
|
37
|
+
[license]: https://github.com/lingui/js-lingui/blob/main/LICENSE
|
|
38
|
+
[linguijs]: https://github.com/lingui/js-lingui
|
|
39
|
+
[documentation]: https://lingui.dev
|
|
40
|
+
[package]: https://www.npmjs.com/package/@lingui/format-csv
|
|
41
|
+
[badge-downloads]: https://img.shields.io/npm/dw/@lingui/format-csv.svg
|
|
42
|
+
[badge-version]: https://img.shields.io/npm/v/@lingui/format-csv.svg
|
|
43
|
+
[badge-license]: https://img.shields.io/npm/l/@lingui/format-csv.svg
|
package/dist/csv.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Papa = require('papaparse');
|
|
4
|
+
|
|
5
|
+
const serialize = (catalog) => {
|
|
6
|
+
const rawArr = Object.keys(catalog).map((key) => [
|
|
7
|
+
key,
|
|
8
|
+
catalog[key].translation
|
|
9
|
+
]);
|
|
10
|
+
return Papa.unparse(rawArr);
|
|
11
|
+
};
|
|
12
|
+
const deserialize = (raw) => {
|
|
13
|
+
const rawCatalog = Papa.parse(raw);
|
|
14
|
+
const messages = {};
|
|
15
|
+
if (rawCatalog.errors.length) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
rawCatalog.errors.map((err) => JSON.stringify(err)).join(";")
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
rawCatalog.data.forEach(([key, translation]) => {
|
|
21
|
+
messages[key] = {
|
|
22
|
+
translation,
|
|
23
|
+
obsolete: false,
|
|
24
|
+
message: null,
|
|
25
|
+
origin: []
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
return messages;
|
|
29
|
+
};
|
|
30
|
+
function formatter() {
|
|
31
|
+
return {
|
|
32
|
+
catalogExtension: ".csv",
|
|
33
|
+
parse(content) {
|
|
34
|
+
return deserialize(content);
|
|
35
|
+
},
|
|
36
|
+
serialize(catalog) {
|
|
37
|
+
return serialize(catalog);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.formatter = formatter;
|
package/dist/csv.d.ts
ADDED
package/dist/csv.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Papa from 'papaparse';
|
|
2
|
+
|
|
3
|
+
const serialize = (catalog) => {
|
|
4
|
+
const rawArr = Object.keys(catalog).map((key) => [
|
|
5
|
+
key,
|
|
6
|
+
catalog[key].translation
|
|
7
|
+
]);
|
|
8
|
+
return Papa.unparse(rawArr);
|
|
9
|
+
};
|
|
10
|
+
const deserialize = (raw) => {
|
|
11
|
+
const rawCatalog = Papa.parse(raw);
|
|
12
|
+
const messages = {};
|
|
13
|
+
if (rawCatalog.errors.length) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
rawCatalog.errors.map((err) => JSON.stringify(err)).join(";")
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
rawCatalog.data.forEach(([key, translation]) => {
|
|
19
|
+
messages[key] = {
|
|
20
|
+
translation,
|
|
21
|
+
obsolete: false,
|
|
22
|
+
message: null,
|
|
23
|
+
origin: []
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return messages;
|
|
27
|
+
};
|
|
28
|
+
function formatter() {
|
|
29
|
+
return {
|
|
30
|
+
catalogExtension: ".csv",
|
|
31
|
+
parse(content) {
|
|
32
|
+
return deserialize(content);
|
|
33
|
+
},
|
|
34
|
+
serialize(catalog) {
|
|
35
|
+
return serialize(catalog);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { formatter };
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lingui/format-csv",
|
|
3
|
+
"version": "4.0.0-next.2",
|
|
4
|
+
"description": "CSV format for Lingui Catalogs",
|
|
5
|
+
"main": "./dist/csv.cjs",
|
|
6
|
+
"module": "./dist/csv.mjs",
|
|
7
|
+
"types": "./dist/csv.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"i18n",
|
|
11
|
+
"lingui-format",
|
|
12
|
+
"lingui-formatter",
|
|
13
|
+
"csv",
|
|
14
|
+
"internationalization",
|
|
15
|
+
"i10n",
|
|
16
|
+
"localization",
|
|
17
|
+
"i9n",
|
|
18
|
+
"translation"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rimraf ./dist && unbuild",
|
|
22
|
+
"stub": "unbuild --stub"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/lingui/js-lingui.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/lingui/js-lingui/issues"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=16.0.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"LICENSE",
|
|
36
|
+
"README.md",
|
|
37
|
+
"dist/"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@lingui/conf": "4.0.0-next.2",
|
|
41
|
+
"papaparse": "^5.4.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"unbuild": "^1.1.2"
|
|
45
|
+
}
|
|
46
|
+
}
|