I guess this is not really an issue with this module but more of a consideration

ran the installation and got
RuntimeException: The intl extension is needed to use intl-based filters. in Twig_Extensions_Extension_Intl->__construct() (line 17 of vendor/twig/extensions/lib/Twig/Extensions/Extension/Intl.php).

PHP intl extension is missing well at least on my defualt setup.

CommentFileSizeAuthor
#14 2694185-14.patch2.09 KBjoelpittet
#5 2694185-5.patch1.33 KBjoelpittet

Comments

mortendk created an issue. See original summary.

rene bakx’s picture

The problem is that not all PHP Installations have the INTL extension enabled by default. To overcome this issue, Symfony developers created to Internationalization shiv/polyfill (yes we have them in backend to!)

See https://packagist.org/packages/symfony/intl

The downside of the shiv, it's limited to english locale, which makes it practically unusable in Drupal land.

However of all the extensions that come with the Symfony2 Twig extensions, the Internationalization is the one that is the least usable in Drupal because we run our own i18n system.

afoster’s picture

Just wanted to note that we needed to install the intl shim to get twig_extensions module to work on pantheon .io.

Fortunately it was for a english-only website so it does the trick.

jdleonard’s picture

I also just encountered this on Pantheon. Installing symfony/intl resolved the issue for me.

I'm not sure whether this is feasible, but, given that this is not an uncommon problem, I wonder whether it would make sense to add a user configurable setting to enable/disable the instigating localizeddate Twig filter.

joelpittet’s picture

StatusFileSize
new1.33 KB

This may work, lightly tested but it avoids registering the intl service if the PHP extension's class doesn't exist.

joelpittet’s picture

Status: Active » Needs review
solide-echt’s picture

I've applied the patch from #5 and the install finished. However, I can not get this to work - or maybe it's just me not able to figure it out. What I want to accomplish is present a date range value with a localized representation of a date value in a view.

When I override a view field template to override a date (the created date of the node; in the view represented as this HTML DateTime) this works:
{{ output|date("m-d-Y") }}
However, trying to apply a localized date like:
{{ output|localizeddate("medium", "none", null, null, "m-d-Y") }}
throws me a
Twig_Error_Syntax: Unknown "localizeddate" filter. in Twig_ExpressionParser->getFilterNodeClass() (line 26 of sites/optisport.nl/themes/optisport/templates/views-view-field--location--rooster--created.html.twig).

I did a composer require twig/extensions before installing and enabling the module.

I'm not sure if this means the patch is not fully working for views, I've skipped a step somewhere or my template is plain wrong...

Eric

joelpittet’s picture

The above patch ensures that the module works but if you don't have the intl PHP extension it will not enable the intl Twig extension.

I could put a drupal status page warning if you think that would help? Or a watchdog log message?

jdleonard’s picture

I think this warrants a Drupal status report message.

solide-echt’s picture

Aha, that makes sense.
I've installed php-intl (which was a bit of a hassle...) but can confirm it's working now.
Thnx for the feedback!

develcuy’s picture

Drupal already has localization built-in so no need to install php-intl nor use twig extensions for dates, just relay on drupal's format_date() function, like this:

{% if node.created.value is defined %}
  {% set created_date = node.created.value|format_date(NULL, 'd F Y') %}
  {{ created_date }}
{% endif %}

More complex examples here: https://medium.com/integral-vision/translatable-custom-dates-in-twig-tem...

develcuy’s picture

Status: Needs review » Closed (works as designed)

Drupal core already provides a localization method for dates.

joelpittet’s picture

Status: Closed (works as designed) » Needs review

That may be right but that doesn't solve the problem this issue indicates for this module without that extension.

joelpittet’s picture

Title: PHP intl extension missing documentation ? » PHP intl extension missing
StatusFileSize
new2.09 KB

I put an info message instead of a warning since it may not be totally needed like @develCuy mentioned.

Give that a try and let me know if it needs more or re-wording.

bserem’s picture

Patch applies and allows usage of the module (I needed the text extension).

I say it gets applied, without it the module is not usable right away.

bserem’s picture

Status: Needs review » Reviewed & tested by the community

  • joelpittet committed 45ba6b8 on 8.x-1.x
    Issue #2694185 by joelpittet, mortendk, jdleonard, solide-echt, bserem,...
joelpittet’s picture

Component: Documentation » Code
Status: Reviewed & tested by the community » Fixed

Thanks for checking on this patch @bserem.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

darvanen’s picture

Would be great to see a new release with this included. Can confirm the patch works nicely.

darvanen’s picture

Thank you!

hlopes’s picture


  if (class_exists('IntlDateFormatter')) {
    $requirements['twig_extensions_intl']['description'] = t('Twig Extensions Intl is not active because the <a href=":intl_url">PHP Extension</a> is not installed. While not needed with Drupal having similar functionality, it may be desired.', [
      ':intl_url' => 'http://php.net/manual/en/book.intl.php',
    ]);
    $requirements['twig_extensions_intl']['severity'] = REQUIREMENT_INFO;
  }

Shouldn't that be

  if (!class_exists('IntlDateFormatter')) {

?

If class exists put a message on Status Report? Doesn't sound logical...

Also we should add a title to the requirements array, otherwise I see a

Notice: Undefined index: title in core/modules/system/src/SystemManager.php on line 116

    $requirements['twig_extensions_intl']['title'] = t("Twig Extensions Intl");
joelpittet’s picture

I think you're right @HLopes. We don't reopen issues, can you please create a new issue with a new patch?