{"record":{"id":"5b4a64bb82a83480","repo":"angular/angular","slug":"when-merging-multiple-translation-files-the-targe","errorCode":null,"errorMessage":"When merging multiple translation files, the target locale \"${nextBundle.locale}\" found in \"${filePaths[i]}\" does not match the target locale \"${bundle.locale}\" found in earlier files [${previousFiles}].","messagePattern":"When merging multiple translation files, the target locale \"(.+?)\" found in \"(.+?)\" does not match the target locale \"(.+?)\" found in earlier files \\[(.+?)\\]\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/localize/tools/src/translate/translation_files/translation_loader.ts","lineNumber":141,"sourceCode":"  /**\n   * There is more than one `filePath` for this locale, so load each as a bundle and then merge\n   * them all together.\n   */\n  private mergeBundles(\n    filePaths: AbsoluteFsPath[],\n    providedLocale: string | undefined,\n  ): TranslationBundle {\n    const bundles = filePaths.map((filePath) => this.loadBundle(filePath, providedLocale));\n    const bundle = bundles[0];\n    for (let i = 1; i < bundles.length; i++) {\n      const nextBundle = bundles[i];\n      if (nextBundle.locale !== bundle.locale) {\n        if (this.diagnostics) {\n          const previousFiles = filePaths\n            .slice(0, i)\n            .map((f) => `\"${f}\"`)\n            .join(', ');\n          this.diagnostics.warn(\n            `When merging multiple translation files, the target locale \"${nextBundle.locale}\" found in \"${filePaths[i]}\" does not match the target locale \"${bundle.locale}\" found in earlier files [${previousFiles}].`,\n          );\n        }\n      }\n      Object.keys(nextBundle.translations).forEach((messageId) => {\n        if (bundle.translations[messageId] !== undefined) {\n          this.diagnostics?.add(\n            this.duplicateTranslation,\n            `Duplicate translations for message \"${messageId}\" when merging \"${filePaths[i]}\".`,\n          );\n        } else {\n          bundle.translations[messageId] = nextBundle.translations[messageId];\n        }\n      });\n    }\n    return bundle;\n  }\n}","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/localize/tools/src/translate/translation_files/translation_loader.ts#L123-L159","documentation":"`mergeBundles()` loads every listed translation file and folds them into one bundle; when a later file declares a target locale different from the first file's, this warning is emitted (only if a diagnostics object is attached to the loader). The merge continues, the first bundle's locale wins, and duplicate message IDs across the files are separately reported.","triggerScenarios":"Calling `mergeBundles(['fr.json', 'en.json'])` - any list where files parsed to different `locale` values; the warning fires at the first index whose locale differs from bundle[0].","commonSituations":"Globbing all translation files (multiple locales) into a single translate/build invocation instead of grouping per locale; one stray file with a wrong or missing locale field mixed into a per-locale set.","solutions":["Group translation file paths by locale and call the translate step (mergeBundles) once per locale.","Find the offending file named in the warning and fix its declared locale to match the rest of the set.","Add a CI check that every file in a merge set declares the same locale before invoking the loader."],"exampleFix":"// before: merging files that declare different locales\nconst bundle = loader.mergeBundles(['fr.json', 'en-US.json']);\n\n// after: one merge per locale\nconst fr = loader.mergeBundles(['fr.json', 'fr-FR.json']);\nconst en = loader.mergeBundles(['en.json', 'en-US.json']);","handlingStrategy":"validation","validationCode":"// Group translation files by declared locale before merging\nfunction groupByLocale(files: string[]): Map<string, string[]> {\n  const groups = new Map<string, string[]>();\n  for (const f of files) {\n    const declared = JSON.parse(readFileSync(f, 'utf8'))['@@locale'] ?? JSON.parse(readFileSync(f, 'utf8')).locale;\n    groups.set(declared, [...(groups.get(declared) ?? []), f]);\n  }\n  return groups; // merge each group separately\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never glob multiple locales into one translate invocation; iterate per locale.","Assert all files in a merge set share the same declared locale before calling mergeBundles."],"tags":["localize","i18n","locale","merge","translation-files"],"backgroundTag":"i18n-locale-mismatch","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}