MCPcopy
hub / github.com/angular/angular / write

Method write

packages/compiler/src/i18n/message_bundle.ts:69–99  ·  view source on GitHub ↗
(serializer: Serializer, filterSources?: (path: string) => string)

Source from the content-addressed store, hash-verified

67 }
68
69 write(serializer: Serializer, filterSources?: (path: string) => string): string {
70 const messages: {[id: string]: i18n.Message} = {};
71 const mapperVisitor = new MapPlaceholderNames();
72
73 // Deduplicate messages based on their ID
74 this._messages.forEach((message) => {
75 const id = serializer.digest(message);
76 if (!messages.hasOwnProperty(id)) {
77 messages[id] = message;
78 } else {
79 messages[id].sources.push(...message.sources);
80 }
81 });
82
83 // Transform placeholder names using the serializer mapping
84 const msgList = Object.keys(messages).map((id) => {
85 const mapper = serializer.createNameMapper(messages[id]);
86 const src = messages[id];
87 const nodes = mapper ? mapperVisitor.convert(src.nodes, mapper) : src.nodes;
88 let transformedMessage = new i18n.Message(nodes, {}, {}, src.meaning, src.description, id);
89 transformedMessage.sources = src.sources;
90 if (filterSources) {
91 transformedMessage.sources.forEach(
92 (source: i18n.MessageSpan) => (source.filePath = filterSources(source.filePath)),
93 );
94 }
95 return transformedMessage;
96 });
97
98 return serializer.write(msgList, this._locale);
99 }
100}
101
102// Transform an i18n AST by renaming the placeholder nodes with the given mapper

Callers 4

serializeTranslationsFunction · 0.95
toXliffFunction · 0.95
toXliffFunction · 0.95
toXmbFunction · 0.95

Calls 8

convertMethod · 0.95
mapMethod · 0.80
keysMethod · 0.65
writeMethod · 0.65
forEachMethod · 0.45
digestMethod · 0.45
pushMethod · 0.45
createNameMapperMethod · 0.45

Tested by

no test coverage detected