@lingual/i18n-check 0.5.4 → 0.5.5

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.
@@ -64,10 +64,9 @@ const hasDiff = (a, b) => {
64
64
  if ((0, icu_messageformat_parser_1.isTagElement)(formatElementA) && (0, icu_messageformat_parser_1.isTagElement)(formatElementB)) {
65
65
  return (0, exports.hasDiff)(formatElementA.children, formatElementB.children);
66
66
  }
67
- if (((0, icu_messageformat_parser_1.isSelectElement)(formatElementA) && (0, icu_messageformat_parser_1.isSelectElement)(formatElementB)) ||
68
- ((0, icu_messageformat_parser_1.isPluralElement)(formatElementA) && (0, icu_messageformat_parser_1.isPluralElement)(formatElementB))) {
67
+ if (((0, icu_messageformat_parser_1.isSelectElement)(formatElementA) && (0, icu_messageformat_parser_1.isSelectElement)(formatElementB))) {
69
68
  const optionsA = Object.keys(formatElementA.options).sort();
70
- const optionsB = Object.keys(formatElementA.options).sort();
69
+ const optionsB = Object.keys(formatElementB.options).sort();
71
70
  if (optionsA.join("-") !== optionsB.join("-")) {
72
71
  return true;
73
72
  }
@@ -75,6 +74,19 @@ const hasDiff = (a, b) => {
75
74
  return (0, exports.hasDiff)(formatElementA.options[key].value, formatElementB.options[key].value);
76
75
  });
77
76
  }
77
+ if ((0, icu_messageformat_parser_1.isPluralElement)(formatElementA) && (0, icu_messageformat_parser_1.isPluralElement)(formatElementB)) {
78
+ const optionsA = Object.keys(formatElementA.options).sort();
79
+ return optionsA.some((key) => {
80
+ // We can only compare translations that have the same plural keys.
81
+ // In English, we might have "one", "other", but in German, we might have "one", "few", "other".
82
+ // Or, in Arabic it might just be "other".
83
+ // So, we'll have to skip over the ones that don't have a one-to-one match.
84
+ if (!formatElementB.options[key]) {
85
+ return false;
86
+ }
87
+ return (0, exports.hasDiff)(formatElementA.options[key].value, formatElementB.options[key].value);
88
+ });
89
+ }
78
90
  return false;
79
91
  });
80
92
  return hasErrors;
@@ -39,4 +39,18 @@ describe("findInvalidTranslations", () => {
39
39
  fr: ["message.text-format"],
40
40
  });
41
41
  });
42
+ it("should allow for different types of keys per locale", () => {
43
+ expect((0, findInvalidTranslations_1.findInvalidTranslations)(sourceFile, {
44
+ de: Object.assign(Object.assign({}, secondaryFile), { "message.plural": "{count, plural, other {# of {total} items}}" })
45
+ })).toEqual({
46
+ de: ["multipleVariables"]
47
+ });
48
+ });
49
+ it("should fail if a variable is changed in one of the translations", () => {
50
+ expect((0, findInvalidTranslations_1.findInvalidTranslations)(sourceFile, {
51
+ de: Object.assign(Object.assign({}, secondaryFile), { "message.plural": "{count, plural, other {# of {cargado} items}}" })
52
+ })).toEqual({
53
+ de: ["message.plural", "multipleVariables"]
54
+ });
55
+ });
42
56
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingual/i18n-check",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "i18n translation messages check",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",