Proper months localisation

Discussion corner for Developers of Serendipity.
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post 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
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post 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?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post 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
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post 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?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post 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)
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post by Timbalu »

What is the trouble with your modifier.localmonth.php in Smarty plugin and a $serendipity['smarty']->register_modifier('localmonth', 'localmonth'); ?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post 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
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post 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).
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post 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...
?>
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post 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
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post 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.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post 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}
...
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post 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}
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post 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
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post 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;
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Post Reply