@lingual/i18n-check 0.9.2 → 0.9.3

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/dist/index.js CHANGED
@@ -14,6 +14,7 @@ const fs_1 = __importDefault(require("fs"));
14
14
  const path_1 = __importDefault(require("path"));
15
15
  const constants_1 = require("./utils/constants");
16
16
  const ParseFormats = ['react-intl', 'i18next', 'next-intl'];
17
+ const CONTEXT_SEPARATOR = '_';
17
18
  const checkInvalidTranslations = (source, targets, options = { format: 'icu' }) => {
18
19
  return options.format === 'i18next'
19
20
  ? (0, findInvalidI18NextTranslations_1.findInvalidI18NextTranslations)(source, targets)
@@ -219,7 +220,7 @@ const findUndefinedI18NextKeys = async (source, filesToParse, options = {
219
220
  .flatMap(({ content }) => {
220
221
  return Object.keys(content);
221
222
  })
222
- // Ensure that any plural definitiions like key_one, key_other etc.
223
+ // Ensure that any plural definitions like key_one, key_other etc.
223
224
  // are flatted into a single key
224
225
  .map((key) => {
225
226
  const pluralSuffix = constants_1.I18NEXT_PLURAL_SUFFIX.find((suffix) => {
@@ -302,7 +303,9 @@ const getI18NextKeysInCode = async (filesToParse, componentFunctions = []) => {
302
303
  else {
303
304
  extractedResult.push({
304
305
  file,
305
- key: entry.key,
306
+ key: entry.context
307
+ ? `${entry.key}${CONTEXT_SEPARATOR}${entry.context}`
308
+ : entry.key,
306
309
  namespace: entry.namespace,
307
310
  });
308
311
  }
@@ -347,6 +347,33 @@ const extractFromExpression = (node, options) => {
347
347
  }
348
348
  entries[0].key = concatenatedString;
349
349
  }
350
+ else if (ts.isFunctionExpression(keyArgument) ||
351
+ ts.isFunctionDeclaration(keyArgument) ||
352
+ ts.isArrowFunction(keyArgument)) {
353
+ // Try to find selector api definitions: ($) => $.a.b.c
354
+ if (!keyArgument.body) {
355
+ return null;
356
+ }
357
+ // Check if the function contains a return statement
358
+ if (ts.isBlock(keyArgument.body)) {
359
+ const returnStatement = keyArgument.body.statements.find((statement) => ts.isReturnStatement(statement));
360
+ if (returnStatement &&
361
+ returnStatement.expression &&
362
+ ts.isPropertyAccessExpression(returnStatement.expression)) {
363
+ const [_, ...keys] = returnStatement.expression
364
+ .getFullText()
365
+ .split('.');
366
+ entries[0].key = keys.join('.');
367
+ }
368
+ else {
369
+ return null;
370
+ }
371
+ }
372
+ else {
373
+ const [_, ...keys] = keyArgument.body.getFullText().split('.');
374
+ entries[0].key = keys.join('.');
375
+ }
376
+ }
350
377
  else {
351
378
  return null;
352
379
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingual/i18n-check",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "i18n translation messages check",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "@formatjs/icu-messageformat-parser": "^2.11.4",
29
29
  "chalk": "^4.1.2",
30
30
  "commander": "^12.1.0",
31
- "glob": "12.0.0",
31
+ "glob": "13.0.6",
32
32
  "js-yaml": "^4.1.1",
33
33
  "typescript": "^5.9.3"
34
34
  },
@@ -37,11 +37,11 @@
37
37
  "@types/js-yaml": "^4.0.9",
38
38
  "@types/node": "^22.19.1",
39
39
  "braces": "^3.0.3",
40
- "eslint": "^9.39.1",
40
+ "eslint": "^10.0.3",
41
41
  "globals": "^16.5.0",
42
42
  "prettier": "^3.6.2",
43
- "typescript-eslint": "^8.47.0",
44
- "vitest": "^4.0.10"
43
+ "typescript-eslint": "^8.56.1",
44
+ "vitest": "^4.0.18"
45
45
  },
46
46
  "repository": {
47
47
  "type": "git",