Angular 动态语言环境无法立即运行

Angular Dynamic Locale not working instantly

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

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

有没有什么办法可以让这种变化直接发生?

没关系,我居然找到了一个不涉及动态定位的解决方案。作为 proposed by will Farrrell,我在 index.html 的 header 中检测到用户的语言环境,并加载相应的语言环境:

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>');
} 

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