国际与angularjs [英] Internationalization with angularjs

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

问题描述

我在想我的移动网站angularjs,我想开始很小,从Django的所有动静态我的服务器端的纯文本模板,以角(否则会出现语法麻烦'{{ }}')

I'm thinking of moving my site to angularjs, and I want to start very small, by moving all my static server-side plain-text templating from django to angular (otherwise there will be syntax trouble with the '{{}}').

看来,这样做的最佳方式将是两个选项之一:

It seems that the best way to do that will be one of two options:


  1. 要拥有一个Ajax调用返回一个JSON我的网站的所有文本。该文本将被存储在其中绑定到我的HTML元素,因此角将更新所有的变量。

  2. 要存储与字典静态js文件并将其包含在我的HTML和绑定的字典,angularjs。

这两种方法都可以让我无需重新加载页面语言之间切换。

Both options will allow me to switch between languages without reloading the page.

哪一个更好?一般情况下,这是一个很好的做法还是有一个比较正确的做法?

Which one is better? In general, is this a good approach or is there a more correct way?

推荐答案

首先,有改变角度的分隔符其他符号的方式在这里得到解答:的角JS自定义分隔符

First of all, there is a way to change angular's delimiters to other symbols as answered here: Angular JS custom delimiter

2的选项更容易。你有一次,你必须在页面加载所有的翻译。没有异步调用,没有承诺,美观,方便。

The 2. option is easier. You include it once and you have all translations on page load. No async calls, no promises, nice and easy.

,但我会去的第一个。如 $服务翻译将真正使您的生活更轻松以下选项1.加上它有加载和许多选项存储localStorage的和饼干加载的数据,所以有足够的空间扩展和定制。然后,您可以转换您的内容与$翻译服务,指导或过滤器。

And yet i'd go with the first one. Services like $translate would really make your life easier following option 1. Plus it has many options for loading and storing loaded data in LocalStorage and cookies, so there's plenty of space for extension and customization. You can then translate your content with $translate service, directive or filter.

和不要忘记,2选项禁用缓存请求的任何选项。在每个请求您的起始页服务器读取静态文件,并将其包含在HTML。随着第一个选项,用户的浏览器可以缓存以.json,只要你喜欢。

And don't forget that 2 option disables any options of cached requests. On each request to your start page the server has to read static file and include it in the html. With first option the user's browser can cache .json for as long as you like.

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

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