HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

Change date format...

Good afternoon from Spain,

Please see if somebody could help me ...

Does not work the setlocale() function for spanish, still showing the date in English.
How I can display it in Spanish? Example: Diciembre instead of December.

Another question: How I can show 'one day ago' or a 'five minutes ago' or ... instead of the exact date?

I hope your answer.

Regards, Kokudroid

PD: Sorry for my English.

Tagged:

Comments

  • peregrineperegrine MVP
    edited December 2012

    ♦locales:

    http://vanillaforums.org/addon/vf_ca_es-locale
    http://vanillaforums.org/addon/spanish-locale

    ♦plugins:
    http://vanillaforums.org/addon/timeago-plugin

    or search for timeago for other options.

    ♦documentation for locales and internationalization

    http://vanillaforums.org/docs

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • AnonymooseAnonymoose ✭✭
    edited December 2012

    I'm having the same problem, not just with Spanish. The definitions for dates in the locales don't work.

  • peregrineperegrine MVP
    edited December 2012

    unless somebody comes up with a better idea.

    I believe that has to do with your server and the way date routine strftime, etc. works in php based on setlocale function.

    copy and paste this line to a file e.g. mylocalecheck.php

    on a linux based server:

    <?php system('locale -a') ?>

    this will show you the locales you have available. you may need to install a language pack for your server or generate a locale for your server os.

    or modify the date format routine to substitute months for your language..

    for windows you need to google for country region string setting.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited December 2012

    for mine I added the OS specific spanish locale language pack (not to be confused with vanilla locale addons).

    for a test of locale after I added the language pack for my server I tired this

    <?php
    /* Set locale to Spanish */
    setlocale(LC_ALL, 'es_ES.utf8');
    
    
    echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 13, 2012));
    
    /* try different possible locale names for spanish  */
    $loc_spanish = setlocale(LC_ALL, 'es_ES.utf8', 'es_ES', 'es');
    
    
    echo "</br>Preferred locale for spanish on this system is '$loc_spanish'";
    ?>
    

    which output

    jueves 13 diciembre 2012
    Preferred locale for spanish on this system is 'es_ES.utf8'

    after I knew that displayed correctly i changed this in the spanish transiflex
    definitions.php

    then added

    <?php
    
     $LocaleInfo['vf_ca_ES'] = array (
      'Locale' => 'ca-ES',
      'Name' => 'Catalan (Spain) Transifex',
      'Description' => 'Catalan (Spain) language translations for Vanilla. Help contribute to this translation by going to its translation site <a href="https://www.transifex.com/projects/p/vanilla/language/ca_ES/">here</a>.',
      'Version' => '2012.10.05p1534',
      'Author' => 'Vanilla Community',
      'AuthorUrl' => 'https://www.transifex.com/projects/p/vanilla/language/ca_ES/',
    );
    
    /added this line to the transiflex
    setlocale(LC_ALL, 'es_Es.utf8');
    

    and a mod for above suggestion - add the ;
    <?php system('locale -a'); ?>

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Thanks, I've tried everything but the locales still don't work.

  • peregrineperegrine MVP
    edited December 2012

    Thanks, I've tried everything but the locales still don't work.

    "everything???"

    post your results from

    list-locales.php (if you have a linux server).

    <?php system('locale -a'); ?>

    A) nobody can help you unless you specify

    1) your server os,
    2) what web server and what locales you have available.
    3) Also provide what you have in config.php with respect to:

    $Configuration['Garden']['Locale']
    $Configuration['EnabledLocales']
    4) you might also include your vanilla version of software - always a good idea.

    You are not helping yourself without providing more info.

    B) short of that write a little routine in php after the date is returned and change it to what you want if you can't get locales working the way it should.

    C) if it is not your server, ask your host provider to add the locale.

    D) hire someone on this forum to write a plugin or some code to write a routine to change month names for you - if you can't get the locale working the proper way through setlocale - with the proper language packs as specified here:

    E) or change the date format to only display month numbers instead of names.
    e.g. 3-3 instead of March 3

    http://vanillaforums.org/discussion/comment/171772/#Comment_171772

    setlocale(LC_ALL, 'es_ES.utf8', 'es_ES', 'es', 'esn', 'spanish');

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • kokudroidkokudroid New
    edited December 2012

    Thanks Peregrine for your help.

    My server is XAMPP.

    In my config.php:

    // EnabledLocales
    $Configuration['EnabledLocales']['vf_es_ES'] = 'es-ES';

    // Garden
    $Configuration['Garden']['Locale'] = 'es-ES';

    // Vanilla
    $Configuration['Vanilla']['Version'] = '2.0.18.4';

    I have tried your code:

    <?php

    setlocale(LC_ALL, 'es_ES.utf8');
    echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 13, 2012));
    $loc_spanish = setlocale(LC_ALL, 'es_ES.utf8', 'es_ES', 'es');
    echo "Preferred locale for spanish on this system is '$loc_spanish'";
    ?>

    which output is

    Thursday 13 December 2012
    Preferred locale for spanish on this system is ''

    For now the solution E) is easiest.

    Thanks again. Try other alternatives later.

  • AnonymooseAnonymoose ✭✭
    edited December 2012

    But shouldn't this be something that should be overridden with the script's locale file, no matter what sort of date formatting the server provides?

  • peregrineperegrine MVP
    edited December 2012

    @Anonymoose said:
    But shouldn't this be something that should be overridden with the script's locale file, no matter what sort of date formatting the server provides?

    One could ask why should vanilla forums attempt to fix something that is broken on your server. You should install locales for your server os correctly if you run the server or ask your host provider to install the proper locale. Although, otoh ....

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited December 2012

    Assuming you have no control over correctly installing locales on your server you could do this. Although you know what they say about mods to the core.

    I suppose you would need some modification to the core to make it work.

    worked for me.

    library/core/class.format.php around  line 485
    

       
        replacing
          if ($Html) {
                 $Result = Wrap($Result, 'span', array('title' => strftime($FullFormat, $Timestamp)));
              }
         return $Result;
     

    with
    

       
        if ($Html) {
                 $Result = Wrap($Result, 'span', array('title' => strftime($FullFormat, $Timestamp)));
              }
             
          // added monthset config if statement
              if (C('Garden.MonthSet')) {
                    $patterns = array('/January/','/February/','/March/','/April/','/May/','/June/','/July/','/August/','/September/','/October/','/November/','/December/');
                   $replacements = C('Garden.MonthSet');
        
                   $Result = preg_replace($patterns,$replacements, $Result);
                    }
         
        return $Result;
     

    and add this to your config.php (with your custom months e.g.'diciembre')

        
        $Configuration['Garden']['MonthSet'] = array('MyJanuary','MyFebruary','MyMarch','MyApril','MyMay','MyJune','MyJuly','MyAugust','MySeptember','MyOctober','MyNovember','diciembre');
    
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    Anonymoose
  • Thank you!

    peregrine
  • AnonymooseAnonymoose ✭✭
    edited December 2012

    @peregrine said:
    You should install locales for your server os correctly if you run the server

    I install locales on Vanilla. These should override everything else going on. For example, my Emoji locale, with symbols instead of words.

    None of these definitions in the locale file work, but I found them in locales that can be downloaded here. Do they require a plugin? Or a different version of Vanilla?

    $Definition['(YYYY-mm-dd)'] = ' (YYYY-mm-dd)';

    $Definition['Date.DefaultDayFormat'] = '📆 %A %e 🕐 %H:%M';

    $Definition['Date.DefaultFormat'] = '%h %i, %Y, 🕐 %H:%M';

    $Definition['Date.DefaultTimeFormat'] = '🕐 %H:%M';

    $Definition['Date.WeekdayNames'] = array("&#9318;","&#9312;","&#9313;","&#9314;","&#9315;","&#9316;","&#9317;"); 
    $Definition['Date.WeekdayShortNames'] = array("&#9318;","&#9312;","&#9313;","&#9314;","&#9315;","&#9316;","&#9317;");
    $Definition['Date.MonthNames'] = array("01","02","03","04","05","06","07","08","09","10","11","12");
    $Definition['Date.MonthShortNames'] = array("01","02","03","04","05","06","07","08","09","10","11","12");
    
  • peregrineperegrine MVP
    edited December 2012

    @Anonymoose said that
    @peregrine said: You should install locales for your server os correctly if you run the server

    and then @Anonymoose replied

    I install locales on Vanilla. These should override everything else going on. For example, my Emoji locale, with symbols instead of words.

    and then @peregrine further replied in his last reply on this discussion :)

    @Anonymoose
    You are beating a dead horse, or you don't understand the concept.

    Unless you make custom modifications - you will need to get "the setlocale" function working properly on your webserver. ` The folks at vanilla decided to base dates on setlocale and strftime. if you cannot display the days and date properly in the following non-vanilla based script you did not install the regional or country locales in windows or linux, or whatever on your server.

    google setlocale strftime

    replace with your appropriate language.

    <?php 
    setlocale(LC_ALL, 'es_ES.utf8');
    echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 13, 2012)); 
    $loc_spanish = setlocale(LC_ALL, 'es_ES.utf8', 'es_ES', 'es');
    echo "</br>Preferred locale for spanish on this system is '$loc_spanish'"; 
    ?> 
    

    if you did not see your language - you need to adjust your server locales.
    Server locales are a different animal then vanilla locales.

    On Windows, setlocale(LC_ALL, '') sets the locale names from the system's regional/language settings (accessible via Control Panel).

    http://us3.php.net/manual/en/function.setlocale.php
    

    on a linux based server:

    <?php 
    echo "display all available locales on a linux based server";
    system('locale -a') 
    ?> 
    


    I searched for Date.MonthNames and found this discussion
    This is a very good write-up on date localization. If I would have seen this discussion before, I would just posted the link instead of pursuing this discussion, because it says it all there clearly. It is up to you whether you want to digest it and accept it.

        http://vanillaforums.org/discussion/11275/dates-localization
    

    I already explained the ready of definitions and the order for you, if you did not see it - it is here.

         http://vanillaforums.org/discussion/comment/170146/#Comment_170146
    

    over and out...

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • AnonymooseAnonymoose ✭✭
    edited December 2012

    @peregrine said:
    The folks at vanilla decided to base dates on setlocale and strftime

    Well then it is a bug that impedes localization efforts, plain and simple.

  • hbfhbf wiki guy? MVP

    @Anonymoose said:
    Well then it is a bug that impedes localization efforts, plain and simple.

    there's a difference between a bug and a design decision, good bad or indifferent, it's working as designed.

    just make the changes to core, and submit a pull request.

  • peregrineperegrine MVP
    edited December 2012

    @hbf said:
    just make the changes to core, and submit a pull request.

    if he did that - he couldn't carp on the discussion thread. Then what would be the fun.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • AnonymooseAnonymoose ✭✭
    edited December 2012

    @peregrine said:
    if he did that - he couldn't carp on the discussion thread. Then what would be the fun.

    That's for people involved with developing vanilla to do. The purpose of a support forum is to relay other people's feedback to the developers to do something. I'm sorry you feel the need to somehow insult those who aren't actively involved at your level in your coding projects.

  • peregrineperegrine MVP
    edited December 2012

    @Anonymoose said:

    That's for people involved with developing vanilla to do. The purpose of a support forum is to relay other people's feedback to the developers to do something. I'm sorry you feel the need to somehow insult those who aren't actively involved at your level in your coding projects.

    Perhaps, i did poke fun at you, my apologies. It just seems sometimes you are not looking for a solution to a problem, but occasionally you tend to be "tenacious" on something that the developers have already "decided upon". The point being either enter a problem on github, or use the feedback discussion category. Posting in a thread of a question submitted by someone else may not be read by the designers of vanilla. Sometimes, one has to live with the decisions made by the designers or you would need to make the code changes presented (assuming they work for you), if you feel they are necessary for your forum.

    As far as your emoji questions - i have no idea. I don't use it.

    I do agree with you about

    impedes localization efforts, plain and simple.

    perhaps the designers have designed it the way they did for efficiency and performance.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    AnonymooseUnderDog
  • Please can you add one features, if the post is older the say 3 months, nothing is displayed. As I have loads of old posts and would prefer it not to say 'Posted 10 years ago', I'd prefer nothing.

  • R_JR_J Ex-Fanboy Munich Admin

    You would have to write a function for that. Create a file /conf/bootstrap.before.php and create public function FormatDateCustom($Timestamp, $Format) in there and see if you can achieve what you like. Look at /library/core/class.format.php for inspirations how Vanilla does formatting

    hgtonight
Sign In or Register to comment.