MCPcopy
hub / github.com/angular/angular / translateFiles

Function translateFiles

packages/localize/tools/src/translate/index.ts:86–134  ·  view source on GitHub ↗
({
  sourceRootPath,
  sourceFilePaths,
  translationFilePaths,
  translationFileLocales,
  outputPathFn,
  diagnostics,
  missingTranslation,
  duplicateTranslation,
  sourceLocale,
}: TranslateFilesOptions)

Source from the content-addressed store, hash-verified

84}
85
86export function translateFiles({
87 sourceRootPath,
88 sourceFilePaths,
89 translationFilePaths,
90 translationFileLocales,
91 outputPathFn,
92 diagnostics,
93 missingTranslation,
94 duplicateTranslation,
95 sourceLocale,
96}: TranslateFilesOptions) {
97 const fs = getFileSystem();
98 const translationLoader = new TranslationLoader(
99 fs,
100 [
101 new Xliff2TranslationParser(),
102 new Xliff1TranslationParser(),
103 new XtbTranslationParser(),
104 new SimpleJsonTranslationParser(),
105 new ArbTranslationParser(),
106 ],
107 duplicateTranslation,
108 diagnostics,
109 );
110
111 const resourceProcessor = new Translator(
112 fs,
113 [new SourceFileTranslationHandler(fs, {missingTranslation}), new AssetTranslationHandler(fs)],
114 diagnostics,
115 );
116
117 // Convert all the `translationFilePaths` elements to arrays.
118 const translationFilePathsArrays = translationFilePaths.map((filePaths) =>
119 Array.isArray(filePaths) ? filePaths.map((p) => fs.resolve(p)) : [fs.resolve(filePaths)],
120 );
121
122 const translations = translationLoader.loadBundles(
123 translationFilePathsArrays,
124 translationFileLocales,
125 );
126 sourceRootPath = fs.resolve(sourceRootPath);
127 resourceProcessor.translateFiles(
128 sourceFilePaths.map(relativeFrom),
129 fs.resolve(sourceRootPath),
130 outputPathFn,
131 translations,
132 sourceLocale,
133 );
134}

Callers 2

main_spec.tsFile · 0.90
cli.tsFile · 0.90

Calls 6

loadBundlesMethod · 0.95
translateFilesMethod · 0.95
getFileSystemFunction · 0.85
mapMethod · 0.80
isArrayMethod · 0.80
resolveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…