Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong month name in russian

Tags:

php

strftime

I'm working on a site and my customer is from Russia. He said that the month translation in the news is wrong.

For example, September:

  • I get this from php: Сентябрь
  • and this from him: Сентября

How can I overwrite this?

Clarification: When using the locale ru_RU, the name of the month outputted will be Russian. But according to my client the name of the months is wrong. I don't speak Russian so I have no idea if he's right or wrong

I just saw that if I translate the date from this: 8th of September 2011 to Russian it will look like this: 8 сентября 2011. See the translation.

So the solution to the problem would probably be to rewrite the date format.

I haven't fixed this yet; apparently this is a bug/missing feature because of the advance Russian declensions. And the date format I need doesn't exist. I think this affects strftime and PHP date().

Can someone verify this?

like image 441
Patrik Avatar asked Sep 27 '11 09:09

Patrik


1 Answers

I know it's too late now but hope that will save someone's time.

Russian language is considered to be the hardest one in the world. In this case the right variant is definitely Сентября. You can say 'That's September now' which would be 'That's Сенбярь now'. But if you are referring to the date like 'Tomorrow is the 6th of September' then in Russian that would change to 'Tomorrow is the 6 Сентября". Changing the locale to ru_RU apparently does not know this, so here is a simple solution to fulfil this task:

(Assume $date is in d.m.Y format)

function russianDate($date){
    $date=explode(".", $date);
    switch ($date[1]){
        case 1: $m='января'; break;
        case 2: $m='февраля'; break;
        case 3: $m='марта'; break;
        case 4: $m='апреля'; break;
        case 5: $m='мая'; break;
        case 6: $m='июня'; break;
        case 7: $m='июля'; break;
        case 8: $m='августа'; break;
        case 9: $m='сентября'; break;
        case 10: $m='октября'; break;
        case 11: $m='ноября'; break;
        case 12: $m='декабря'; break;
    }
    return $date[0].' '.$m.' '.$date[2];
}
like image 173
hraban Avatar answered Oct 01 '22 14:10

hraban