Closed (fixed)
Project:
Twig Extensions
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
25 Mar 2016 at 10:37 UTC
Updated:
15 May 2018 at 01:01 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
rene bakxThe 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.
Comment #3
afoster commentedJust 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.
Comment #4
jdleonardI 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.
Comment #5
joelpittetThis may work, lightly tested but it avoids registering the intl service if the PHP extension's class doesn't exist.
Comment #6
joelpittetComment #7
solide-echt commentedI'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
Comment #8
joelpittetThe 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?
Comment #9
jdleonardI think this warrants a Drupal status report message.
Comment #10
solide-echt commentedAha, 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!
Comment #11
develcuy commentedDrupal 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:
More complex examples here: https://medium.com/integral-vision/translatable-custom-dates-in-twig-tem...
Comment #12
develcuy commentedDrupal core already provides a localization method for dates.
Comment #13
joelpittetThat may be right but that doesn't solve the problem this issue indicates for this module without that extension.
Comment #14
joelpittetI 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.
Comment #15
bserem commentedPatch 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.
Comment #16
bserem commentedComment #18
joelpittetThanks for checking on this patch @bserem.
Comment #20
darvanenWould be great to see a new release with this included. Can confirm the patch works nicely.
Comment #21
darvanenThank you!
Comment #22
hlopes commentedShouldn't that be
?
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
Comment #23
joelpittetI think you're right @HLopes. We don't reopen issues, can you please create a new issue with a new patch?