MCPcopy Index your code
hub / github.com/angular/angular / extractTranslations

Function extractTranslations

packages/localize/tools/src/extract/index.ts:79–122  ·  view source on GitHub ↗
({
  rootPath,
  sourceFilePaths,
  sourceLocale,
  format,
  outputPath: output,
  logger,
  useSourceMaps,
  useLegacyIds,
  duplicateMessageHandling,
  formatOptions = {},
  fileSystem: fs,
}: ExtractTranslationsOptions)

Source from the content-addressed store, hash-verified

77}
78
79export function extractTranslations({
80 rootPath,
81 sourceFilePaths,
82 sourceLocale,
83 format,
84 outputPath: output,
85 logger,
86 useSourceMaps,
87 useLegacyIds,
88 duplicateMessageHandling,
89 formatOptions = {},
90 fileSystem: fs,
91}: ExtractTranslationsOptions) {
92 const basePath = fs.resolve(rootPath);
93 const extractor = new MessageExtractor(fs, logger, {basePath, useSourceMaps});
94
95 const messages: ɵParsedMessage[] = [];
96 for (const file of sourceFilePaths) {
97 messages.push(...extractor.extractMessages(file));
98 }
99
100 const diagnostics = checkDuplicateMessages(fs, messages, duplicateMessageHandling, basePath);
101 if (diagnostics.hasErrors) {
102 throw new Error(diagnostics.formatDiagnostics('Failed to extract messages'));
103 }
104
105 const outputPath = fs.resolve(rootPath, output);
106 const serializer = getSerializer(
107 format,
108 sourceLocale,
109 fs.dirname(outputPath),
110 useLegacyIds,
111 formatOptions,
112 fs,
113 diagnostics,
114 );
115 const translationFile = serializer.serialize(messages);
116 fs.ensureDir(fs.dirname(outputPath));
117 fs.writeFile(outputPath, translationFile);
118
119 if (diagnostics.messages.length) {
120 logger.warn(diagnostics.formatDiagnostics('Messages extracted with warnings'));
121 }
122}
123
124function getSerializer(
125 format: string,

Callers 2

main_spec.tsFile · 0.90
cli.tsFile · 0.90

Calls 11

extractMessagesMethod · 0.95
checkDuplicateMessagesFunction · 0.90
getSerializerFunction · 0.85
formatDiagnosticsMethod · 0.80
resolveMethod · 0.65
dirnameMethod · 0.65
serializeMethod · 0.65
ensureDirMethod · 0.65
writeFileMethod · 0.65
warnMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…