Author Topic: Translation of dates  (Read 1014 times)

Offline rumen

  • Posts: 399
Translation of dates
« on: February 19, 2019, 04:03:21 PM »
I noticed that months are not translated in some modules like News module for example, but they does not exist in the language file as they are in the My Calendar for example. Where that months are located to translate them in the multi language sites? I could not find them anywhere and also here in the forum did not find any info about that. Maybe I didn't search as needed but ...

Regards, 

Offline jacobi22

  • Posts: 5879
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Translation of dates
« Reply #1 on: February 19, 2019, 04:17:09 PM »
normalize, the date-part like day or month come's from the PHP-date-function and you need a setlocale-definition in your initialize.php  ~ Ln 290 (see the deactivated lines there) or try to add there this line

Code: [Select]
setlocale (LC_ALL, 'bg_BG');

but the jquery and the js-calendar has language files and maybe, the problem is solved, if you add there a translation

for jquery in include/jquery/i18n

for js-calendar ininclude/jscalendar/lang

both addons has a bulgarian translation
Wer nicht will, findet Gründe, wer will, findet Wege.

Offline zirzy

  • Posts: 168
Re: Translation of dates
« Reply #2 on: February 20, 2019, 12:32:10 PM »
Hi,

Yes, I got the same problem with news..

Is this initialize.php in framework folder? If yes, there was no deactivated lines on line ~ 290 what was telling something about time and date format.. On line ~ 500 is time and date but no deactivated lines.. I don't know if this is correct but I inserted code to line 504 and now it's working  (Y)

Offline jacobi22

  • Posts: 5879
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Translation of dates
« Reply #3 on: February 20, 2019, 12:52:27 PM »
ah... sorry, it was a older initialize.php with this comment

actual version WB 2.12.1 - /framework/ initialize.php  behind this ~Ln 319

Code: [Select]
    \date_default_timezone_set('UTC');

that's a good place, but you lost it in the next upgrade. normalize, it doesn't matter, where you are in the initialize. important is, that you're not inside of a function there

in my test's, it works also, if i add this line in the top of my template-index.php, maybe, somebody can confirm this - looks for me as the best solution
Wer nicht will, findet Gründe, wer will, findet Wege.

Offline zirzy

  • Posts: 168
Re: Translation of dates
« Reply #4 on: February 20, 2019, 02:29:15 PM »
Thanks jacobi22  (Y)

Offline rumen

  • Posts: 399
Re: Translation of dates
« Reply #5 on: February 20, 2019, 03:58:09 PM »
I put the code there but there are no changes still the same settings.  Cleared the cache but no any effect. 

Offline jacobi22

  • Posts: 5879
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Translation of dates
« Reply #6 on: February 20, 2019, 05:57:58 PM »
i'm thinking about this and play a little bit...
from my eyes (at the moment)...
-
- if you use setlocale as global definition (like my words in the top) in framework/initialize.php or index.php from the template, you get a problem on multi-lingual pages, because, then, i get also my localistation on pages with other languages, that means, a bulgarian date like 20 февруари 2019, 17:11 is also visible, if you visit the english news

so i build this code for the view.php from the news module - dont forget, it is lost in the next upgrade  :-(

in my example project, i use german, italien and bulgarian as languages

go into modules/news/view.php and search for this line  (~ 327)

Code: [Select]
$publ_date      = date(DATE_FORMAT,$post['published_when']+TIMEZONE);
add this code in the next line(s)

Code: [Select]
if(LANGUAGE == 'DE'){
                    $locale = 'de_DE.UTF-8';
                    setlocale(LC_ALL, $locale);
                    $publ_date      = strftime('%d %B %Y', strtotime($publ_date));
                }
                elseif(LANGUAGE == 'IT'){
                    $locale = 'it_IT.UTF-8';
                    setlocale(LC_ALL, $locale);
                    $publ_date      = strftime('%d %B %Y', strtotime($publ_date));
                }else{
                    $locale = 'bg_BG.UTF-8';
                    setlocale(LC_ALL, $locale);
                    $publ_date      = strftime('%d %B %Y', strtotime($publ_date));
                }
Dont forget to change the setlocale-Definition. see here the language code -> https://www.w3.org/WAI/ER/IG/ert/iso639.htm and use lower and Upper Letters like the example

if you need only two languages, remove the elseif-part in the middle. if you need more languages, copy the elseif-Part in the middle
Important!!:  Use your default-Language (see WB-settings) in the else-Part as last option

Results:

Bulgarian


Italian

Wer nicht will, findet Gründe, wer will, findet Wege.

Offline rumen

  • Posts: 399
Re: Translation of dates
« Reply #7 on: February 20, 2019, 07:16:42 PM »
WORKS PERFECT!

Thanks a lot mate!

 

postern-length