1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import * as i18n from '../../../i18n/i18n_ast';
|
---|
9 | import { toPublicName } from '../../../i18n/serializers/xmb';
|
---|
10 | import * as o from '../../../output/output_ast';
|
---|
11 | /* Closure variables holding messages must be named `MSG_[A-Z0-9]+` */
|
---|
12 | const CLOSURE_TRANSLATION_VAR_PREFIX = 'MSG_';
|
---|
13 | /**
|
---|
14 | * Prefix for non-`goog.getMsg` i18n-related vars.
|
---|
15 | * Note: the prefix uses lowercase characters intentionally due to a Closure behavior that
|
---|
16 | * considers variables like `I18N_0` as constants and throws an error when their value changes.
|
---|
17 | */
|
---|
18 | export const TRANSLATION_VAR_PREFIX = 'i18n_';
|
---|
19 | /** Name of the i18n attributes **/
|
---|
20 | export const I18N_ATTR = 'i18n';
|
---|
21 | export const I18N_ATTR_PREFIX = 'i18n-';
|
---|
22 | /** Prefix of var expressions used in ICUs */
|
---|
23 | export const I18N_ICU_VAR_PREFIX = 'VAR_';
|
---|
24 | /** Prefix of ICU expressions for post processing */
|
---|
25 | export const I18N_ICU_MAPPING_PREFIX = 'I18N_EXP_';
|
---|
26 | /** Placeholder wrapper for i18n expressions **/
|
---|
27 | export const I18N_PLACEHOLDER_SYMBOL = '�';
|
---|
28 | export function isI18nAttribute(name) {
|
---|
29 | return name === I18N_ATTR || name.startsWith(I18N_ATTR_PREFIX);
|
---|
30 | }
|
---|
31 | export function isI18nRootNode(meta) {
|
---|
32 | return meta instanceof i18n.Message;
|
---|
33 | }
|
---|
34 | export function isSingleI18nIcu(meta) {
|
---|
35 | return isI18nRootNode(meta) && meta.nodes.length === 1 && meta.nodes[0] instanceof i18n.Icu;
|
---|
36 | }
|
---|
37 | export function hasI18nMeta(node) {
|
---|
38 | return !!node.i18n;
|
---|
39 | }
|
---|
40 | export function hasI18nAttrs(element) {
|
---|
41 | return element.attrs.some((attr) => isI18nAttribute(attr.name));
|
---|
42 | }
|
---|
43 | export function icuFromI18nMessage(message) {
|
---|
44 | return message.nodes[0];
|
---|
45 | }
|
---|
46 | export function wrapI18nPlaceholder(content, contextId = 0) {
|
---|
47 | const blockId = contextId > 0 ? `:${contextId}` : '';
|
---|
48 | return `${I18N_PLACEHOLDER_SYMBOL}${content}${blockId}${I18N_PLACEHOLDER_SYMBOL}`;
|
---|
49 | }
|
---|
50 | export function assembleI18nBoundString(strings, bindingStartIndex = 0, contextId = 0) {
|
---|
51 | if (!strings.length)
|
---|
52 | return '';
|
---|
53 | let acc = '';
|
---|
54 | const lastIdx = strings.length - 1;
|
---|
55 | for (let i = 0; i < lastIdx; i++) {
|
---|
56 | acc += `${strings[i]}${wrapI18nPlaceholder(bindingStartIndex + i, contextId)}`;
|
---|
57 | }
|
---|
58 | acc += strings[lastIdx];
|
---|
59 | return acc;
|
---|
60 | }
|
---|
61 | export function getSeqNumberGenerator(startsAt = 0) {
|
---|
62 | let current = startsAt;
|
---|
63 | return () => current++;
|
---|
64 | }
|
---|
65 | export function placeholdersToParams(placeholders) {
|
---|
66 | const params = {};
|
---|
67 | placeholders.forEach((values, key) => {
|
---|
68 | params[key] = o.literal(values.length > 1 ? `[${values.join('|')}]` : values[0]);
|
---|
69 | });
|
---|
70 | return params;
|
---|
71 | }
|
---|
72 | export function updatePlaceholderMap(map, name, ...values) {
|
---|
73 | const current = map.get(name) || [];
|
---|
74 | current.push(...values);
|
---|
75 | map.set(name, current);
|
---|
76 | }
|
---|
77 | export function assembleBoundTextPlaceholders(meta, bindingStartIndex = 0, contextId = 0) {
|
---|
78 | const startIdx = bindingStartIndex;
|
---|
79 | const placeholders = new Map();
|
---|
80 | const node = meta instanceof i18n.Message ? meta.nodes.find(node => node instanceof i18n.Container) : meta;
|
---|
81 | if (node) {
|
---|
82 | node
|
---|
83 | .children
|
---|
84 | .filter((child) => child instanceof i18n.Placeholder)
|
---|
85 | .forEach((child, idx) => {
|
---|
86 | const content = wrapI18nPlaceholder(startIdx + idx, contextId);
|
---|
87 | updatePlaceholderMap(placeholders, child.name, content);
|
---|
88 | });
|
---|
89 | }
|
---|
90 | return placeholders;
|
---|
91 | }
|
---|
92 | /**
|
---|
93 | * Format the placeholder names in a map of placeholders to expressions.
|
---|
94 | *
|
---|
95 | * The placeholder names are converted from "internal" format (e.g. `START_TAG_DIV_1`) to "external"
|
---|
96 | * format (e.g. `startTagDiv_1`).
|
---|
97 | *
|
---|
98 | * @param params A map of placeholder names to expressions.
|
---|
99 | * @param useCamelCase whether to camelCase the placeholder name when formatting.
|
---|
100 | * @returns A new map of formatted placeholder names to expressions.
|
---|
101 | */
|
---|
102 | export function i18nFormatPlaceholderNames(params = {}, useCamelCase) {
|
---|
103 | const _params = {};
|
---|
104 | if (params && Object.keys(params).length) {
|
---|
105 | Object.keys(params).forEach(key => _params[formatI18nPlaceholderName(key, useCamelCase)] = params[key]);
|
---|
106 | }
|
---|
107 | return _params;
|
---|
108 | }
|
---|
109 | /**
|
---|
110 | * Converts internal placeholder names to public-facing format
|
---|
111 | * (for example to use in goog.getMsg call).
|
---|
112 | * Example: `START_TAG_DIV_1` is converted to `startTagDiv_1`.
|
---|
113 | *
|
---|
114 | * @param name The placeholder name that should be formatted
|
---|
115 | * @returns Formatted placeholder name
|
---|
116 | */
|
---|
117 | export function formatI18nPlaceholderName(name, useCamelCase = true) {
|
---|
118 | const publicName = toPublicName(name);
|
---|
119 | if (!useCamelCase) {
|
---|
120 | return publicName;
|
---|
121 | }
|
---|
122 | const chunks = publicName.split('_');
|
---|
123 | if (chunks.length === 1) {
|
---|
124 | // if no "_" found - just lowercase the value
|
---|
125 | return name.toLowerCase();
|
---|
126 | }
|
---|
127 | let postfix;
|
---|
128 | // eject last element if it's a number
|
---|
129 | if (/^\d+$/.test(chunks[chunks.length - 1])) {
|
---|
130 | postfix = chunks.pop();
|
---|
131 | }
|
---|
132 | let raw = chunks.shift().toLowerCase();
|
---|
133 | if (chunks.length) {
|
---|
134 | raw += chunks.map(c => c.charAt(0).toUpperCase() + c.slice(1).toLowerCase()).join('');
|
---|
135 | }
|
---|
136 | return postfix ? `${raw}_${postfix}` : raw;
|
---|
137 | }
|
---|
138 | /**
|
---|
139 | * Generates a prefix for translation const name.
|
---|
140 | *
|
---|
141 | * @param extra Additional local prefix that should be injected into translation var name
|
---|
142 | * @returns Complete translation const prefix
|
---|
143 | */
|
---|
144 | export function getTranslationConstPrefix(extra) {
|
---|
145 | return `${CLOSURE_TRANSLATION_VAR_PREFIX}${extra}`.toUpperCase();
|
---|
146 | }
|
---|
147 | /**
|
---|
148 | * Generate AST to declare a variable. E.g. `var I18N_1;`.
|
---|
149 | * @param variable the name of the variable to declare.
|
---|
150 | */
|
---|
151 | export function declareI18nVariable(variable) {
|
---|
152 | return new o.DeclareVarStmt(variable.name, undefined, o.INFERRED_TYPE, undefined, variable.sourceSpan);
|
---|
153 | }
|
---|
154 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9yZW5kZXIzL3ZpZXcvaTE4bi91dGlsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUNILE9BQU8sS0FBSyxJQUFJLE1BQU0sd0JBQXdCLENBQUM7QUFDL0MsT0FBTyxFQUFDLFlBQVksRUFBQyxNQUFNLCtCQUErQixDQUFDO0FBRTNELE9BQU8sS0FBSyxDQUFDLE1BQU0sNEJBQTRCLENBQUM7QUFHaEQsc0VBQXNFO0FBQ3RFLE1BQU0sOEJBQThCLEdBQUcsTUFBTSxDQUFDO0FBRTlDOzs7O0dBSUc7QUFDSCxNQUFNLENBQUMsTUFBTSxzQkFBc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