如何翻译数据中对象的属性 table

how to translate the properties of an object in data table

我目前使用 material 数据 table 和 ngx-trnslate 库

我设法迭代数据中的对象 table,但问题是我只需要转换属性。

我看过允许您像这样迭代对象的代码:

<tr *ngFor="let i of (identy| keyvalue)">
      <td>{{ i.key }}</td>
      <td>{{ i.value }}</td>
   </tr>

这是我的对象,是假的,值稍后由服务器提供

  identity = {
      prenom: "toto",
      nom: "titi"
    }

但是我如何翻译我的 json 文件中的密钥?

   "PROPERTIES":
    {
        "prenom": "surname",
        "nom": "name"
    },

我试过像这样使用 get observable:

this.translate.get(
        ['PROPERTIES.prenom', 'PROPERTIES.nom'])
        .subscribe(val => {
          this.tradPrenom = val['PROP.prenom'];
          this.tradNom = val['PROP.nom'];
        });

我已经为此苦苦挣扎了几个小时,但没有找到任何解决方案。感谢您的帮助

在模板中使用翻译标签(注意 PROPERTIES 之后的 .

<tr *ngFor="let i of (identy| keyvalue)">
      <td>{{ "PROPERTIES." + i.key | translate }}</td>
      <td>{{ i.value }}</td>
   </tr>

这将使您的模板查找 "PROPERTIES.prenom""PROPERTIES.nom"