首页 > 解决方案 > 我们如何使用下拉菜单以角度选择不同的 message.xlf 文件?

问题描述

我需要在 Angular 中编写方法或函数,以便通过下拉菜单选择要显示的语言。但是我对下拉列表进行了编码,但我不知道如何编写下拉列表和 message.fr.xlf 文件之间的链接并在之后在屏幕上显示内容。你能帮我吗,我被困在这个问题上 3 天......?我的 app.component.ts 文件是 >

import { Component, LOCALE_ID, Inject } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  minutes = 0;
  gender = 'female';
  fly = true;
  logo = 'https://angular.io/assets/images/logos/angular/angular.png';
  heroes: string[] = ['Magneta', 'Celeritas', 'Dynama'];
  public items: Array<string>;

  inc(i: number) {
    this.minutes = Math.min(5, Math.max(0, this.minutes + i));
  }
  male() { this.gender = 'male'; }
  female() { this.gender = 'female'; }
  other() { this.gender = 'other'; }

  myFuncEnglish(lang) {
    if (lang === 'EN') {
      console.log('function called is english');
    } else {
      console.log('function called is french');
    }
  }



}

我的 HTML 文件是:

<h1 i18n="User welcome|An introduction header for this sample@@introductionHeader">
  Hello i18n!
</h1>

<ng-container i18n>I don't output any element</ng-container>

<br />

<img [src]="logo" i18n-title title="Angular logo" />
<br>
<button (click)="inc(1)">+</button> <button (click)="inc(-1)">-</button>
<span i18n>Updated {minutes, plural, =0 {just now} =1 {one minute ago} other {{{minutes}} minutes ago}}</span>
({{minutes}})
<br><br>
<button (click)="male()">&#9794;</button> <button (click)="female()">&#9792;</button> <button (click)="other()">&#9895;</button>
<span i18n>The author is {gender, select, male {male} female {female} other {other}}</span>
<br><br>
<span i18n>Updated: {minutes, plural,
  =0 {just now}
  =1 {one minute ago}
  other {{{minutes}} minutes ago by {gender, select, male {male} female {female} other {other}}}}
</span>


<select (ngModelChange)="myFuncEnglish($event)"  [(ngModel)]="lang">
  <option value="EN">English</option>
  <option value="FR">France</option>
</select> 

标签: htmlangular

解决方案


推荐阅读