Proper months localisation

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

Proper months localisation

Post by LazyBadger »

OK, I cast Garvin or somebody with power in Smarty!
Because strftime (behind formatTime:DATE_FORMAT_ENTRY) even with setlocale() doesn't do (and can't) it excellent for languages, which have cases forms (Kasusendungen, Ich richtig gesagt?). %B always generates ucfirst'ed nominative, but language rules may require different form - lowercased genitive , f.e for Russian and some other East European languages.
I know, it can be easy solved by additional modifier (it's one-string-function in pure PHP)

Code: Select all

return strtr(date(....), $langmonth);
where $langmonth is hash from serendipity_lang_*.inc.php with bad and good month's writing, but - how to get this array inside new Smarty-modifier definition?

Just example
Четверг, 3 Март 2011 => Четверг, 3 марта 2011
Quis custodiet ipsos custodes?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Proper months localisation

Post by garvinhicking »

Hi!

Wow. I don't unterstand a thing. ;)

You can create/edit a custom config.inc.php file inside your template's directory, and add a code like this:

Code: Select all

<?php
function mydate($timestamp)  {

  return strtr(...);
}

$serendipity['smarty']->register_modifier('mydate', 'mydate');
and then in smarty, everywherre you want your custom date you can use {$entry.timestamp|@mydate}...

Does that help?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post by LazyBadger »

garvinhicking wrote: ...
Does that help?
Somehow,partially. Because:
- I see it not only as my personal problem, but - rather common situation here, and template-based modifier will not solve it for everybody;
- I haven't troubles to place my modifier in bundled-libs/Smarty/libs/plugins/modifier.localmonth.php, but still have the same missing of knowledge - how (correctly) have array from lang-file accessible from my code (I didn't read source, I don't know, are there all constants from lang-files GLOBAL or smth. else).

Is it more clean now?
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 didn't read source, I don't know, are there all constants from lang-files GLOBAL or smth. else).
Is it more clean now?
Not really. ;-)
You can access CONSTANTS globally if set by serendipity (and plugins?). But why in modifiers?
To come back to you problem...
You mean eastern blogs get month names as a short version like 'Mar' and you would like to have 'March'?
Where does that happen?
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: Not really. ;-)
Going to knock my head against the wall, completely forgotten how to clearly explain the problem :-(
Timbalu wrote:You mean eastern blogs get month names as a short version like 'Mar' and you would like to have 'March'?Where does that happen?
Not exactly, %B from '%A, %e %B %Y' (DATE_FORMAT_ENTRY) in {$entry.timestamp|@formatTime:DATE_FORMAT_ENTRY} shows full month name, as it must be, but with uppercased fist letter and nominative (it's correct for %B and strftime), when correct form (in context) is lowercase genitive. It happens in entries.tpl,when I have to output date. Compare char-by-char (top-right on page)
Понедельник, 7 Март 2011
Понедельник, 7 марта 2011

if I'll add one more pipe to $entry.timestamp, I'll solve problem globally
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post by Timbalu »

Ah I see, and the modifier lower, the smarty equivalent to PHPs strtolower()

Code: Select all

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

is not working as expected?

Edit: The month name is not a CONSTANT, it is PHP internally build in and cannot be modified directly. But you can modify the result like lower, upper, etc.
Last edited by Timbalu on Thu Mar 10, 2011 10:29 am, edited 1 time in total.
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 »

You could even use CSS

Code: Select all

.serendipity_entryFooter .YOUR_PLACE { text-transform: lowercase; /* force text to lower */ }
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:Ah I see, and the modifier lower, the smarty equivalent to PHPs strtolower()
But still in incorrect casing. To avoid scaring the Cyrillic alphabet, show example without it
Martā, Marts 7 - March, March 7 (Latvian)
Martxa, martxoaren 7 - March, March 7 (Bacque)
U ožujku, 7. ožujka - March, March 7 (Croatian)
Märtsil. 7. märts - March. March 7 (Estonian)
Maaliskuuta. 7 maaliskuu - March. March 7 (Finnish)
Marzo. 7 de marzo - March. March 7 (Galician)
Março. 7 de março - March. March 7 (Portuguese)
Quis custodiet ipsos custodes?
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper months localisation

Post by LazyBadger »

Timbalu wrote: Edit: The month name is not a CONSTANT
I can add my own data to lang-file, and I think about hash with months names 'before'=>'after'
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post by Timbalu »

Interesting, but Confusing!
I still do not understand what you mean with casing?
What you have and what you want?
Why you are talking about constants at all? Edit:(ok I missed your second answer)-but why can't you use the upsizing or downsizing features via smarty or css?
???
'M' seems to be latin not Cyrillic, 'GMail' in text ist latinized, Cyrillic text is flatened, but 'В' and 'Ф' in Воскресенье, 27 Февраль 2011, need to get sized down, is that right?

Did you try with |upper ?
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 »

If I use CSS at you site

Code: Select all

.serendipity_date {
    text-transform: lowercase;
}
it looks quite ok for me.....
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:Interesting, but Confusing!
I still do not understand what you mean with casing?
Buchen liegt.
Ich legte das Buch.
Ich bin zufrieden mit dem Buch
What you have and what you want?

Get date according to local language rules instead of formal translation for now
Cyrillic text is flatened, but 'В' and 'Ф' in Воскресенье, 27 Февраль 2011, need to get sized down, is that right?
No, do nothing with weekday name, modify only month
Февраль - февраля
In Bacque example (for pure US-ASCII): Martxa -> 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:
What you have and what you want?

Get date according to local language rules instead of formal translation for now
No, do nothing with weekday name, modify only month
Ahhh, now the clouds are clearing up for me.
This seems to me like a PHP problem you should give back to the PHP developers, if the date('B') does not follow your local language rules.
Did you try something with you locale?

Code: Select all

  $locale = 'Czech_Czech.1250';
  $res = setlocale( 'LC_CTYPE', $locale); //important
  $res = setlocale( 'LC_TIME', $locale);
  echo strftime( '%A %m. %B %Y', mktime( 0,0,0,9,6,2001));
If this is all useless you have to modify the Smarty formatTime modifier or create your own as adviced by Garvin.
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: Did you try something with you locale?
Serendipity do it for me even now in serendipity_config.inc.php,without it I'll get only English names
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper months localisation

Post by Timbalu »

Just dropped in again with another :idea: idea.... :)

How about doing some sort of splitting the DATE_FORMAT_ENTRY in the lang en file or in your custom config.inc.php file

Code: Select all

@define('DATE_FORMAT_SPLIT_ENTRY_DAY', ''%A, %e');
@define('DATE_FORMAT_SPLIT_ENTRY_MONTH', ''%B');
@define('DATE_FORMAT_SPLIT_ENTRY_YEAR', ''%Y');
and in entries.tpl

Code: Select all

{$entry.timestamp|@formatTime:DATE_FORMAT_SPLIT_ENTRY_DAY|@formatTime:DATE_FORMAT_SPLIT_ENTRY_MONTH|lower|@formatTime:DATE_FORMAT_SPLIT_ENTRY_YEAR} 
This should do what you want... :?:
Regards,
Ian

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