开发者

Wrong month name in russian

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?

Clarificati开发者_如何学Pythonon: 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?


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];
}


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. :)


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

Where you display month names, try :

str_replace("Сентябрь", "Сентября", $month);


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;
}


@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;
    }

}


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.


setlocale(LC_ALL, 'ru_RU.UTF-8');
strftime('%B',strtotime($time));


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜