Loading locales in the browser1.0.0+

  1. // From 2.8.1 onward
  2. moment.locale(String, Object);
  3. // Deprecated in 2.8.1
  4. 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.

  1. <script src="moment.js"></script>
  2. <script src="locale/fr.js" charset="UTF-8"></script>
  3. <script src="locale/pt.js" charset="UTF-8"></script>
  4. <script>
  5. moment.locale('fr'); // Set the default/global locale
  6. // ...
  7. </script>

There are minified versions of all locales together:

  1. <script src="moment.js"></script>
  2. <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:

  1. grunt transpile:fr,it
  1. <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.

  1. import * as moment from 'moment';
  2. import 'moment/locale/fr';

Note: Locale files are defined in UMD style, so they should work seamlessly in all environments.