Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to localize (i18n) moment.js within meteor.js?

How can moment.js used within a meteor.js app be told to use another language than English? moment.js (installed as an mrt package) works fine with the default English language.

Using the demo calls from the moment.js docs at http://momentjs.com/docs/#/i18n/changing-language/ always produces 'en'. I noticed there is a German language file for moment in meteor_project/packages/moment/lib/moment/lang/de.js that doesn't seem to be used though?

To specify: within a template helper I tried: moment.lang('de'); return moment.lang() //will result to 'en'

and the other options mentioned here: Format a date from inside a Handlebars Template in Meteor

like image 813
user3573583 Avatar asked Apr 28 '14 13:04

user3573583


People also ask

How do I set a moment in locale?

You set locale with moment. locale('de') , and you create a new object representing the date of now by moment() (note the parenthesis) and then format('LLL') it. The parenthesis is important.

Is MomentJS deprecated?

Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor.

What is Moment default locale?

lang(String[]); moment. lang(String, Object); By default, Moment. js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.

How do you find time from moment?

The moment(). hour() Method is used to get the hours from the current time or to set the hours.


1 Answers

You can use rzymek's packages.

These packages use the offical momentjs:moment Meteor package.

Locales:

To add a specific locale user

meteor add rzymek:moment-locale-pl

The complete list of locales can be obtained by

meteor search rzymek:moment-locale-.*

To add all locales use:

meteor add rzymek:moment-locales

like image 58
mutil Avatar answered Sep 21 '22 17:09

mutil