1

I'm trying to output a date like this for instance:

{{ now|date('l, j-m-Y') }}

This outputs the date in my standard language. I need it output on the same page in English too. Is this possible?

2

The Craft/Twig dateFilter that you're using will currently only translate the string into the current locale the site is set to.

You could probably write a plugin that added its own Twig Extension that added its own filter... let's call it |translatedDate and you could pass in the target locale code as a parameter |translatedDate('en_us').

That filter would do something like:

$currentLanguage = craft()->getLanguage();
craft()->setLanguage('en_us');
...
// Do logic similar to Craft's existing date filter
...
craft()->setLanguage($currentLanguage);
| improve this answer | |
  • Thanks Brad, I started with the plugin, but with my next level php skills ;-) eventually decided to just pickup the local date and translate that in the template (see underneath) – noregt Jan 2 '17 at 11:43
1

I decided to do the translation in the template itself. So if the local is in Dutch but I want to use English:

{% set dag = now|date('l' ) %}    
{% set maand = now|date('F' ) %}                                  
{% switch dag %}
    {% case "maandag" %}
       {% set EnDag = 'Monday' %}
    {% case "dinsdag" %}
        {% set EnDag = 'Tuesday' %}
    {% case "woensdag" %}
        {% set EnDag = 'Wednesday' %}
    {% case "donderdag" %}
        {% set EnDag = 'Thursday' %}
    {% case "vrijdag" %}
        {% set EnDag = 'Friday' %}
    {% case "zaterdag" %}
        {% set EnDag = 'Saturday' %}
    {% case "zondag" %}
        {% set EnDag = 'Sunday' %}
{% endswitch %}
 {% switch maand %}
    {% case "januari" %}
       {% set EnMaand = 'January' %}
    {% case "februari" %}
        {% set EnMaand = 'February' %}
    {% case "maart" %}
        {% set EnMaand = 'March' %}
    {% case "april" %}
        {% set EnMaand = 'April' %}
    {% case "mei" %}
        {% set EnMaand = 'May' %}
    {% case "juni" %}
        {% set EnMaand = 'June' %}
    {% case "juli" %}
        {% set EnMaand = 'July' %}
    {% case "augustus" %}
        {% set EnMaand = 'August' %}
    {% case "september" %}
        {% set EnMaand = 'September' %}
    {% case "oktober" %}
        {% set EnMaand = 'October' %}
    {% case "november" %}
        {% set EnMaand = 'November' %}
    {% case "december" %}
        {% set EnMaand = 'December' %}
{% endswitch %}                                       
{# output the day #}
{{EnDag}}, {{EnMaand}} {{day.date.format('j, Y')}}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.