【问题标题】:Angular Dynamic Locale not working instantlyAngular Dynamic Locale 无法立即工作
【发布时间】:2015-04-30 10:48:44
【问题描述】:

我使用angular-dynamic-locale 更改UI Bootstrap 的日期选择器的语言(我不想在服务器端添加正确的本地化源文件。因此,我需要更动态的东西)。

本地化文件已加载。但是,当我在页面上打开日期选择器时,只有在我通过 <> 按钮切换到新月份后才会进行本地化。

有没有办法让这种变化直接发生?

【问题讨论】:

    标签: angularjs localization datepicker locale angular-ui-bootstrap


    【解决方案1】:

    没关系,我实际上找到了一个不涉及动态本地化的解决方案。作为proposed by will Farrrell,我在index.html 的标题中检测到用户的语言环境并加载相应的语言环境:

    var locale = window.navigator.userLanguage || window.navigator.language;
    if (locale) {
        var smallLocale = locale.toLowerCase();
        document.write('<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.2.15/angular-locale_' + smallLocale + '.js"><\/script>');
    } 
    

    这适用于日期选择器(如果不需要动态行为)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-13
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 2012-09-28
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      相关资源
      最近更新 更多