【问题标题】:ngb-datepicker change tooltips languagengb-datepicker 更改工具提示语言
【发布时间】:2018-12-19 17:10:40
【问题描述】:

我有一个使用自定义 NgbDatePickerI18n 的多语言应用程序:

@Injectable()
export class CustomDatepickerService extends NgbDatepickerI18n {

    constructor(private translateService: TranslateService) {
        super();
    }

    getWeekdayShortName(weekday: number): string {
        return I18N_VALUES[this.translateService.getLanguage()].weekdays[weekday - 1];
    }

    getMonthShortName(month: number): string {
        return I18N_VALUES[this.translateService.getLanguage()].months[month - 1];
    }

    getMonthFullName(month: number): string {
        return this.getMonthShortName(month);
    }

    getDayAriaLabel(date: NgbDateStruct): string {
        return `${date.day}-${date.month}-${date.year}`;
    }
}

一切正常,但是当我将鼠标悬停在上/下个月按钮上时,以及用于选择月份/年份的下拉菜单时,我可以看到一个英文的小工具提示。我想翻译那个。查看了实际代码:https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/datepicker/datepicker-navigation.ts#L15 和关于国际化的文档https://ng-bootstrap.github.io/#/components/datepicker/overview#i18n,我不太清楚如何实现这一点。我可以看到以下内容:

下一个/上一个按钮标签可以使用标准 Angular i18n 机制进行翻译。例如,在 ngb.datepicker.previous-month 名称下提取上个月标签。

但就像我说的那样,我找不到一个小例子来说明如何将它集成到我的 CustomDatepickerService 中。任何人都可以给我一个关于如何实现这一目标的小例子吗?

非常感谢!

【问题讨论】:

    标签: angular internationalization ng-bootstrap angular-i18n ngb-datepicker


    【解决方案1】:

    您可以参考 i18n 内部化 Angular 文档https://angular.io/guide/i18n#internationalization-i18n

    需要遵循自定义 ID 并使用以下标签创建 .xlf 文件。

    <trans-unit id="ngb.datepicker.previous-month" datatype="html">
      <source>Previous Month</source>
      <target state="new">Translated Text</target>
    </trans-unit> 
    

    然后你需要把这个 .xlf 挂接到 ng build 脚本中。

    参考:https://medium.com/frontend-fun/angular-introduction-to-internationalization-i18n-28226a85e04e

    https://angular-templates.io/tutorials/about/angular-internationalization-i18n-multi-language-app

    【讨论】:

    • 是否可以让应用程序即时使用不同的文件,或者它是静态的。我这么说主要是因为我希望能够在同一个应用程序中更改它的语言,并且查看示例似乎它实际上是使用翻译构建应用程序?
    • 您找到动态更改工具提示的解决方案了吗?
    • 有关此的任何更新
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 1970-01-01
    相关资源
    最近更新 更多