// 从 2.8.1 开始
moment.locale(String, Object);
// 废弃于 2.8.1
moment.lang(String, Object);
在浏览器中加载语言环境仅需要包括语言环境文件。 确保指定字符集以防止编码问题。
<script src="moment.js"></script>
<script src="locale/fr.js" charset="UTF-8"></script>
<script src="locale/pt.js" charset="UTF-8"></script>
<script>
moment.locale('fr'); // 设置默认/全局的语言环境。
// ...
</script>
有所有语言环境的压缩版本:
<script src="moment.js"></script>
<script src="min/locales.js" charset="UTF-8"></script>
为了最大程度地减少 HTTP 请求,请使用 Grunt 任务以自定义的语言环境列表来编译 Moment:
grunt transpile:fr,it
<script src="min/moment-with-locales.custom.js" charset="UTF-8"></script>
如果使用 JSPM 作为插件管理器,则应在 lib 中添加语言环境。
import * as moment from 'moment';
import 'moment/locale/fr';
注意:语言环境文件是以 UMD 风格定义的,因此它们应在所有环境中无缝运行。
// From 2.8.1 onward
moment.locale(String, Object);
// Deprecated in 2.8.1
moment.lang(String, Object);
Loading locales in the browser just requires you to include the locale files. Be sure to specify the charset to prevent encoding issues.
<script src="moment.js"></script>
<script src="locale/fr.js" charset="UTF-8"></script>
<script src="locale/pt.js" charset="UTF-8"></script>
<script>
moment.locale('fr'); // Set the default/global locale
// ...
</script>
There are minified versions of all locales together:
<script src="moment.js"></script>
<script src="min/locales.js" charset="UTF-8"></script>
To minimize HTTP requests, use our Grunt task to compile Moment with a custom list of locales:
grunt transpile:fr,it
<script src="min/moment-with-locales.custom.js" charset="UTF-8"></script>
If you are using JSPM as plugin manager, you should add the locale in your lib.
import * as moment from 'moment';
import 'moment/locale/fr';
Note: Locale files are defined in UMD style, so they should work seamlessly in all environments.