i18next-cli 1.56.5 → 1.56.6

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/cjs/cli.js CHANGED
@@ -32,7 +32,7 @@ const program = new commander.Command();
32
32
  program
33
33
  .name('i18next-cli')
34
34
  .description('A unified, high-performance i18next CLI.')
35
- .version('1.56.5'); // This string is replaced with the actual version at build time by rollup
35
+ .version('1.56.6'); // This string is replaced with the actual version at build time by rollup
36
36
  // new: global config override option
37
37
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
38
38
  program
@@ -224,6 +224,11 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
224
224
  const cardinalCategories = cardinalRules.resolvedOptions().pluralCategories;
225
225
  cardinalCategories.forEach(cat => targetLanguagePluralCategories.add(cat));
226
226
  ordinalRules.resolvedOptions().pluralCategories.forEach(cat => targetLanguagePluralCategories.add(`ordinal_${cat}`));
227
+ // Plural categories of the primary language — used to recognise locale-specific
228
+ // plural variants (e.g. French `_many` when primary is English) so we don't
229
+ // treat their absence from the primary file as a "divergence" during --sync-all.
230
+ const primaryCardinalCategoriesSet = new Set(pluralRules.safePluralRules(primaryLanguage, { type: 'cardinal' }).resolvedOptions().pluralCategories);
231
+ const primaryOrdinalCategoriesSet = new Set(pluralRules.safePluralRules(primaryLanguage, { type: 'ordinal' }).resolvedOptions().pluralCategories);
227
232
  // When allPluralForms is enabled, compute the union of cardinal categories across all configured locales.
228
233
  // This ensures every locale gets the same set of plural keys — but only the forms actually needed by at least one locale.
229
234
  const allLocalesCardinalCategories = config.extract.allPluralForms
@@ -762,8 +767,26 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
762
767
  else {
763
768
  // Non-primary locale behavior
764
769
  const isVariantKey = key.includes(pluralSeparator) || key.includes(contextSeparator);
770
+ // A plural variant whose category exists in the current locale but not in the
771
+ // primary language (e.g. French `_many` vs English `one`/`other`) will always be
772
+ // absent from the primary file by CLDR design. Treat that absence as expected —
773
+ // not as the primary "diverging" from the default — so --sync-all preserves the
774
+ // locale-specific translation instead of clearing it on every run. (issue #248)
775
+ const isLocaleSpecificPluralVariant = (() => {
776
+ if (!hasCount)
777
+ return false;
778
+ const parts = String(key).split(pluralSeparator);
779
+ if (parts.length < 2)
780
+ return false;
781
+ const lastPart = parts[parts.length - 1];
782
+ if (isOrdinal && parts.length >= 3 && parts[parts.length - 2] === 'ordinal') {
783
+ return !primaryOrdinalCategoriesSet.has(lastPart);
784
+ }
785
+ return !primaryCardinalCategoriesSet.has(lastPart);
786
+ })();
765
787
  const primaryDivergedFromDefault = Boolean(defaultValue$1 &&
766
788
  !primaryShouldPreserveObject &&
789
+ !isLocaleSpecificPluralVariant &&
767
790
  (primaryExistingValue === undefined ||
768
791
  primaryIsStaleObject ||
769
792
  ((!isVariantKey || explicitDefault) &&
package/dist/esm/cli.js CHANGED
@@ -30,7 +30,7 @@ const program = new Command();
30
30
  program
31
31
  .name('i18next-cli')
32
32
  .description('A unified, high-performance i18next CLI.')
33
- .version('1.56.5'); // This string is replaced with the actual version at build time by rollup
33
+ .version('1.56.6'); // This string is replaced with the actual version at build time by rollup
34
34
  // new: global config override option
35
35
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
36
36
  program
@@ -222,6 +222,11 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
222
222
  const cardinalCategories = cardinalRules.resolvedOptions().pluralCategories;
223
223
  cardinalCategories.forEach(cat => targetLanguagePluralCategories.add(cat));
224
224
  ordinalRules.resolvedOptions().pluralCategories.forEach(cat => targetLanguagePluralCategories.add(`ordinal_${cat}`));
225
+ // Plural categories of the primary language — used to recognise locale-specific
226
+ // plural variants (e.g. French `_many` when primary is English) so we don't
227
+ // treat their absence from the primary file as a "divergence" during --sync-all.
228
+ const primaryCardinalCategoriesSet = new Set(safePluralRules(primaryLanguage, { type: 'cardinal' }).resolvedOptions().pluralCategories);
229
+ const primaryOrdinalCategoriesSet = new Set(safePluralRules(primaryLanguage, { type: 'ordinal' }).resolvedOptions().pluralCategories);
225
230
  // When allPluralForms is enabled, compute the union of cardinal categories across all configured locales.
226
231
  // This ensures every locale gets the same set of plural keys — but only the forms actually needed by at least one locale.
227
232
  const allLocalesCardinalCategories = config.extract.allPluralForms
@@ -760,8 +765,26 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
760
765
  else {
761
766
  // Non-primary locale behavior
762
767
  const isVariantKey = key.includes(pluralSeparator) || key.includes(contextSeparator);
768
+ // A plural variant whose category exists in the current locale but not in the
769
+ // primary language (e.g. French `_many` vs English `one`/`other`) will always be
770
+ // absent from the primary file by CLDR design. Treat that absence as expected —
771
+ // not as the primary "diverging" from the default — so --sync-all preserves the
772
+ // locale-specific translation instead of clearing it on every run. (issue #248)
773
+ const isLocaleSpecificPluralVariant = (() => {
774
+ if (!hasCount)
775
+ return false;
776
+ const parts = String(key).split(pluralSeparator);
777
+ if (parts.length < 2)
778
+ return false;
779
+ const lastPart = parts[parts.length - 1];
780
+ if (isOrdinal && parts.length >= 3 && parts[parts.length - 2] === 'ordinal') {
781
+ return !primaryOrdinalCategoriesSet.has(lastPart);
782
+ }
783
+ return !primaryCardinalCategoriesSet.has(lastPart);
784
+ })();
763
785
  const primaryDivergedFromDefault = Boolean(defaultValue &&
764
786
  !primaryShouldPreserveObject &&
787
+ !isLocaleSpecificPluralVariant &&
765
788
  (primaryExistingValue === undefined ||
766
789
  primaryIsStaleObject ||
767
790
  ((!isVariantKey || explicitDefault) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.56.5",
3
+ "version": "1.56.6",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAohC9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,EAC5B,EACE,uBAA+B,EAC/B,OAAe,EACf,oBAA4B,EAC5B,MAA4B,EAC7B,GAAE;IACD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;CACX,GACL,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAiK9B"}
1
+ {"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AA8iC9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,EAC5B,EACE,uBAA+B,EAC/B,OAAe,EACf,oBAA4B,EAC5B,MAA4B,EAC7B,GAAE;IACD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;CACX,GACL,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAiK9B"}