Wrong month name in russian
Asked Answered
S

8

5

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?

Salimeter answered 27/9, 2011 at 9:46 Comment(3)
what do you mean by "I get this from PHP and this from him". If PHP writes Сентябрь onto the page the user sees Сентябрь. It wont magically transform into Сентября. Also, Google Translate says translate.google.de/…. Please clarify the question.Keramics
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.Salimeter
You can use a switch statement to echo out the correct month.Gainly
C
4

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];
}
Chopstick answered 2/2, 2012 at 19:31 Comment(0)
K
2

Too late I know but you may use a date formatter with "LLLL" it's a stand alone month name. Just wanted to share a piece of information I've just found. :)

Killarney answered 11/10, 2016 at 10:10 Comment(0)
M
1

If your customer really wants "Сентября" then a simple str_replace() would do the job.

Where you display month names, try :

str_replace("Сентябрь", "Сентября", $month);
Martingale answered 27/9, 2011 at 10:15 Comment(1)
A good solution. however, when the answer was posted, the end of september was nearing and the OP was likely to post another question about октябрь/октября (october) :)) jkPancreatin
R
1

You could put a simple if statement in to override the month name:

// Shorthand if
echo $month_name == "Сентябрь" ? "Сентября" : $month_name;

or

// Normal if
if ($month_name == "Сентябрь")
{
   echo "Сентября";
}
else
{
   echo $month_name;
}
Recourse answered 27/9, 2011 at 10:16 Comment(0)
O
0
setlocale(LC_ALL, 'ru_RU.UTF-8');
strftime('%B',strtotime($time));
Ontogeny answered 27/9, 2011 at 9:47 Comment(1)
I doubt that this helps, or even works at all. To covince me otherwise please edit and add an explanation how this works and why it is supposed to help.Barge
S
0

@tsabz's answer is probably the solution, because the error is inside PHP. That, or there is some kind of dialect in Russia that needs to be set instead.

Implementing @tsabz's answer into Typo3 requires you xclassing tslib_content (ie. tslib_cObj). This can be done by adding the following line to you typo3conf/localconf.php or better yet, in a custom extension inside typo3conf/ext/your_ext/ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_content.php']                  = PATH_typo3conf.'ext/your_ext/xclass/class.ux_tslib_content.php';

Then create the file typo3conf/ext/your_ext/xclass/class.ux_tslib_content.php and put in the following:

<?php
class ux_tslib_cObj extends tslib_cObj {
    /**
     * date
     * Will return a formatted date based on configuration given according to PHP date/gmdate properties
     * Will return gmdate when the property GMT returns true
     *
     * @param   string      Input value undergoing processing in this function.
     * @param   array       stdWrap properties for date.
     * @return  string      The processed input value
     */
    public function stdWrap_date($content = '', $conf = array()) {
        $content = parent::stdWrap_date($content, $conf);
        $content = str_replace("Сентябрь", "Сентября", $content);
        return $content;
    }

}
Spray answered 27/9, 2011 at 17:27 Comment(0)
B
0

I know it's a bit later, but others might come across this question too, so might still be worth answering. The answer from @hraban comes closest to explaining it, all other answers are only providing (partly unsatisfactory) workarounds:

Both php and the customer are correct!

The issue is that your customer expects the month name (and probably all month names) in the genitive case, see this page.

The string formatter you are using is not respecting the Russian grammar :-( This is unfortunately a tricky thing :-( Thus, you will have to do implement some workaround, as provided by others.

Bricker answered 14/4, 2015 at 8:56 Comment(0)
P
0

Whenever you write a date in Russian a month name must be in genetive. To avoid messing with locale I came up with this solution:

$monthGenetive = 
   (new \IntlDateFormatter(
   'ru_RU', 
   \IntlDateFormatter::FULL, 
   \IntlDateFormatter::FULL, 
   'Europe/Moscow', 
   \IntlDateFormatter::GREGORIAN, 
   'MMMM'))->format(new \DateTime('@' . strtotime($datum)));

where $datum is the date in whatever format strtotime would accept. PHP docs and
mysterious 'MMMM' explained. Make sure intl extension is on.

Preset answered 7/12, 2020 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.