@lingual/i18n-check 0.5.1 → 0.5.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.
Files changed (2) hide show
  1. package/dist/index.js +25 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19,7 +19,6 @@ const findInvalidi18nTranslations_1 = require("./utils/findInvalidi18nTranslatio
19
19
  const glob_1 = require("glob");
20
20
  const cli_lib_1 = require("@formatjs/cli-lib");
21
21
  const fs_1 = __importDefault(require("fs"));
22
- const vinyl_1 = __importDefault(require("vinyl"));
23
22
  const checkInvalidTranslations = (source, targets, options = { format: "icu" }) => {
24
23
  return options.format === "i18next"
25
24
  ? (0, findInvalidi18nTranslations_1.findInvalid18nTranslations)(source, targets)
@@ -95,31 +94,32 @@ const findUnusedI18NextTranslations = (source_1, codebaseSrc_1, ...args_1) => __
95
94
  let extractedResult = [];
96
95
  // @ts-ignore
97
96
  const { transform } = yield import("i18next-parser");
97
+ const i18nextParser = new transform({
98
+ lexers: {
99
+ jsx: [
100
+ {
101
+ lexer: "JsxLexer",
102
+ componentFunctions: componentFunctions.concat(["Trans"]),
103
+ },
104
+ ],
105
+ tsx: [
106
+ {
107
+ lexer: "JsxLexer",
108
+ componentFunctions: componentFunctions.concat(["Trans"]),
109
+ },
110
+ ],
111
+ },
112
+ });
98
113
  unusedKeysFiles.forEach((file) => {
99
- const rawContent = fs_1.default.readFileSync(file);
100
- const i18nextParser = new transform({
101
- lexers: {
102
- jsx: [
103
- {
104
- lexer: "JsxLexer",
105
- componentFunctions: componentFunctions.concat(["Trans"]),
106
- },
107
- ],
108
- tsx: [
109
- {
110
- lexer: "JsxLexer",
111
- componentFunctions: componentFunctions.concat(["Trans"]),
112
- },
113
- ],
114
- },
115
- });
116
- i18nextParser.once("data", (file) => {
117
- extractedResult = extractedResult.concat(Object.keys(flatten(JSON.parse(file.contents))));
118
- });
119
- i18nextParser.end(new vinyl_1.default({
120
- contents: rawContent,
121
- path: file,
122
- }));
114
+ const rawContent = fs_1.default.readFileSync(file, "utf-8");
115
+ const entries = i18nextParser.parser.parse(rawContent, file);
116
+ // Intermediate solution to retrieve all keys from the parser.
117
+ // This will be built out to also include the namespace and check
118
+ // the key against the namespace corresponding file.
119
+ // The current implementation considers the key as used no matter the namespace.
120
+ for (const entry of entries) {
121
+ extractedResult.push(entry.key);
122
+ }
123
123
  });
124
124
  const extractedResultSet = new Set(extractedResult);
125
125
  source.forEach(({ name, content }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingual/i18n-check",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "i18n translation messages check",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",