Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: [MOD] - Month names in your language  (Read 3741 times)

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
[MOD] - Month names in your language
« on: February 26, 2008, 08:49:34 pm »

The purpose of this MOD is to show the month names in your own language.

By default sNews has the following language array:

Code: [Select]
$l['month_names'] = 'January, February, March, April, May, June, July, August, September, October, November, December';

This is used only on the "Archive" page when the date format is cutted into more parts and so the array comes into the action. We will NOT use this array ;D, just telling you to know better this MOD and it's details :)

But what about if you are building for example a dutch website? The posting date of the articles will be shown in english.

ATTENTION: This MOD is needed only when you use the month names in the date as:

Ianuary, February, etc.

or

Ian, Feb, etc.

Because this word can be different in other languages than english.


So let's do the work:

Don't backup anything, we are PRO's  ;D and this action is not so dangerous  :)



ro_RO = set it to your needs dude! (http://www.php.net/manual/en/function.setlocale.php)
Blue lines = use this lines instead of black only if your local time is different on the time from the server! BUT!!! For this you will need to install also Ghassem's MOD from here http://snewscms.com/forum/index.php?topic=5999.0



Step 1. changing the date_format

Login into the administration panel of you site and at settings change the date_format in strftime time format. Examples you can find here: http://www.php.net/manual/en/function.strftime.php

Step 2. Articles listing, function center():

Find line:

Code: [Select]
$a_date_format = date(s('date_format'), strtotime($r['date']));
change it to:

Quote
setlocale(LC_ALL, "ro_RO");
 $a_date_format = strftime(s('date_format'),strtotime($r['date']));

or

Quote
setlocale(LC_ALL, "ro_RO");
$a_date_format = strftime(s('date_format'),strtotime($r['date'])+time_offset());

Step 3. function comment($freeze_status)

Find line:

Code: [Select]
$date = date($date_format, strtotime($r['time']));
change it to:

Quote
setlocale(LC_ALL, "ro_RO");
$date = strftime(s('date_format'),strtotime($r['time'])+time_offset());

or

Quote
setlocale(LC_ALL, "ro_RO");
$a_date_format = strftime(s('date_format'),strtotime($r['time'])+time_offset());

time - so it is stored the date in the comments, not date as in the articles, i don't know why, but is ok

Step 4. function menu_articles($start, $size) (no so important, just in case ... future plans ...)

Find line:

Code: [Select]
$date = date(s('date_format'), strtotime($r['date']));
change it to:

Quote
setlocale(LC_ALL, "ro_RO");
 $a_date_format = strftime(s('date_format'),strtotime($r['date']));

or

Quote
setlocale(LC_ALL, "ro_RO");
$a_date_format = strftime(s('date_format'),strtotime($r['date'])+time_offset());

Same also on function search(), function search_keywords($word) (if you have this), function admin_articles($contents).

Step 5. function rss_contents($rss_item, $artSEF='')

We have this line:

Code: [Select]
$date = date('D, d M Y H:i:s +0000', strtotime($r['time']));
if prefer:

Quote
setlocale(LC_ALL, "ro_RO");
 $a_date_format = strftime(s('date_format'),strtotime($r['time']));



Good luck! For questions i will be here. Thank you! :)
Logged
By(e) Henrich :)
------------------------------
IT related blog

dziegiel

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
    • http://bank.internetowy.waw.pl
Re: [MOD] - Month names in your language
« Reply #1 on: February 26, 2008, 10:32:33 pm »

It works!! Great!!!
Logged

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
Re: [MOD] - Month names in your language
« Reply #2 on: February 27, 2008, 12:11:55 am »

Good, i am happy that you find it useful :) For me it was a must, for a guy who pay attention to the details  ;D

If peoples from here will consider that the ro_RO or en_En or any other values must be stored in db just like the date_format, to be available for anyone to change it from the admin panel, then just tell me and i will expand this MOD.
Logged
By(e) Henrich :)
------------------------------
IT related blog

Pawel Landzberg

  • Newbie
  • *
  • Karma: 0
  • Posts: 16
    • Łuszczyca
Re: [MOD] - Month names in your language
« Reply #3 on: October 01, 2009, 01:34:38 pm »

Great mod but i had a small problem: my national characters in days of week and month didn't look correctly (insted of them there were squares with question mark).

I don't know PHP almost at all but I solved this problem by myself. The problem is that the date was coded in ISO-8859-2 and my site was coded in UTF-8.

Ok, anyway here's my solution (i based on Henrich mod and some site in Internet):

When i found this line:
Code: [Select]
$a_date_format = date(s('date_format'), strtotime($r['date']));
I replaced it with this:
Code: [Select]
$arrLocales = array('pl_PL', 'pl','Polish_Poland.28592');
setlocale(LC_ALL, $arrLocales);
$a_date_format = iconv("ISO-8859-2","UTF-8",ucfirst(strftime(s('date_format'),strtotime($r['date']))));

And when found this:
Code: [Select]
$date = date($date_format, strtotime($r['time']));
I replaced with this:
Code: [Select]
$arrLocales = array('pl_PL', 'pl','Polish_Poland.28592');
setlocale(LC_ALL, $arrLocales);
$date = iconv("ISO-8859-2","UTF-8",ucfirst(strftime(s('date_format'),strtotime($r['date']))));

Site which i used (not english):http://blog.vokiel.com/php-date-polskie-nazwy-dni-i-miesiecy-funkcje-date-strftime

Works for me. I was tested it in 1.7 version.
Hope it'll help someone
Logged

jesth

  • Jr. Member
  • **
  • Karma: 1
  • Posts: 66
Re: [MOD] - Month names in your language
« Reply #4 on: July 27, 2010, 04:01:24 pm »

In step 3:
Code: [Select]
$date = date($date_format, strtotime($r['time']));You told to change it to:
Code: [Select]
$date = strftime(s('date_format'),strtotime($r['time'])+time_offset());Which is not working for me, it's giving a semi-blank page when clicking comments.

My solution which works for me, was to change:
Code: [Select]
$date = date($date_format, strtotime($r['time']));to
Code: [Select]
$date = strftime($date_format, strtotime($r['time']));
*EDIT* Damn, didn't see this was for sNews 1.6 anyways, my "fix is for sNews 1.7
« Last Edit: July 28, 2010, 12:52:56 pm by jesth »
Logged