@lingui/format-po 4.1.1 → 4.2.0
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 +15 -0
- package/dist/po.cjs +13 -5
- package/dist/po.d.ts +14 -0
- package/dist/po.mjs +13 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -61,6 +61,21 @@ export type PoFormatterOptions = {
|
|
|
61
61
|
* @default false
|
|
62
62
|
*/
|
|
63
63
|
printLinguiId?: boolean
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* By default, the po-formatter treats the pair `msgid` + `msgctx` as the source
|
|
67
|
+
* for generating an ID by hashing its value.
|
|
68
|
+
*
|
|
69
|
+
* For messages with explicit IDs, the formatter adds a special comment `js-lingui-explicit-id` as a flag.
|
|
70
|
+
* When this flag is present, the formatter will use the `msgid` as-is without any additional processing.
|
|
71
|
+
*
|
|
72
|
+
* Set this option to true if you exclusively use explicit-ids in your project.
|
|
73
|
+
*
|
|
74
|
+
* https://lingui.dev/tutorials/react-patterns#using-custom-id
|
|
75
|
+
*
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
explicitIdAsDefault?: boolean
|
|
64
79
|
}
|
|
65
80
|
```
|
|
66
81
|
|
package/dist/po.cjs
CHANGED
|
@@ -23,6 +23,7 @@ function getCreateHeaders(language) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
|
|
26
|
+
const GENERATED_ID_FLAG = "js-lingui-generated-id";
|
|
26
27
|
const serialize = (catalog, options) => {
|
|
27
28
|
return Object.keys(catalog).map((id) => {
|
|
28
29
|
const message = catalog[id];
|
|
@@ -35,14 +36,21 @@ const serialize = (catalog, options) => {
|
|
|
35
36
|
const _isGeneratedId = isGeneratedId(id, message);
|
|
36
37
|
if (_isGeneratedId) {
|
|
37
38
|
item.msgid = message.message;
|
|
39
|
+
if (options.explicitIdAsDefault) {
|
|
40
|
+
if (!item.extractedComments.includes(GENERATED_ID_FLAG)) {
|
|
41
|
+
item.extractedComments.push(GENERATED_ID_FLAG);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
38
44
|
if (options.printLinguiId) {
|
|
39
45
|
if (!item.extractedComments.find((c) => c.includes("js-lingui-id"))) {
|
|
40
46
|
item.extractedComments.push(`js-lingui-id: ${id}`);
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
} else {
|
|
44
|
-
if (!
|
|
45
|
-
item.extractedComments.
|
|
50
|
+
if (!options.explicitIdAsDefault) {
|
|
51
|
+
if (!item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
|
|
52
|
+
item.extractedComments.push(EXPLICIT_ID_FLAG);
|
|
53
|
+
}
|
|
46
54
|
}
|
|
47
55
|
item.msgid = id;
|
|
48
56
|
}
|
|
@@ -62,7 +70,7 @@ const serialize = (catalog, options) => {
|
|
|
62
70
|
return item;
|
|
63
71
|
});
|
|
64
72
|
};
|
|
65
|
-
function deserialize(items) {
|
|
73
|
+
function deserialize(items, options) {
|
|
66
74
|
return items.reduce((catalog, item) => {
|
|
67
75
|
const message = {
|
|
68
76
|
translation: item.msgstr[0],
|
|
@@ -76,7 +84,7 @@ function deserialize(items) {
|
|
|
76
84
|
}
|
|
77
85
|
};
|
|
78
86
|
let id = item.msgid;
|
|
79
|
-
if (!item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
|
|
87
|
+
if (options.explicitIdAsDefault ? item.extractedComments.includes(GENERATED_ID_FLAG) : !item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
|
|
80
88
|
id = generateMessageId.generateMessageId(item.msgid, item.msgctxt);
|
|
81
89
|
message.message = item.msgid;
|
|
82
90
|
}
|
|
@@ -95,7 +103,7 @@ function formatter(options = {}) {
|
|
|
95
103
|
templateExtension: ".pot",
|
|
96
104
|
parse(content) {
|
|
97
105
|
const po = PO.parse(content);
|
|
98
|
-
return deserialize(po.items);
|
|
106
|
+
return deserialize(po.items, options);
|
|
99
107
|
},
|
|
100
108
|
serialize(catalog, ctx) {
|
|
101
109
|
let po;
|
package/dist/po.d.ts
CHANGED
|
@@ -19,6 +19,20 @@ type PoFormatterOptions = {
|
|
|
19
19
|
* @default false
|
|
20
20
|
*/
|
|
21
21
|
printLinguiId?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* By default, the po-formatter treats the pair `msgid` + `msgctx` as the source
|
|
24
|
+
* for generating an ID by hashing its value.
|
|
25
|
+
*
|
|
26
|
+
* For messages with explicit IDs, the formatter adds a special comment `js-lingui-explicit-id` as a flag.
|
|
27
|
+
* When this flag is present, the formatter will use the `msgid` as-is without any additional processing.
|
|
28
|
+
*
|
|
29
|
+
* Set this option to true if you exclusively use explicit-ids in your project.
|
|
30
|
+
*
|
|
31
|
+
* https://lingui.dev/tutorials/react-patterns#using-custom-id
|
|
32
|
+
*
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
explicitIdAsDefault?: boolean;
|
|
22
36
|
};
|
|
23
37
|
declare function formatter(options?: PoFormatterOptions): CatalogFormatter;
|
|
24
38
|
|
package/dist/po.mjs
CHANGED
|
@@ -21,6 +21,7 @@ function getCreateHeaders(language) {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
|
|
24
|
+
const GENERATED_ID_FLAG = "js-lingui-generated-id";
|
|
24
25
|
const serialize = (catalog, options) => {
|
|
25
26
|
return Object.keys(catalog).map((id) => {
|
|
26
27
|
const message = catalog[id];
|
|
@@ -33,14 +34,21 @@ const serialize = (catalog, options) => {
|
|
|
33
34
|
const _isGeneratedId = isGeneratedId(id, message);
|
|
34
35
|
if (_isGeneratedId) {
|
|
35
36
|
item.msgid = message.message;
|
|
37
|
+
if (options.explicitIdAsDefault) {
|
|
38
|
+
if (!item.extractedComments.includes(GENERATED_ID_FLAG)) {
|
|
39
|
+
item.extractedComments.push(GENERATED_ID_FLAG);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
36
42
|
if (options.printLinguiId) {
|
|
37
43
|
if (!item.extractedComments.find((c) => c.includes("js-lingui-id"))) {
|
|
38
44
|
item.extractedComments.push(`js-lingui-id: ${id}`);
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
} else {
|
|
42
|
-
if (!
|
|
43
|
-
item.extractedComments.
|
|
48
|
+
if (!options.explicitIdAsDefault) {
|
|
49
|
+
if (!item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
|
|
50
|
+
item.extractedComments.push(EXPLICIT_ID_FLAG);
|
|
51
|
+
}
|
|
44
52
|
}
|
|
45
53
|
item.msgid = id;
|
|
46
54
|
}
|
|
@@ -60,7 +68,7 @@ const serialize = (catalog, options) => {
|
|
|
60
68
|
return item;
|
|
61
69
|
});
|
|
62
70
|
};
|
|
63
|
-
function deserialize(items) {
|
|
71
|
+
function deserialize(items, options) {
|
|
64
72
|
return items.reduce((catalog, item) => {
|
|
65
73
|
const message = {
|
|
66
74
|
translation: item.msgstr[0],
|
|
@@ -74,7 +82,7 @@ function deserialize(items) {
|
|
|
74
82
|
}
|
|
75
83
|
};
|
|
76
84
|
let id = item.msgid;
|
|
77
|
-
if (!item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
|
|
85
|
+
if (options.explicitIdAsDefault ? item.extractedComments.includes(GENERATED_ID_FLAG) : !item.extractedComments.includes(EXPLICIT_ID_FLAG)) {
|
|
78
86
|
id = generateMessageId(item.msgid, item.msgctxt);
|
|
79
87
|
message.message = item.msgid;
|
|
80
88
|
}
|
|
@@ -93,7 +101,7 @@ function formatter(options = {}) {
|
|
|
93
101
|
templateExtension: ".pot",
|
|
94
102
|
parse(content) {
|
|
95
103
|
const po = PO.parse(content);
|
|
96
|
-
return deserialize(po.items);
|
|
104
|
+
return deserialize(po.items, options);
|
|
97
105
|
},
|
|
98
106
|
serialize(catalog, ctx) {
|
|
99
107
|
let po;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/format-po",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Gettext PO format for Lingui Catalogs",
|
|
5
5
|
"main": "./dist/po.cjs",
|
|
6
6
|
"module": "./dist/po.mjs",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"dist/"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@lingui/conf": "4.
|
|
45
|
-
"@lingui/message-utils": "4.
|
|
44
|
+
"@lingui/conf": "4.2.0",
|
|
45
|
+
"@lingui/message-utils": "4.2.0",
|
|
46
46
|
"date-fns": "^2.29.3",
|
|
47
47
|
"pofile": "^1.1.4"
|
|
48
48
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"tsd": "^0.28.0",
|
|
53
53
|
"unbuild": "^1.1.2"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "57aa5ce306558d0a9d29a14dd40ffa31e5d591bd"
|
|
56
56
|
}
|