After changing the moment's locale by setting the property below:
moment.locale(chosenLocale);
It appears that everything is functioning correctly. The month names and weekday names are displayed according to the selected locale, and week numbers are calculated accurately as well.
Using the default (English) locale, I see month names such as January, February, etc., along with weekday names like Monday, Tuesday, etc. However, with the Danish locale, these names appear in lowercase. While it's simple to capitalize the first letter when formatting a basic weekday, more complex formats may present challenges where merely uppercase the first letter won't suffice (January 1st
vs. 1. Januar
).
The format I'm using to show the month name and day of the month is:
moment().format('dddd LL')
In Danish, I receive 7. marts 2016
, but my preference is 7. Marts 2016
. It's important to note that I need a solution that works for all locales, so hardcoding the month names isn't an option - or is it? I attempted the following workaround:
moment.locale(chosenLocale);
var __months = moment.months().map(function (m) { return m.toUpperCase() + "TEST"; });
moment.locale(chosenLocale, {
months : __months
});
My expectation was to receive JANUARTEST
for the Danish locale during testing, however, I received januartest
. This suggests that the lowercase issue is being applied elsewhere within the framework. I also experimented with setting the months
property to a function as per the API docs, returning the uppercase value of the cached month array, but encountered the same outcome.
Is there a viable solution to this dilemma?