Angular 内化翻译文件上传按钮文本

问题描述 投票:0回答:2

我正在使用 Angular 和

i18n
将应用程序翻译成不同的语言。

如何翻译输入文件上传按钮选择文件和未选择文件文本。

<input type="file" ng2FileSelect [uploader] = "uploader">

ng2-file-upload

angular localization internationalization angular-i18n
2个回答
0
投票

尝试这样的事情:

您可以使用传统方式创建自定义文件上传,以便您可以使用

Angular internalization translate

堆栈闪电战

HTML:

<label class="custom-file-upload">
            <input #fileInput  type="file" (change)="select($event)" />
            <span i18n>Upload File</span>
        </label>

CSS:

input[type="file"] {
    display: none;
}
.custom-file-upload {
    border: none;
    display: inline-block;
    padding: 0;
    cursor: pointer;
    float: left;
    margin-bottom: 20px;
    a {
        color: #0000ee;
    }

    a:hover {
        color: #0000ee;
        text-decoration: underline;
    }
}

TS:

export class AppComponent {

  @ViewChild('fileInput') fileInput: any;
  select(event) {
    console.log(event);
  }
}

0
投票

这是一个很老的问题,但是我会回答它,因为我刚刚遇到了同样的情况。 p-upload 允许您设置选择标签,如

chooseLabel="Choose" 
那么你可以用这种方式应用你的本地化

chooseLabel="{{ 'Choose' | localize }}"

如官方文档所示 https://primeng.org/fileupload

© www.soinside.com 2019 - 2024. All rights reserved.