Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 如何在爱奥尼亚3中使用翻译管道更新html_Ionic Framework_Ionic3 - Fatal编程技术网

Ionic framework 如何在爱奥尼亚3中使用翻译管道更新html

Ionic framework 如何在爱奥尼亚3中使用翻译管道更新html,ionic-framework,ionic3,Ionic Framework,Ionic3,在ionic 3中,我创建了一个名为translate的管道,在HTML中,我像{{'welcome'| translate}} 翻译.pipe.ts 翻译工作正常,但我不知道当用户在不关闭和不重新启动应用程序的情况下更改语言时如何更新HTML。。取决于你想什么时候改变它。。你可以把lang变量作为pipeNo的第二个参数,我想你明白了。这很好,但举一个例子,比如在一个表单中,我用translate pipe和一个lang下拉列表English显示Hello,法语现在Hello是英语,我如何更改

在ionic 3中,我创建了一个名为
translate
的管道,在HTML中,我像
{{'welcome'| translate}}

翻译.pipe.ts
翻译工作正常,但我不知道当用户在不关闭和不重新启动应用程序的情况下更改语言时如何更新HTML。。取决于你想什么时候改变它。。你可以把
lang
变量作为pipeNo的第二个参数,我想你明白了。这很好,但举一个例子,比如在一个表单中,我用translate pipe和一个lang下拉列表English显示Hello,法语现在Hello是英语,我如何更改它是法语,因为管道已经加载了它们的内容。
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'translate',
})
export class TranslatePipe implements PipeTransform 
{
    transform(value: string, ...args) 
    {
        var lang = localStorage.getItem("default-app-lang");
        return this[lang](value);
    }
    en(key)
    {
        var lang = 
        {
            "welcome":"welcome",
        }

        return lang[key];
    }
    gu(key)
    {
        var lang = 
        {
            "welcome":"વેલકોમ",
        }
        return lang[key];
    }
}