Angularjs 和 $locale [英] Angularjs and $locale

查看:23
本文介绍了Angularjs 和 $locale的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以手动为某些应用程序设置 $locale 吗?

Can I set $locale for some application manually?

是否有可能支持本地人的唯一方法是包含来自当前语言环境的 angular 库的本地化文件.如果有多种文化怎么办?在那种情况下,我必须动态加载本地化文件?我错过了什么?

Is it possible that only way to support locals is to include localization file from angular library for current locale. What if there are multiple cultures? In that case I have to load localization files dynamically? What am I missing?

推荐答案

老实说,angular 中的 $locale 服务仍然非常原始.确实不错,但在这方面似乎缺乏灵活性.最大的问题是,即使您通过动态重新加载正确的语言环境文件来切换语言环境,诸如日期过滤器之类的东西也不会知道您已更改它,因为它们在设置时正在注册其语言环境信息.因此,您目前有几个选择:1. 使用所选区域设置重新加载页面...或 2. 编写您自己的区域设置提供程序和使用它的过滤器.

Honestly, the $locale service in angular is pretty primitive still. It's really good, but it seems to lack flexibility in this area. The biggest issue is that even if you switch your locale by dynamically reloading the proper locale file, things like the date filter won't know you've changed it because they're registering their locale information when they're set up. So you have a couple of choices currently: 1. Reload the page with the selected locale... or 2. Write your own Locale Provider and Filters that use it.

可能创建一个服务来动态加载正确的脚本文件,重新初始化所有受影响的过滤器和服务,然后刷新视图,但我不确定这会涉及到什么此时.

It might be possible create a service that would dynamically load the proper script file, reinitialize all affected filters and services, then refresh the views, but I'm not really sure what all that would involve at this point.

这篇关于Angularjs 和 $locale的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆