使用 ngx-translate 翻译 angular 10 中的动态字符串

translate dynamic string in angular 10 using ngx-translate

我正在使用一些动态值来创建一个字符串并将其发送到 sweetalert 配置。

我想知道在发送到配置之前我们是否可以翻译字符串?

我见过几个可以将变量传递给翻译方法的解决方案,但是否可以使用其他解决方案?

我应该在 en.json 中添加什么?

let status = '';
switch (action?.innerText) {
    case 'Accept': {
        status = 'Accepted';
        break;
    }
    case 'Approve': {
        status = 'Approved';
        break;
    }
    case 'Delete': {
        status = 'Deleted';
        break;
    }
    case 'Reject': {
        status = 'Rejected';
        break;
    }
}

//You have ${status} a Request for $${this.data?.details?.amount}
let transalteTitle;
this.translate.get('You have', {
    value: status
}, ' a Request for', {
    value: this.data?.details?.amount
}).subscribe(res => {
    transalteTitle = res;
});

const configval = {
    title: transalteTitle,
    text: 'Do you want to continue?',
    showCancelButton: true,
    icon: 'warning',
    confirmButtonText: 'YES',
    cancelButtonText: 'NO'
};


//en.json

{
    "title": "You have ${status} a Request for ${val}"
    "status_accepted": "accepeted",
    "status_rejected": "rejected"
}

let status = '';
switch (action?.innerText) {
    case 'Accept': {
        status = 'status_accepted';
        break;
    }
    case 'Approve': {
        status = 'status_approve';
        break;
    }
    case 'Delete': {
        status = 'status_delete';
        break;
    }
    case 'Reject': {
        status = 'status_rejected';
        break;
    }
}

//You have ${status} a Request for $${this.data?.details?.amount}
let transalteTitle;
this.translate.get(status).pipe(switchMap(translatedStatus =>
    this.translate.get('title', {
        status: translatedStatus, val:
            this.data?.details?.amount
    }))).subcribe(translatedTilte => {
    const configval = {
        title: transalteTitle,
        text: 'Do you want to continue?',
        showCancelButton: true,
        icon: 'warning',
        confirmButtonText: 'YES',
        cancelButtonText: 'NO'
    };
})


//en.json

{
    "title": "You have ${status} a Request for ${val}"
    "status_accepted": "accepeted",
        "status_rejected": "rejected"
}`enter code here`