Page 2 of 3

Re: Proper months localisation

Posted: Thu Mar 10, 2011 9:37 pm
by LazyBadger
[quote="Timbalu"]Just dropped in again with another :idea: idea.... :)

Code: Select all

{$entry.timestamp|@formatTime:DATE_FORMAT_SPLIT_ENTRY_DAY|@formatTime:DATE_FORMAT_SPLIT_ENTRY_MONTH|lower|@formatTime:DATE_FORMAT_SPLIT_ENTRY_YEAR} 
Same effect ("less than needed done") - I'll get martxa from Martxa, but I must to have martxoaren

Re: Proper months localisation

Posted: Fri Mar 11, 2011 10:40 am
by Timbalu
LazyBadger wrote:I'll get martxa from Martxa, but I must to have martxoaren
But Понедельник, 7 martxoaren 2011 means Monday, 7 March 2011, you say....
Google translation says russian languange is Понедельник, 7 марта 2011

If I try to tranlate with Понедельник, 7 martxoaren 2011 it says
Понедельник = russian (Monday) and
martxoaren = basque(March) which are totally different languages,
This is getting confusing while I dont get why you want 2 languages in a time string?
If these were just examples to confuse me, you really did, well done! ;-) Talking foreign languages can be hard sometimes...

As far as I understand the cases problem now, in this case the а is to much (right?), you definitely have to write your own modifier. Did you solve your original question doing this?

Re: Proper months localisation

Posted: Fri Mar 11, 2011 11:33 am
by LazyBadger
I don't want language-mix, I just use 2 separate example (with Cyrillic and lain alphabets), but with the same task: change not only casing on month, but also writing too

7 Martxa => martxoaren 7
or
7 Март => 7 марта

See at these string as at two different independent examples for 1 task - getting local month's name in correct local form

PS: Mein wollen, ist nicht ihre Muttersprache so schlecht schreiben wie dieses Beispiel ist ähnlich wie das deutsche

Re: Proper months localisation

Posted: Fri Mar 11, 2011 11:48 am
by Timbalu
LazyBadger wrote:getting local month's name in correct local form
Timbalu wrote:..., you definitely have to write your own modifier. Did you solve your original question doing this?
Yes, lastly I was quite sure to understand.... ;-) So, did you solve you modifier question/problem?

Re: Proper months localisation

Posted: Fri Mar 11, 2011 11:55 am
by LazyBadger
Timbalu wrote: So, did you solve you modifier question/problem?
No, I can get lowercased months, but nothing around accessing external file (hash-storage)

Re: Proper months localisation

Posted: Fri Mar 11, 2011 12:02 pm
by Timbalu
What is the trouble with your modifier.localmonth.php in Smarty plugin and a $serendipity['smarty']->register_modifier('localmonth', 'localmonth'); ?

Re: Proper months localisation

Posted: Fri Mar 11, 2011 12:23 pm
by LazyBadger
Timbalu wrote:What is the trouble with your modifier.localmonth.php?
Missing code of plugin, I write it from the first my post - I have php-code and business logic of smarty-modifier, can't convert it into real, live smarty-modifier

Re: Proper months localisation

Posted: Fri Mar 11, 2011 12:39 pm
by Timbalu
Well, show us what you have already.
I think what you need is something like an array of 12 month name given by %B and an array of 12 wanted local month names to convert to. You could have it as one array like keyes (old) and values (new).

Re: Proper months localisation

Posted: Fri Mar 11, 2011 1:36 pm
by Timbalu
I still think it is an interesting topic.... and I really can't imagine PHP does not know about a problem like this with russian or eastern languages.

Having this in mind, i still think it could depend on some wrong locales settings.

For checking available locales on your server, use something like this

Code: Select all

<?php
system('locale -a'); // for all locales
//system('locale -a | grep ru'); // for russian locales
?>
For russian locales in serendipity or other php frameworks, in most cases universal will do

Code: Select all

<?php
setlocale (LC_ALL, array ('ru_RU.CP1251', 'rus_RUS.1251'));
?>
for your special date and time problem it would be LC_TIME.

You could make a testlocale.php with all possible russian locales and test them one by one

Code: Select all

<?php
setlocale (LC_TIME, 'ru_RU.CP1251');
echo strftime ("%A, %e %B %Y");

setlocale (LC_TIME, 'rus_RUS.1251');
echo strftime ("%A, %e %B %Y");

setlocale(LC_TIME, 'ru_RU.UTF-8');
echo strftime ("%A, %e %B %Y");

and so on 
ru_RU.CP866
ru_RU.ISO8859-5
ru_RU.KOI8-R
I dont know if there are more to test with...
?>

Re: Proper months localisation

Posted: Fri Mar 11, 2011 4:58 pm
by LazyBadger
Timbalu wrote: You could make a testlocale.php with all possible russian locales and test them one by one
For all supported Russian locales I got identical result
Пятница, 11 Март 2011
as it shows Serendipity also

Re: Proper months localisation

Posted: Sun Mar 13, 2011 11:07 am
by Timbalu
LazyBadger wrote:For all supported Russian locales I got identical result
Well, it was worth a try.

I do understand that PHP delivers Март and you are saying it has to be Мартa, true?
That Март = March and марта = March, they are just special cases.

But I do not understand where you find a different language case in
Пятница, 11 Март 2011 and Пятница, 11 марта 2011?
In Germany there only 4 cases and in this case its all the same.

You were saying this problem is quite common. If it is a wrong language handling of PHP date and time functions, it shouldn't be common, it should happen everywhere where cyrillic is being used, true?

If this is true, please write a bugtracker notice to the PHP Developers.

Then we can go on writing a workaround for Serendipity.

What I need from you is a list of all 12 monthname 'oldMonthName' => 'newMonthName' eg
'January => 'January', February' => 'February', 'Март' => 'марта',
and so on please. If this is happening in other languages like Latvian, Bacque, Croatian, Estonian, Finnish, Galician, Portuguese too and you know which month case name is better, please tell us also and we can write an even better workround.

Re: Proper months localisation

Posted: Sun Mar 13, 2011 1:25 pm
by LazyBadger
Well, my rough blanks
lang/UTF-8/serendipity_lang_ru.inc.php

Code: Select all

...
$cased_month = array (
'Январь'		=>	"января",
'Февраль'		=>	"февраля",
'Март'		=>	"марта",
'Апрель'		=>	"апреля",
'Май'			=>	"мая",
'Июнь'		=>	"июня",
'Июль'		=>	"июля",
'Август'		=>	"августа",
'Сентябрь'		=>	"сентября",
'Октябрь'		=>	"октября",
'Ноябрь'		=>	"ноября",
'Декабрь'		=>	"декабря"
);
...
include/functions.inc.php

Code: Select all

...
function serendipity_monthCasing($datestring) { 
    return strtr($datestring,$cased_month)
}
...
templates/default/entries.tpl + entries_summary.tpl

Code: Select all

...
{...|@formatTime:DATE_FORMAT_ENTRY|@monthCasing}
...

Re: Proper months localisation

Posted: Sun Mar 13, 2011 3:11 pm
by Timbalu
modifier.localmonth.php in /bundled-libs/Smarty/libs/plugins/:

Code: Select all

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty localmonth modifier plugin
 *
 * Type:     modifier
 * Name:     localmonth
 * Purpose:  convert date strings month to correct case and lowercase
 * @author   Ian
 * @param string
 * @return string
Code:
{$variable|localmonth:"montharray":"rus":true}

*/

function smarty_modifier_localmonth( $monthdate, $newmonth=NULL, $lang="rus", $lower=false )
{
    // $monthdate => $variable aus template
    // $newmonth => $month array
    // $lang => "rus"

    if(!is_array($newmonth)) { 
        $newmonth = array (
              'Январь'      =>   "января",
              'Февраль'      =>   "февраля",
              'Март'      =>   "марта",
              'Апрель'      =>   "апреля",
              'Май'         =>   "мая",
              'Июнь'      =>   "июня",
              'Июль'      =>   "июля",
              'Август'      =>   "августа",
              'Сентябрь'      =>   "сентября",
              'Октябрь'      =>   "октября",
              'Ноябрь'      =>   "ноября",
              'Декабрь'      =>   "декабря" );
    }

    list($dayname,$day,$month,$year) = explode(' ', $monthdate);
	 foreach ($newmonth AS $k => $v) { 
		 if($k == $month) { $month = $v; }
	 }
	 $string = $dayname . ' ' . $day . ' ' . $month . ' ' . $year;
    if($lower) $string = strtolower($string);
    return (string)$string;
} 

?>
use as

Code: Select all

{$entry.timestamp|@formatTime:DATE_FORMAT_ENTRY|localmonth}

Re: Proper months localisation

Posted: Mon Mar 14, 2011 12:23 pm
by LazyBadger
Danke, it will work for me. But how we'll handle arrays for other languages ($$newmonth)? I.e - where to store hash-definitions (outside modifier code)
BTW - why not use strtr() insted of additional array and cycle? One-liner is more readable, at least

Re: Proper months localisation

Posted: Mon Mar 14, 2011 12:37 pm
by Timbalu
Well, my first idea was to send newmonth array to modifier by entries.tpl or config.inc.php, thats why. If we know all possible language arrays, better will be something like

Code: Select all

function smarty_modifier_localmonth( $monthdate='', $lang="rus", $lower=false )
        switch($lang) {
            case 'rus':
                $newmonth = array (.....);
                break;
            case 'fin':
                $newmonth = array (.....);
                break;
etc etc etc
}

One-liner? Sure, just replace with

Code: Select all

    $string = strtr($monthdate, $newmonth);
    if($lower) $string = strtolower($string);
    
    return (string)$string;