我想知道如何翻译'.ts‘文件中的文本
基本上这是一个加载文本
showLoader() {
this.loading = this.loadingCtrl.create({
content: 'Loading...'
});
this.loading.present();
}我需要的是发短信“加载.”翻译成“权力.”当语言设置为法语时
谢谢
发布于 2017-09-21 10:09:17
你可以这样做:
注意:,我从我的工作代码base.So中提取了这个,请根据您的意愿进行调整。如果您需要进一步的帮助,请告诉我。
presentLoader(): Loading {
this.translate.get('Please_wait').subscribe(res => {
this.content = res;
});
let loader = this.loadingCtrl.create({
content: this.content
});
loader.present();
return loader;
}发布于 2017-09-21 11:14:55
@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
});https://stackoverflow.com/questions/46340783
复制相似问题