@l10nmonster/helpers-json 3.0.0-alpha.1 → 3.0.0-alpha.10
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/.releaserc.json +31 -0
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/i18next.js +22 -7
- package/package.json +5 -2
package/.releaserc.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branches": [
|
|
3
|
+
"main",
|
|
4
|
+
{
|
|
5
|
+
"name": "next",
|
|
6
|
+
"prerelease": "alpha"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"name": "beta",
|
|
10
|
+
"prerelease": "beta"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"tagFormat": "@l10nmonster/helpers-json@${version}",
|
|
14
|
+
"plugins": [
|
|
15
|
+
"@semantic-release/commit-analyzer",
|
|
16
|
+
"@semantic-release/release-notes-generator",
|
|
17
|
+
{
|
|
18
|
+
"path": "@semantic-release/changelog",
|
|
19
|
+
"changelogFile": "CHANGELOG.md"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"path": "@semantic-release/npm",
|
|
23
|
+
"npmPublish": true
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "@semantic-release/git",
|
|
27
|
+
"assets": ["CHANGELOG.md", "package.json"],
|
|
28
|
+
"message": "chore(release): @l10nmonster/helpers-json@${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
package/i18next.js
CHANGED
|
@@ -6,9 +6,9 @@ import { flatten, unflatten } from 'flat';
|
|
|
6
6
|
import { regex } from '@l10nmonster/core';
|
|
7
7
|
import { flattenAndSplitResources, ARB_ANNOTATION_MARKER, arbPlaceholderHandler } from './utils.js';
|
|
8
8
|
|
|
9
|
-
const isArbAnnotations = e => e[0].split('.').
|
|
9
|
+
const isArbAnnotations = e => e[0].split('.').some(segment => segment.startsWith(ARB_ANNOTATION_MARKER));
|
|
10
10
|
const validPluralSuffixes = new Set(['one', 'other', 'zero', 'two', 'few', 'many']);
|
|
11
|
-
const extractArbGroupsRegex = /(?<prefix>.+?\.)?@(?<key
|
|
11
|
+
const extractArbGroupsRegex = /(?<prefix>.+?\.)?@(?<key>[^.]+)\.(?<attribute>.+)/;
|
|
12
12
|
const defaultArbAnnotationHandlers = {
|
|
13
13
|
description: (_, data) => (data == null ? undefined : data),
|
|
14
14
|
placeholders: (_, data) => (data == null ? undefined : arbPlaceholderHandler(data)),
|
|
@@ -117,7 +117,7 @@ export class I18nextFilter {
|
|
|
117
117
|
for (const entry of Object.entries(flatResource)) {
|
|
118
118
|
if (!this.enableArbAnnotations || !isArbAnnotations(entry)) {
|
|
119
119
|
const translation = await translator(...entry);
|
|
120
|
-
if (translation ===
|
|
120
|
+
if (translation === null) {
|
|
121
121
|
delete flatResource[entry[0]];
|
|
122
122
|
} else {
|
|
123
123
|
flatResource[entry[0]] = translation;
|
|
@@ -127,10 +127,25 @@ export class I18nextFilter {
|
|
|
127
127
|
}
|
|
128
128
|
if (this.enableArbAnnotations) {
|
|
129
129
|
for (const entry of Object.entries(flatResource).filter(entry => isArbAnnotations(entry))) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
if
|
|
133
|
-
|
|
130
|
+
const [key, value] = entry;
|
|
131
|
+
|
|
132
|
+
// Always delete if not emitting annotations
|
|
133
|
+
if (!this.emitArbAnnotations) {
|
|
134
|
+
delete flatResource[key];
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Only keep if regex matches and corresponding translation exists and is not null
|
|
139
|
+
const match = extractArbGroupsRegex.exec(key);
|
|
140
|
+
if (match?.groups) {
|
|
141
|
+
const { prefix = '', key: arbKey, attribute } = match.groups;
|
|
142
|
+
const sid = `${prefix}${arbKey}`;
|
|
143
|
+
if (!Object.prototype.hasOwnProperty.call(flatResource, sid) || flatResource[sid] == null) {
|
|
144
|
+
delete flatResource[key];
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
// No regex match, can't determine corresponding translation, so delete
|
|
148
|
+
delete flatResource[key];
|
|
134
149
|
}
|
|
135
150
|
}
|
|
136
151
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@l10nmonster/helpers-json",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.10",
|
|
4
4
|
"description": "Helpers to deal with JSON file formats",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"flat": "^6"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@l10nmonster/core": "
|
|
16
|
+
"@l10nmonster/core": "^3.0.0-alpha.0"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.11.0"
|
|
17
20
|
}
|
|
18
21
|
}
|