How to handle temporary month names - Angular date localization

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

The main problem is that in some languages ​​the month in the nominative and genitive cases differs in different ways. In my case, it will be Polish, Ukrainian and Russian.

As it seems by default, MMMM means the name of the month in the genitive, which usually makes sense.

Although I noticed that in the angular files the locales for Russian and Polish have the STANDALONEMONTH property, which, as I see it, denotes the name of the month in the nominative case. (although the file for Ukrainian is missing in this part)

Although I'm not quite sure how to use them. My main suggestion would be to go with a decorator for dateFilter .

So the question is whether there is a standard way to handle the flex of the month name in angular or a workaround that is commonly used, so third-party libraries using $locale will use the corresponding 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 can see - for the Ukrainian and Polish names of the month there should be a different ending in these two cases. In addition, for the Polish and Russian languages, there is the name of the month, as appropriate, in the angular locale files ( STANDALONEMONTH ). Although I’m not quite sure that they are used everywhere - I couldn’t find a use, or maybe I’m missing something.

+5
source share
1 answer

I could not find anything in the built-in language service when I worked on a similar problem some time ago in Angular 1.3, so I solved this by manually creating a list with translations in the correct case and referring to the month number, something like {{monthNamesNominative[monthNumber]}} where var monthNamesNominative = ['', '', ...] . An additional advantage here is that you have direct control over the line and you do not need to do extra jumps if you need a little difference.

Having said that in the local service in Angular 1.5 there is an LLLL token with the name of the month in the nominative case, and it seems that four days after you asked this question in Angular, which prevented its proper use, it was fixed, and from version 1.5 .1 instead, probably better.

+1
source

Source: https://habr.com/ru/post/1242477/


All Articles