({
sourceRootPath,
sourceFilePaths,
translationFilePaths,
translationFileLocales,
outputPathFn,
diagnostics,
missingTranslation,
duplicateTranslation,
sourceLocale,
}: TranslateFilesOptions)
| 84 | } |
| 85 | |
| 86 | export 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 | } |
no test coverage detected
searching dependent graphs…