MCPcopy Create free account
hub / github.com/angular/angular / parseTranslation

Function parseTranslation

packages/localize/src/utils/src/translations.ts:97–113  ·  view source on GitHub ↗
(messageString: TargetMessage)

Source from the content-addressed store, hash-verified

95 * @param message the message to be parsed.
96 */
97export function parseTranslation(messageString: TargetMessage): ParsedTranslation {
98 const parts = messageString.split(/{\$([^}]*)}/);
99 const messageParts = [parts[0]];
100 const placeholderNames: string[] = [];
101 for (let i = 1; i < parts.length - 1; i += 2) {
102 placeholderNames.push(parts[i]);
103 messageParts.push(`${parts[i + 1]}`);
104 }
105 const rawMessageParts = messageParts.map((part) =>
106 part.charAt(0) === BLOCK_MARKER ? '\\' + part : part,
107 );
108 return {
109 text: messageString,
110 messageParts: makeTemplateObject(messageParts, rawMessageParts),
111 placeholderNames,
112 };
113}
114
115/**
116 * Create a `ParsedTranslation` from a set of `messageParts` and `placeholderNames`.

Callers 3

loadTranslationsFunction · 0.90
parseTranslationsFunction · 0.85

Calls 4

mapMethod · 0.80
charAtMethod · 0.80
makeTemplateObjectFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected