0
Welcome Guest! Login
0 items Join Now

Date issue in Joomla Articles particule for other language

  • Re: Date issue in Joomla Articles particule for other language

    Posted 7 years 5 months ago
    • Hi Damir

      problemetic, no milestone about this project

      means I will need to change my mind in current website projects

      take care

      Bertrand
    • www.en-toutes-lettres.fr
  • Re: Date issue in Joomla Articles particule for other language

    Posted 7 years 3 months ago
    • The main problem is that Twig just uses the date function.

      As the manual say ( php.net/manual/en/function.date.php ),
      To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

      A possible solution would be to add a strftime extension to Gantry's Twig ( github.com/teraone/twig-strftime-extension ) and use it, instead of date, in the templates.

      In my case, media/gantry5/engines/nucleus/particles/contentarray.html.twig.
  • Re: Date issue in Joomla Articles particule for other language

    Posted 7 years 2 months ago
    • Ooops i come back to this topic
      i did not seen your answer

      can you be more clear, please

      What i have to change in the twig file ?
      {% if display.date.enabled %}
      <span class="g-array-item-date">
      {% if display.date.enabled == 'published' %}
      <i class="fa fa-clock-o" aria-hidden="true"></i>{{ article.publish_up|date(display.date.format) }}
      {% elseif display.date.enabled == 'modified' %}
      <i class="fa fa-clock-o" aria-hidden="true"></i>{{ article.modified|date(display.date.format) }}
      {% else %}
      <i class="fa fa-clock-o" aria-hidden="true"></i>{{ article.created|date(display.date.format) }}
      {% endif %}
      </span>
      {% endif %}

      i have to install something (teraone/twig-strftime-extension) and how?
      or add a line in the twig file too ?

      thanks

      take care

      Bertrand
    • www.en-toutes-lettres.fr
  • Re: Date issue in Joomla Articles particule for other language

    Posted 7 years 1 month ago
    • Hi Bertrand,
      I think the best solution would be to install the twig extension.But since I don't know how Gantry works (I use Twig in symfony and there it would not be a problem), I choosed a second, dirty, solution.

      The solution I propose has three pitfalls:
      • It will be ovrwritten on every gantry upgrade
      • You need to manually give the translation
      • It is specific for the "15 February 2017" format

      You have to edit libraries/gantry5/classes/Gantry/Component/Twig/TwigExtension.php

      Add a new filter at line 58:
      new \Twig_SimpleFilter('array', [$this, 'arrayFilter']),
      new \Twig_SimpleFilter('data_trans', [$this, 'dataTransFilter']), //This is the new filter

      Then define the new function for the translation:

          public function dataTransFilter($str)
          {
              // Italians months
              $mesi =   ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'];
              $months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
      
              return str_replace($months, $mesi, $str);
          }
      

      The last thing you have to do is update the media/gantry5/engines/nucleus/particles/contentarray.html.twig file:
      <span class="g-array-item-date">
        {% if display.date.enabled == 'published' %}
            <i class="fa fa-clock-o"></i>{{ article.publish_up|date(display.date.format)|data_trans }}
        {% elseif display.date.enabled == 'modified' %}
            <i class="fa fa-clock-o"></i>{{ article.modified|date(display.date.format)|data_trans }}
        {% else %}
            <i class="fa fa-clock-o"></i>{{ article.created|date(display.date.format)|data_trans }}
        {% endif %}
      </span>

      But, as I sayd before, it's a dirty solution.
    • Last Edit: 7 years 1 month ago by Luca Saba.
    • The following users have thanked you: Bertrand Pascal

  • Re: Date issue in Joomla Articles particule for other language

    Posted 7 years 1 month ago
    • Hi Luca
      works well
      Many thanks, it is the first clear and usable solution on this topic i read (i will write an article about that)

      An overide of the contentarray.html.twig file works also (add modified file in template/custom/particles/contentarray.html.twig)
      so one less file to update on every Gantry 5 update
      but sure it is an dirty solution especialy at this moment where Gantry 5 is updaded oftently due to Grav implementation

      Hope RT team will found a best solution soon

      have a nice sunday

      take care

      Bertrand
    • The following users have thanked you: Luca Saba

    • www.en-toutes-lettres.fr

Time to create page: 0.046 seconds