5

I run into an issue recently - in some parts of my angular application I have to show the date in the following format: MMMM yyyy, as well in some components of the Angular UI Bootstrap framework.

The basic issue is that in some languages the month in nominative and genitive case is spelled differently. In my case that would be Polish, Ukrainian and Russian.

As it seems by default MMMM stands for month name in genitive case, which generally makes sense.

Though I've noticed that in angular locale files for Russian and Polish language there is a property STANDALONEMONTH which, as I see, stands for month name in nominative. (though file for Ukrainian is missing that part)

Though I'm not quite sure how to take use on those. My basic suggestion would be to go with a decorator for the dateFilter.

So the question is - whether there is a standard way for month name inflection handling in angular, or a workaround that is commonly used, so that the third party libraries using the $locale would use the proper month name.

Example

date: '2016-01-20'

en-us: 
'dd MMMM yyyy' -> '20 January 2016'  
'MMMM yyyy'    -> 'January 2016'    

uk-ua: 
'dd MMMM yyyy' -> '20 січня 2016'    // genitive case - it is fine
'MMMM yyyy'    -> 'січня 2016'      // wrong: should be 'січень 2016'

pl-pl: 
'dd MMMM yyyy' -> '20 stycznia 2016' // genitive case - it is fine
'MMMM yyyy'    -> 'stycznia 2016'    // wrong: should be 'styczeń 2016'

As you see - for Ukrainian and Polish the name of the month should have a different ending in those two cases. As well for Polish and Russian there is a month name in proper case in angular locale files (STANDALONEMONTH). Though I'm not quite sure they are used anywhere - was not able to find usage, or maybe I am missing something.

danyloid
  • 1,677
  • 3
  • 21
  • 47
  • Not really clear why if you have included proper `$locale` resources you aren't seeing proper values. A demo would probably help – charlietfl Feb 07 '16 at 13:14
  • @charlietfl I am getting proper values. In a way of course. You're right, I'll add examples. Thanks. – danyloid Feb 07 '16 at 13:40
  • i'm personally unfamiliar with even these language nuances. I would imagine though that many others have run into this. Have you checked through github issues on this? – charlietfl Feb 07 '16 at 14:07
  • @charlietfl yes, I've checked both angularjs and angular-ui/bootstrap issues. though, since there is a `STANDALONEMONTH` property in angular locale files - I guess that the case is kind of handled. I'm trying to figure out if there is a standart way of dealing with those, as I was not able to find any. – danyloid Feb 07 '16 at 14:20
  • 2
    **"In locale files there is a property STANDALONEMONTH. Though I'm not quite sure how to take use on those."** In angular [docs](https://docs.angularjs.org/api/ng/filter/date) I can see new date element 'LLLL': Stand-alone month in year (January-December). Docs version is shown v1.5.1-build.4664 (snapshot) build. In earlier docs there is no 'LLLL' element. Probably 'LLLL' would be added there in next public builds. I think locale files are just fixed earlier. – Sol Mar 15 '16 at 18:15
  • moment.js is locale aware. http://momentjs.com/docs/ – gm2008 Apr 06 '16 at 13:25

1 Answers1

2

I couldn't find anything in the built-in locale service when I was working on a similar issue some time ago in Angular 1.3, so I have solved this by manually creating a list with translations in proper case and referencing those by month number, something like {{monthNamesNominative[monthNumber]}} where var monthNamesNominative = ['Январь', 'Февраль', ...]. The added benefit here is that you have direct control over the string and don't have to do extra jumps if you need a slightly different capitalisation.

Having said that, locale service in Angular 1.5 has the LLLL token with month name in nominative case and it appears that four days after you asked this question the bug in Angular that prevented its correct use was fixed, and from version 1.5.1 onward using it instead is probably better.

n1313
  • 20,555
  • 7
  • 31
  • 46