【问题标题】:Angular 4 - ionic 3 translation of text inside '.ts' fileAngular 4 - '.ts' 文件中文本的离子 3 翻译
【发布时间】:2018-03-02 14:53:21
【问题描述】:

我想知道如何翻译“.ts”文件中的文本
基本上它是一个加载文本

showLoader() { 
this.loading = this.loadingCtrl.create({
  content: 'Loading...'
});
this.loading.present();

  }

当语言设置为法语时,我需要将“正在加载...”文本翻译为“收费...”
谢谢

【问题讨论】:

    标签: angular typescript ionic2 ionic3


    【解决方案1】:

    @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
    });
    

    【讨论】:

    • 很高兴看到另一个很棒的方法。感谢您与我们分享。
    【解决方案2】:

    你可以这样做:

    注意:我从我的工作代码库中提取了这个。所以请随意调整。如果您需要进一步的帮助,请告诉我。

    presentLoader(): Loading {
        this.translate.get('Please_wait').subscribe(res => {
          this.content = res;
        });
        let loader = this.loadingCtrl.create({
          content: this.content
        });
        loader.present();
        return loader;
      }
    

    【讨论】:

    • 非常感谢 :) @sebaferreras
    猜你喜欢
    • 2020-06-30
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多