如何在组件Angular2中按键进行翻译?

时间:2017-09-10 15:43:34

标签: angular

我在Angular 2中使用this library进行翻译:

在我的JSON文件中,我逐字逐句地说:

{
"delete_selected" : "Удалить выделенные",
}

然后在组件内部我尝试填充对象,如:

let obj = {
 title: <delete_selected>
};

如何通过关键词进行翻译?

2 个答案:

答案 0 :(得分:2)

我从来没有使用过这个图书馆,但是我90%肯定会这样做:

translate.get('delete_selected').subscribe((res: string) => {
    console.log(res);
    //=> '"Удалить выделенные"'
});

答案 1 :(得分:0)

You also can use stream() like: 

const item = '';

translate.stream('delete_selected').subscribe((res: string) => {
    this.item = res
});

when get() function return for once the res. stream() is update res every time the language is changed.