(icu: html.Expansion, context: I18nMessageVisitorContext)
| 135 | } |
| 136 | |
| 137 | visitExpansion(icu: html.Expansion, context: I18nMessageVisitorContext): i18n.Node { |
| 138 | context.icuDepth++; |
| 139 | const i18nIcuCases: {[k: string]: i18n.Node} = {}; |
| 140 | const i18nIcu = new i18n.Icu(icu.switchValue, icu.type, i18nIcuCases, icu.sourceSpan); |
| 141 | icu.cases.forEach((caze): void => { |
| 142 | i18nIcuCases[caze.value] = new i18n.Container( |
| 143 | caze.expression.map((node) => node.visit(this, context)), |
| 144 | caze.expSourceSpan, |
| 145 | ); |
| 146 | }); |
| 147 | context.icuDepth--; |
| 148 | |
| 149 | if (context.isIcu || context.icuDepth > 0) { |
| 150 | // Returns an ICU node when: |
| 151 | // - the message (vs a part of the message) is an ICU message, or |
| 152 | // - the ICU message is nested. |
| 153 | const expPh = context.placeholderRegistry.getUniquePlaceholder(`VAR_${icu.type}`); |
| 154 | i18nIcu.expressionPlaceholder = expPh; |
| 155 | context.placeholderToContent[expPh] = { |
| 156 | text: icu.switchValue, |
| 157 | sourceSpan: icu.switchValueSourceSpan, |
| 158 | }; |
| 159 | return context.visitNodeFn(icu, i18nIcu); |
| 160 | } |
| 161 | |
| 162 | // Else returns a placeholder |
| 163 | // ICU placeholders should not be replaced with their original content but with their |
| 164 | // translations. |
| 165 | // TODO(vicb): add a html.Node -> i18n.Message cache to avoid having to re-create the msg |
| 166 | const phName = context.placeholderRegistry.getPlaceholderName('ICU', icu.sourceSpan.toString()); |
| 167 | context.placeholderToMessage[phName] = this.toI18nMessage([icu], '', '', '', undefined); |
| 168 | const node = new i18n.IcuPlaceholder(i18nIcu, phName, icu.sourceSpan); |
| 169 | return context.visitNodeFn(icu, node); |
| 170 | } |
| 171 | |
| 172 | visitExpansionCase(_icuCase: html.ExpansionCase, _context: I18nMessageVisitorContext): i18n.Node { |
| 173 | throw new Error('Unreachable code'); |
nothing calls this directly
no test coverage detected