These are chat archives for locomotivecms/v3

8th
Mar 2016
ljromero
@ljromero
Mar 08 2016 09:36
Hi everybody, is there some way to specify one format for each language to apply to all the localized dates? Maybe, javascript it's the only solution?
ljromero
@ljromero
Mar 08 2016 10:38
JS solution (if it helps someone)...
      $('.js-date').each(function() {
        var date = new Date($(this).html());
        var options = { year: 'numeric', month: 'long', day: 'numeric' }
        $(this).html( date.toLocaleDateString(navigator.language, options) );
      });
Didier Lafforgue
@did
Mar 08 2016 11:05
@ljromero What does your liquid code look like?
ljromero
@ljromero
Mar 08 2016 11:26

@did I want to apply different date format for each language. Ex:

      %p.js-date {{ news.date | localized_date: '%m/%d/%Y'}}   #if current_locale == 'en'
      %p.js-date {{ news.date | localized_date: '%d de %B de %Y'}}   #if current_locale == 'es'

Maybe the solution is to localize the date attribute in the content type.

milanvanzanten
@milanvanzanten
Mar 08 2016 11:33
I guess you could just actually put these ifs in front of the tags..?
ljromero
@ljromero
Mar 08 2016 11:49
@milanvanzanten Yes, but I try to avoid repeating this few lines for each date I add to any haml.
Didier Lafforgue
@did
Mar 08 2016 13:34
@ljromero got it
why not using a translation for that purpose?
{% assign date_form = ‘date_format’ | translate | default: '%m/%d/%Y’ %}
%p.js-date {{ news.date | localized_date: date_form }}
ljromero
@ljromero
Mar 08 2016 14:43

@did Awsome! I had not thought concatenate filters!
Only two syntax differences to run in wagon 2.0.0

{% assign date_form = "date_format" | translate: default: "%m : %d : %Y" %}

Thank you so much.

Didier Lafforgue
@did
Mar 08 2016 14:44
you’re very welcome!