翻译返回按钮 ionic 2 [英] translate back button ionic 2

查看:8
本文介绍了翻译返回按钮 ionic 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ionic 2 中更改了后退按钮的名称,但有人知道如何使用 ng2-translate 翻译此按钮吗?

I changed the name of the Back button in ionic 2 but does somebody know how you can translate this button with ng2-translate?

this.config.set('backButtonText', 'Go Back'); // < want to translate this with ng2-translate.

推荐答案

你可以在你的app.ts中这样翻译后面的文字(假设你已经成功实现了ng2-translate模块):

You can translate the back text like this (assuming you have already successfully implemented the ng2-translate module) in your app.ts:

initializeApp() {
    this.platform.ready().then(() => {
        this.config.set('backButtonText', this.translate.get('ui.general.back')['value']);
    });
}

有必要在 ready-function 中设置它,因为本地化加载异步,这是您知道本地化文件已加载并且模块已准备好工作的地方.

It is neccessary to set this in the ready-function because the localization loads async and this is the place where you know that the localization files have been loaded and the module is ready to work.

显然我已经在 ui.general.back 下的相应 json 文件中设置了翻译文本;)

Obviously I have set the translation text in the appropriate json-files under ui.general.back ;)

如果您尚未访问配置,则需要将其导入:

If you have not yet accessed the config then you need to import it:

import {..., Config} from 'ionic-angular';

这篇关于翻译返回按钮 ionic 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆