Git Product home page Git Product logo

Comments (9)

vojtasvoboda avatar vojtasvoboda commented on May 29, 2024

Yes, you're right, three filters require an environment: https://github.com/twigphp/intl-extra/blob/2.x/IntlExtension.php#L144 to be somehow injected into the filter.

I tried to solve it in 15 minutes, but without any output for now :-(

from oc-twigextensions-plugin.

chocolata avatar chocolata commented on May 29, 2024

Hi, I'm encountering the same issues and the exact same error messages. Our service provider says that the phpIntl extension is installed for my version of PHP.

Do you maybe know of a workaround?

from oc-twigextensions-plugin.

vojtasvoboda avatar vojtasvoboda commented on May 29, 2024

As I said above, the problem is passing Twig\Environment to these filters. So there is no problem with phpIntl installed on hosting/server.

The issue is still open, feel free to send a pull request with the fix.

from oc-twigextensions-plugin.

chocolata avatar chocolata commented on May 29, 2024

Hi @vojtasvoboda - thanks for clarifying, I didn't understand fully. I'm afraid that this is a bit above my level of expertise... I hope that maybe someone else is knowledgeable enough to provide a pull request...

from oc-twigextensions-plugin.

chrisvidal avatar chrisvidal commented on May 29, 2024

stumble on the same error...
I see that the plugin OFFLINE.Mall is succeeding to inject the twig env when it uses the currency formation function for the IntlExtension, but I cant make it work with this plugin.

Maybe that gives you a hint to fix this.

in the plugin.php, I tried this as per the Twig Format_date documentation https://twig.symfony.com/doc/3.x/filters/format_date.html

function register() {
        $this->twig = new Environment(new TwigLoader, ['auto_reload' => true]);
        $this->twig->addExtension(new IntlExtension());
}

and then adding the filter like this

$filters += [
                'format_date' => function ($date, ?string $dateFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null) use ($twig): string {
                    $intlExtension = new IntlExtension();
                    return $intlExtension->formatDate($twig, $date,  $dateFormat,  $pattern, $timezone,  $calendar,  $locale);
                }
            ];

from oc-twigextensions-plugin.

vojtasvoboda avatar vojtasvoboda commented on May 29, 2024

@chrisvidal Thanks for the hint about adding an extension directly to the Twig. It works brilliant :-) The new version is ready in the Market as version 2.0.4 🥳

@chocolata Please test, thanks.

from oc-twigextensions-plugin.

chocolata avatar chocolata commented on May 29, 2024

Hi @vojtasvoboda

Just tested this out and it works perfectly. In my usecase I managed to output the localized month name of my application like this:

{{ '2024-06-01' | format_date('none','MMMM',locale=this.site.locale) }}

Thanks for your work! Much appreciated.

from oc-twigextensions-plugin.

chrisvidal avatar chrisvidal commented on May 29, 2024

excellent! thanks

however, when I install the plugin on a new installation, I have this error [2024-05-12 17:26:31] production.ERROR: Error: Class "IntlDateFormatter" not found in /var/www/valhiraoka.com/public_html/plugins/vojtasvoboda/twigextensions/Plugin.php:36

I tried to composer update but it does not change anything.

from oc-twigextensions-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.