i18next-cli 1.52.0 → 1.52.1
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
|
@@ -31,7 +31,7 @@ const program = new commander.Command();
|
|
|
31
31
|
program
|
|
32
32
|
.name('i18next-cli')
|
|
33
33
|
.description('A unified, high-performance i18next CLI.')
|
|
34
|
-
.version('1.52.
|
|
34
|
+
.version('1.52.1'); // This string is replaced with the actual version at build time by rollup
|
|
35
35
|
// new: global config override option
|
|
36
36
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
37
37
|
program
|
|
@@ -210,8 +210,9 @@ function sortObject(obj, config, customSort) {
|
|
|
210
210
|
* A helper function to build a new translation object for a single namespace.
|
|
211
211
|
* This centralizes the core logic of merging keys.
|
|
212
212
|
*/
|
|
213
|
-
function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, namespace, preservePatterns = [], objectKeys = new Set(), syncPrimaryWithDefaults = false, syncAll = false, trustDerivedDefaults = false, logger$1 = new logger.ConsoleLogger()) {
|
|
214
|
-
const { keySeparator = '.', sort = true, removeUnusedKeys = true,
|
|
213
|
+
function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, namespace, preservePatterns = [], objectKeys = new Set(), syncPrimaryWithDefaults = false, syncAll = false, trustDerivedDefaults = false, primaryExistingTranslations = {}, logger$1 = new logger.ConsoleLogger()) {
|
|
214
|
+
const { keySeparator = '.', sort = true, removeUnusedKeys = true, defaultValue: emptyDefaultValue = '', pluralSeparator = '_', contextSeparator = '_', preserveContextVariants = false, } = config.extract;
|
|
215
|
+
const primaryLanguage = config.extract.primaryLanguage || config.locales[0] || 'en';
|
|
215
216
|
const nsSep = typeof config.extract.nsSeparator === 'string' ? config.extract.nsSeparator : ':';
|
|
216
217
|
// Keep the raw configured defaultValue so we can distinguish:
|
|
217
218
|
// - "not provided" (undefined) vs
|
|
@@ -621,17 +622,24 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
621
622
|
}
|
|
622
623
|
}
|
|
623
624
|
const existingValue = nestedObject.getNestedValue(existingTranslations, key, separator);
|
|
625
|
+
const primaryExistingValue = locale === primaryLanguage
|
|
626
|
+
? existingValue
|
|
627
|
+
: nestedObject.getNestedValue(primaryExistingTranslations, key, separator);
|
|
624
628
|
// When keySeparator === false we are working with flat keys (no nesting).
|
|
625
629
|
// Avoid concatenating false into strings (``${key}${false}`` => "keyfalse") which breaks the startsWith check.
|
|
626
630
|
// For flat keys there cannot be nested children, so treat them as leaves.
|
|
627
631
|
const isLeafInNewKeys = keySeparator === false
|
|
628
632
|
? true
|
|
629
633
|
: !filteredKeys.some(otherKey => otherKey.key !== key && otherKey.key.startsWith(`${key}${keySeparator}`));
|
|
634
|
+
const isDerivedDefault = isDerivedFromKey(key, defaultValue$1, explicitDefault);
|
|
630
635
|
// Determine if we should preserve an existing object
|
|
631
636
|
const shouldPreserveObject = typeof existingValue === 'object' && existingValue !== null && (objectKeys.has(key) || // Explicit returnObjects
|
|
632
637
|
!defaultValue$1 || defaultValue$1 === key // No explicit default or default equals key
|
|
633
638
|
);
|
|
634
639
|
const isStaleObject = typeof existingValue === 'object' && existingValue !== null && isLeafInNewKeys && !objectKeys.has(key) && !shouldPreserveObject;
|
|
640
|
+
const primaryShouldPreserveObject = typeof primaryExistingValue === 'object' && primaryExistingValue !== null && (objectKeys.has(key) ||
|
|
641
|
+
!defaultValue$1 || defaultValue$1 === key);
|
|
642
|
+
const primaryIsStaleObject = typeof primaryExistingValue === 'object' && primaryExistingValue !== null && isLeafInNewKeys && !objectKeys.has(key) && !primaryShouldPreserveObject;
|
|
635
643
|
// Special handling for existing objects that should be preserved
|
|
636
644
|
if (shouldPreserveObject) {
|
|
637
645
|
nestedObject.setNestedValue(newTranslations, key, existingValue, separator);
|
|
@@ -641,8 +649,6 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
641
649
|
if (existingValue === undefined || isStaleObject) {
|
|
642
650
|
if (locale === primaryLanguage) {
|
|
643
651
|
if (syncPrimaryWithDefaults) {
|
|
644
|
-
// use the unified "derived" detector (includes keyPrefix suffixes).
|
|
645
|
-
const isDerivedDefault = isDerivedFromKey(key, defaultValue$1, explicitDefault);
|
|
646
652
|
valueToSet =
|
|
647
653
|
(defaultValue$1 && (!isDerivedDefault || trustDerivedDefaults))
|
|
648
654
|
? defaultValue$1
|
|
@@ -651,8 +657,7 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
651
657
|
else {
|
|
652
658
|
// If there's no real code-provided default (defaultValue is derived fallback),
|
|
653
659
|
// use the configured extract.defaultValue for PRIMARY language too.
|
|
654
|
-
|
|
655
|
-
if (derived && configuredDefaultValue !== undefined) {
|
|
660
|
+
if (isDerivedDefault && configuredDefaultValue !== undefined) {
|
|
656
661
|
valueToSet = defaultValue.resolveDefaultValue(configuredDefaultValue, key, namespace || config?.extract?.defaultNS || 'translation', locale, defaultValue$1);
|
|
657
662
|
}
|
|
658
663
|
else {
|
|
@@ -668,8 +673,6 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
668
673
|
else {
|
|
669
674
|
// Existing value exists - decide whether to preserve, sync primary, or clear other locales when requested
|
|
670
675
|
if (locale === primaryLanguage && syncPrimaryWithDefaults) {
|
|
671
|
-
// Reuse the same derived-default detection as the initial write path so reruns stay idempotent.
|
|
672
|
-
const isDerivedDefault = isDerivedFromKey(key, defaultValue$1, explicitDefault);
|
|
673
676
|
// If this key looks like a plural/context variant and the default
|
|
674
677
|
// wasn't explicitly provided in source code, preserve the existing value.
|
|
675
678
|
const isVariantKey = key.includes(pluralSeparator) || key.includes(contextSeparator);
|
|
@@ -685,7 +688,18 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
685
688
|
}
|
|
686
689
|
else {
|
|
687
690
|
// Non-primary locale behavior
|
|
688
|
-
const
|
|
691
|
+
const isVariantKey = key.includes(pluralSeparator) || key.includes(contextSeparator);
|
|
692
|
+
const syncDerivedDefault = Boolean(syncAll &&
|
|
693
|
+
locale !== primaryLanguage &&
|
|
694
|
+
syncPrimaryWithDefaults &&
|
|
695
|
+
trustDerivedDefaults &&
|
|
696
|
+
defaultValue$1 &&
|
|
697
|
+
isDerivedDefault &&
|
|
698
|
+
!primaryShouldPreserveObject &&
|
|
699
|
+
(primaryExistingValue === undefined ||
|
|
700
|
+
primaryIsStaleObject ||
|
|
701
|
+
((!isVariantKey || explicitDefault) &&
|
|
702
|
+
primaryExistingValue !== defaultValue.resolveDefaultValue(defaultValue$1, key, namespace || config?.extract?.defaultNS || 'translation', primaryLanguage, defaultValue$1))));
|
|
689
703
|
if (syncAll && locale !== primaryLanguage && (explicitDefault || syncDerivedDefault)) {
|
|
690
704
|
// When syncAll is requested, clear (reset) any existing translations for keys
|
|
691
705
|
// that had explicit defaults in code so the primary default can be propagated
|
|
@@ -841,7 +855,8 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
841
855
|
*/
|
|
842
856
|
async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaults = false, syncAll = false, trustDerivedDefaults = false, logger: logger$1 = new logger.ConsoleLogger() } = {}) {
|
|
843
857
|
config.extract.primaryLanguage ||= config.locales[0] || 'en';
|
|
844
|
-
config.extract.
|
|
858
|
+
const primaryLanguage = config.extract.primaryLanguage || config.locales[0] || 'en';
|
|
859
|
+
config.extract.secondaryLanguages ||= config.locales.filter((l) => l !== primaryLanguage);
|
|
845
860
|
const patternsToPreserve = [...(config.extract.preservePatterns || [])];
|
|
846
861
|
const indentation = config.extract.indentation ?? 2;
|
|
847
862
|
for (const key of objectKeys) {
|
|
@@ -885,6 +900,10 @@ async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaul
|
|
|
885
900
|
const outputPath = fileUtils.getOutputPath(config.extract.output, locale);
|
|
886
901
|
const fullPath = node_path.resolve(process.cwd(), outputPath);
|
|
887
902
|
const existingMergedFile = await fileUtils.loadTranslationFile(fullPath) || {};
|
|
903
|
+
const primaryMergedPath = node_path.resolve(process.cwd(), fileUtils.getOutputPath(config.extract.output, primaryLanguage));
|
|
904
|
+
const primaryMergedFile = locale === primaryLanguage
|
|
905
|
+
? existingMergedFile
|
|
906
|
+
: (await fileUtils.loadTranslationFile(primaryMergedPath) || {});
|
|
888
907
|
// Determine whether the existing merged file already uses namespace objects
|
|
889
908
|
// or is a flat mapping of translation keys -> values.
|
|
890
909
|
// If it's flat (values are primitives), we must NOT treat each translation key as a namespace.
|
|
@@ -920,12 +939,13 @@ async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaul
|
|
|
920
939
|
const nsKeys = keysByNS.get(nsKey) || [];
|
|
921
940
|
if (isTopLevel(nsKey)) {
|
|
922
941
|
// keys without namespace -> merged into top-level of the merged file
|
|
923
|
-
const built = buildNewTranslationsForNs(nsKeys, existingMergedFile, config, locale, undefined, preservePatterns, objectKeys, syncPrimaryWithDefaults, syncAll, trustDerivedDefaults, logger$1);
|
|
942
|
+
const built = buildNewTranslationsForNs(nsKeys, existingMergedFile, config, locale, undefined, preservePatterns, objectKeys, syncPrimaryWithDefaults, syncAll, trustDerivedDefaults, primaryMergedFile, logger$1);
|
|
924
943
|
Object.assign(newMergedTranslations, built);
|
|
925
944
|
}
|
|
926
945
|
else {
|
|
927
946
|
const existingTranslations = existingMergedFile[nsKey] || {};
|
|
928
|
-
|
|
947
|
+
const primaryExistingTranslations = primaryMergedFile[nsKey] || {};
|
|
948
|
+
newMergedTranslations[nsKey] = buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, nsKey, preservePatterns, objectKeys, syncPrimaryWithDefaults, syncAll, trustDerivedDefaults, primaryExistingTranslations, logger$1);
|
|
929
949
|
}
|
|
930
950
|
}
|
|
931
951
|
// Preserve ignored namespaces as-is from the existing merged file
|
|
@@ -963,7 +983,11 @@ async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaul
|
|
|
963
983
|
const outputPath = fileUtils.getOutputPath(config.extract.output, locale, ns);
|
|
964
984
|
const fullPath = node_path.resolve(process.cwd(), outputPath);
|
|
965
985
|
const existingTranslations = await fileUtils.loadTranslationFile(fullPath) || {};
|
|
966
|
-
const
|
|
986
|
+
const primaryOutputPath = node_path.resolve(process.cwd(), fileUtils.getOutputPath(config.extract.output, primaryLanguage, ns));
|
|
987
|
+
const primaryExistingTranslations = locale === primaryLanguage
|
|
988
|
+
? existingTranslations
|
|
989
|
+
: (await fileUtils.loadTranslationFile(primaryOutputPath) || {});
|
|
990
|
+
const newTranslations = buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, ns, preservePatterns, objectKeys, syncPrimaryWithDefaults, syncAll, trustDerivedDefaults, primaryExistingTranslations, logger$1);
|
|
967
991
|
const oldContent = JSON.stringify(existingTranslations, null, indentation);
|
|
968
992
|
const newContent = JSON.stringify(newTranslations, null, indentation);
|
|
969
993
|
// Push one result per namespace file
|
package/dist/esm/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ const program = new Command();
|
|
|
29
29
|
program
|
|
30
30
|
.name('i18next-cli')
|
|
31
31
|
.description('A unified, high-performance i18next CLI.')
|
|
32
|
-
.version('1.52.
|
|
32
|
+
.version('1.52.1'); // This string is replaced with the actual version at build time by rollup
|
|
33
33
|
// new: global config override option
|
|
34
34
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
35
35
|
program
|
|
@@ -208,8 +208,9 @@ function sortObject(obj, config, customSort) {
|
|
|
208
208
|
* A helper function to build a new translation object for a single namespace.
|
|
209
209
|
* This centralizes the core logic of merging keys.
|
|
210
210
|
*/
|
|
211
|
-
function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, namespace, preservePatterns = [], objectKeys = new Set(), syncPrimaryWithDefaults = false, syncAll = false, trustDerivedDefaults = false, logger = new ConsoleLogger()) {
|
|
212
|
-
const { keySeparator = '.', sort = true, removeUnusedKeys = true,
|
|
211
|
+
function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, namespace, preservePatterns = [], objectKeys = new Set(), syncPrimaryWithDefaults = false, syncAll = false, trustDerivedDefaults = false, primaryExistingTranslations = {}, logger = new ConsoleLogger()) {
|
|
212
|
+
const { keySeparator = '.', sort = true, removeUnusedKeys = true, defaultValue: emptyDefaultValue = '', pluralSeparator = '_', contextSeparator = '_', preserveContextVariants = false, } = config.extract;
|
|
213
|
+
const primaryLanguage = config.extract.primaryLanguage || config.locales[0] || 'en';
|
|
213
214
|
const nsSep = typeof config.extract.nsSeparator === 'string' ? config.extract.nsSeparator : ':';
|
|
214
215
|
// Keep the raw configured defaultValue so we can distinguish:
|
|
215
216
|
// - "not provided" (undefined) vs
|
|
@@ -619,17 +620,24 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
619
620
|
}
|
|
620
621
|
}
|
|
621
622
|
const existingValue = getNestedValue(existingTranslations, key, separator);
|
|
623
|
+
const primaryExistingValue = locale === primaryLanguage
|
|
624
|
+
? existingValue
|
|
625
|
+
: getNestedValue(primaryExistingTranslations, key, separator);
|
|
622
626
|
// When keySeparator === false we are working with flat keys (no nesting).
|
|
623
627
|
// Avoid concatenating false into strings (``${key}${false}`` => "keyfalse") which breaks the startsWith check.
|
|
624
628
|
// For flat keys there cannot be nested children, so treat them as leaves.
|
|
625
629
|
const isLeafInNewKeys = keySeparator === false
|
|
626
630
|
? true
|
|
627
631
|
: !filteredKeys.some(otherKey => otherKey.key !== key && otherKey.key.startsWith(`${key}${keySeparator}`));
|
|
632
|
+
const isDerivedDefault = isDerivedFromKey(key, defaultValue, explicitDefault);
|
|
628
633
|
// Determine if we should preserve an existing object
|
|
629
634
|
const shouldPreserveObject = typeof existingValue === 'object' && existingValue !== null && (objectKeys.has(key) || // Explicit returnObjects
|
|
630
635
|
!defaultValue || defaultValue === key // No explicit default or default equals key
|
|
631
636
|
);
|
|
632
637
|
const isStaleObject = typeof existingValue === 'object' && existingValue !== null && isLeafInNewKeys && !objectKeys.has(key) && !shouldPreserveObject;
|
|
638
|
+
const primaryShouldPreserveObject = typeof primaryExistingValue === 'object' && primaryExistingValue !== null && (objectKeys.has(key) ||
|
|
639
|
+
!defaultValue || defaultValue === key);
|
|
640
|
+
const primaryIsStaleObject = typeof primaryExistingValue === 'object' && primaryExistingValue !== null && isLeafInNewKeys && !objectKeys.has(key) && !primaryShouldPreserveObject;
|
|
633
641
|
// Special handling for existing objects that should be preserved
|
|
634
642
|
if (shouldPreserveObject) {
|
|
635
643
|
setNestedValue(newTranslations, key, existingValue, separator);
|
|
@@ -639,8 +647,6 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
639
647
|
if (existingValue === undefined || isStaleObject) {
|
|
640
648
|
if (locale === primaryLanguage) {
|
|
641
649
|
if (syncPrimaryWithDefaults) {
|
|
642
|
-
// use the unified "derived" detector (includes keyPrefix suffixes).
|
|
643
|
-
const isDerivedDefault = isDerivedFromKey(key, defaultValue, explicitDefault);
|
|
644
650
|
valueToSet =
|
|
645
651
|
(defaultValue && (!isDerivedDefault || trustDerivedDefaults))
|
|
646
652
|
? defaultValue
|
|
@@ -649,8 +655,7 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
649
655
|
else {
|
|
650
656
|
// If there's no real code-provided default (defaultValue is derived fallback),
|
|
651
657
|
// use the configured extract.defaultValue for PRIMARY language too.
|
|
652
|
-
|
|
653
|
-
if (derived && configuredDefaultValue !== undefined) {
|
|
658
|
+
if (isDerivedDefault && configuredDefaultValue !== undefined) {
|
|
654
659
|
valueToSet = resolveDefaultValue(configuredDefaultValue, key, namespace || config?.extract?.defaultNS || 'translation', locale, defaultValue);
|
|
655
660
|
}
|
|
656
661
|
else {
|
|
@@ -666,8 +671,6 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
666
671
|
else {
|
|
667
672
|
// Existing value exists - decide whether to preserve, sync primary, or clear other locales when requested
|
|
668
673
|
if (locale === primaryLanguage && syncPrimaryWithDefaults) {
|
|
669
|
-
// Reuse the same derived-default detection as the initial write path so reruns stay idempotent.
|
|
670
|
-
const isDerivedDefault = isDerivedFromKey(key, defaultValue, explicitDefault);
|
|
671
674
|
// If this key looks like a plural/context variant and the default
|
|
672
675
|
// wasn't explicitly provided in source code, preserve the existing value.
|
|
673
676
|
const isVariantKey = key.includes(pluralSeparator) || key.includes(contextSeparator);
|
|
@@ -683,7 +686,18 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
683
686
|
}
|
|
684
687
|
else {
|
|
685
688
|
// Non-primary locale behavior
|
|
686
|
-
const
|
|
689
|
+
const isVariantKey = key.includes(pluralSeparator) || key.includes(contextSeparator);
|
|
690
|
+
const syncDerivedDefault = Boolean(syncAll &&
|
|
691
|
+
locale !== primaryLanguage &&
|
|
692
|
+
syncPrimaryWithDefaults &&
|
|
693
|
+
trustDerivedDefaults &&
|
|
694
|
+
defaultValue &&
|
|
695
|
+
isDerivedDefault &&
|
|
696
|
+
!primaryShouldPreserveObject &&
|
|
697
|
+
(primaryExistingValue === undefined ||
|
|
698
|
+
primaryIsStaleObject ||
|
|
699
|
+
((!isVariantKey || explicitDefault) &&
|
|
700
|
+
primaryExistingValue !== resolveDefaultValue(defaultValue, key, namespace || config?.extract?.defaultNS || 'translation', primaryLanguage, defaultValue))));
|
|
687
701
|
if (syncAll && locale !== primaryLanguage && (explicitDefault || syncDerivedDefault)) {
|
|
688
702
|
// When syncAll is requested, clear (reset) any existing translations for keys
|
|
689
703
|
// that had explicit defaults in code so the primary default can be propagated
|
|
@@ -839,7 +853,8 @@ function buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale,
|
|
|
839
853
|
*/
|
|
840
854
|
async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaults = false, syncAll = false, trustDerivedDefaults = false, logger = new ConsoleLogger() } = {}) {
|
|
841
855
|
config.extract.primaryLanguage ||= config.locales[0] || 'en';
|
|
842
|
-
config.extract.
|
|
856
|
+
const primaryLanguage = config.extract.primaryLanguage || config.locales[0] || 'en';
|
|
857
|
+
config.extract.secondaryLanguages ||= config.locales.filter((l) => l !== primaryLanguage);
|
|
843
858
|
const patternsToPreserve = [...(config.extract.preservePatterns || [])];
|
|
844
859
|
const indentation = config.extract.indentation ?? 2;
|
|
845
860
|
for (const key of objectKeys) {
|
|
@@ -883,6 +898,10 @@ async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaul
|
|
|
883
898
|
const outputPath = getOutputPath(config.extract.output, locale);
|
|
884
899
|
const fullPath = resolve(process.cwd(), outputPath);
|
|
885
900
|
const existingMergedFile = await loadTranslationFile(fullPath) || {};
|
|
901
|
+
const primaryMergedPath = resolve(process.cwd(), getOutputPath(config.extract.output, primaryLanguage));
|
|
902
|
+
const primaryMergedFile = locale === primaryLanguage
|
|
903
|
+
? existingMergedFile
|
|
904
|
+
: (await loadTranslationFile(primaryMergedPath) || {});
|
|
886
905
|
// Determine whether the existing merged file already uses namespace objects
|
|
887
906
|
// or is a flat mapping of translation keys -> values.
|
|
888
907
|
// If it's flat (values are primitives), we must NOT treat each translation key as a namespace.
|
|
@@ -918,12 +937,13 @@ async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaul
|
|
|
918
937
|
const nsKeys = keysByNS.get(nsKey) || [];
|
|
919
938
|
if (isTopLevel(nsKey)) {
|
|
920
939
|
// keys without namespace -> merged into top-level of the merged file
|
|
921
|
-
const built = buildNewTranslationsForNs(nsKeys, existingMergedFile, config, locale, undefined, preservePatterns, objectKeys, syncPrimaryWithDefaults, syncAll, trustDerivedDefaults, logger);
|
|
940
|
+
const built = buildNewTranslationsForNs(nsKeys, existingMergedFile, config, locale, undefined, preservePatterns, objectKeys, syncPrimaryWithDefaults, syncAll, trustDerivedDefaults, primaryMergedFile, logger);
|
|
922
941
|
Object.assign(newMergedTranslations, built);
|
|
923
942
|
}
|
|
924
943
|
else {
|
|
925
944
|
const existingTranslations = existingMergedFile[nsKey] || {};
|
|
926
|
-
|
|
945
|
+
const primaryExistingTranslations = primaryMergedFile[nsKey] || {};
|
|
946
|
+
newMergedTranslations[nsKey] = buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, nsKey, preservePatterns, objectKeys, syncPrimaryWithDefaults, syncAll, trustDerivedDefaults, primaryExistingTranslations, logger);
|
|
927
947
|
}
|
|
928
948
|
}
|
|
929
949
|
// Preserve ignored namespaces as-is from the existing merged file
|
|
@@ -961,7 +981,11 @@ async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaul
|
|
|
961
981
|
const outputPath = getOutputPath(config.extract.output, locale, ns);
|
|
962
982
|
const fullPath = resolve(process.cwd(), outputPath);
|
|
963
983
|
const existingTranslations = await loadTranslationFile(fullPath) || {};
|
|
964
|
-
const
|
|
984
|
+
const primaryOutputPath = resolve(process.cwd(), getOutputPath(config.extract.output, primaryLanguage, ns));
|
|
985
|
+
const primaryExistingTranslations = locale === primaryLanguage
|
|
986
|
+
? existingTranslations
|
|
987
|
+
: (await loadTranslationFile(primaryOutputPath) || {});
|
|
988
|
+
const newTranslations = buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, ns, preservePatterns, objectKeys, syncPrimaryWithDefaults, syncAll, trustDerivedDefaults, primaryExistingTranslations, logger);
|
|
965
989
|
const oldContent = JSON.stringify(existingTranslations, null, indentation);
|
|
966
990
|
const newContent = JSON.stringify(newTranslations, null, indentation);
|
|
967
991
|
// Push one result per namespace file
|
package/package.json
CHANGED
|
@@ -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;
|
|
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;AAo8B9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
|