angular - 带有选择的属性的角度 i18n
问题描述
我有一个我想使用 i18n 从角度翻译的元素。我要翻译的部分是 matTooltip 但值是一个选择。我知道我必须使用i18n-matTooltip
它才能使其工作。我应该使用文档中的这种语法<span i18n>The author is {gender, select, male {male} female {female} other {other}}</span>
,但这样做会出错。
Uncaught Error: Template parse errors:
Parser Error: Missing expected : at column 9 in [{section.addTooltip,
select, test {test} test2 {test2} test3 {test3}}] in
ng:///AppModule/TestComponent.html@34:72 ("
</div>
这就是我的元素的样子:
<button mat-flat-button (click)="click()"
[matTooltip]="{section.addTooltip, select, test {test} test2 {test2} test3
{test3}}" matTooltipPosition="above" i18n-matTooltip>
我错过了什么吗?
解决方案
我遇到了完全相同的问题,要将 i18n 插入matTooltip
您必须创建一个隐藏的 HTML 元素来执行 i18n 并reference.innerText
作为工具提示值传递(在此处找到)。这看起来像是 hack,但 Angular 组件团队决定不支持ng-template
作为有效输入值。
与 不同ng-template
的是,隐藏的元素并不总是不显眼,例如mat-select
触发值使用 mat-option
's textContent
,因此如果将工具提示或带有工具提示的元素放入mat-option
,整个工具提示文本将在触发器中可见。这可以使用mat-select-trigger
自定义触发器文本来解决。
<button
[matTooltip]='template.innerText'
(click)='changeValue()'
>Click to change value</button>
Value: {{value}}
<template
#template
i18n='@@foo'
>Value is {value, select, true {truthy} false {falsy} }</template>
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
value = 'true'
changeValue() {
this.value = this.value === 'true' ? 'false' : 'true'
}
}
推荐阅读
- javascript - 解析来自 Firebase 的数据
- python - 用python打开doc文件(97-2003版本)
- julia - 如何在 Julia 中计算数组的模式?
- angular - 警告:当执行 npm install 时,“推断的 tsconfig 文件”..../frontend/tsconfig.json”似乎是“解决方案风格”...”
- javascript - 如何将全局变量传递到具有 3 个测试用例的测试套件中
- mysql - 使用 REGEX 组合多个查询
- swift - 从滑动操作(Swift/Xcode)调用时,键盘不会停留在文本字段上
- python-3.x - 将 TFIDF 向量转换为句子
- algorithm - 关于算法复杂度,我怎么知道 n^(0.1) = w[ (log n)^10 ]
- python - 如何在 Python 中使现有的时间序列更加不稳定?