嘿伙计们,我想知道如何翻译'.ts'文件中的文字
基本上它是一个加载文本
page:load
我需要的是将文本“Loading ...”翻译为“Chargement ...”当语言设置为法语时 感谢
答案 0 :(得分:6)
你可以这样做:
注意:我是从我的工作代码库中提取的。所以请根据需要进行调整。如果您需要进一步的帮助,请告诉我。
presentLoader(): Loading {
this.translate.get('Please_wait').subscribe(res => {
this.content = res;
});
let loader = this.loadingCtrl.create({
content: this.content
});
loader.present();
return loader;
}
答案 1 :(得分:3)
@Sampath's回答完美无缺,但我仍然希望添加另一种方法,返回Promise
。
由于get
方法是异步的,我更倾向于在转换准备就绪时创建Loading
,而不是创建它,然后更新对内容的引用。
// Imports
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/toPromise';
// ...
presentLoader(translationKey: string): Promise<Loading> {
return this.translate.get(translationKey)
.toPromise()
.then(translation => {
// Create the loader
let loader = this.loadingCtrl.create({
content: translation
});
// Present the loader
loader.present();
// Return the loader
return loader;
});
}
你可以使用这样的方法:
this.presentLoader('Please_wait').then((loader: Loading) => {
// This code is executed after the loading has been presented...
// ... You can use the loader property to hide the loader
});