Giter Site home page Giter Site logo

Comments (6)

eLod avatar eLod commented on August 21, 2024

hey @fancenl. the thing is with g11n helpers is that they are added to view rendering via config initializers, you can check here. the good news is that you should be able to add those helpers to mail rendering just the same (adding to li3_mailer\net\mail\Media).

from li3_mailer.

jeffreyvanhees avatar jeffreyvanhees commented on August 21, 2024

Thanks @eLod for the quick response. Unfortunately, when I add the following code to the li3_mailer's media.php, I got an error:

# li3_mailer\net\mail\Media
Media::applyFilter('_handle', function($self, $params, $chain) {
    $params['handler'] += array('outputFilters' => array());
    $params['handler']['outputFilters'] += \lithium\g11n\Message::aliases(); // Added full namespace because Message is already in use by the library itself
    return $chain->next($self, $params, $chain);
});

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Locale `` could not be parsed.' in /var/www/production/libraries/lithium/g11n/Locale.php:131

So, how can I take care of the fact that Lithium will use the current locale-configuration?

from li3_mailer.

eLod avatar eLod commented on August 21, 2024

hey @fancenl. i think you need to set the locale as well if you are rendering emails outside of the request-response cycle, e.g. you see the initializer applying the locale setter here. also i think you don't need to use the the full path for Message because of the explicit import in that initializer file, where have you added your code? i would add it in that same initializer, and use li3_mailer\net\mail\Media as MailMedia;.

from li3_mailer.

jeffreyvanhees avatar jeffreyvanhees commented on August 21, 2024

@eLod I've added the code just at the end of the file outside the class. If I do not use the full path for Message I got the error:
Fatal error: Call to undefined method li3_mailer\net\mail\Message::aliases()

So I did use lithium\g11n\Message as MailMessage; and the top of the file and changed my code to:

MailMedia::applyFilter('_handle', function($self, $params, $chain) {
    $params['handler'] += array('outputFilters' => array());
    $params['handler']['outputFilters'] += MailMessage::aliases();
    return $chain->next($self, $params, $chain);
});

and below the code above:

$setLocale = function($self, $params, $chain) {
    if (!$params['request']->locale()) {
        $params['request']->locale(Locale::preferred($params['request']));
    }
    Environment::set(true, array('locale' => $params['request']->locale()));

    return $chain->next($self, $params, $chain);
};

MailMedia::applyFilter('_handle', $setLocale);

This gives a new error:
Notice: Undefined index: request in /var/www/production/libraries/li3_mailer/net/mail/Media.php on line 424
and
Fatal error: Call to a member function locale() on a non-object in /var/www/production/libraries/li3_mailer/net/mail/Media.php on line 424

So I think that lithium cannot find the right locale because there is no request-object.

(I'm sorry, I'm trying to understand MVC & Lithium and I'm not an expert yet ;-))

from li3_mailer.

eLod avatar eLod commented on August 21, 2024

@fancenl strange, i dont think you should use MailMessage though, i would pass the class to the anonymous function via using. For the new error: yes, there is no $params['request'] just remove those lines and set whatever locale you want to.

from li3_mailer.

jeffreyvanhees avatar jeffreyvanhees commented on August 21, 2024

A few months later; it is working by adding:

use lithium\g11n\Message;
use li3_mailer\net\mail\Media;

Media::applyFilter('_handle', function($self, $params, $chain) {
    $params['handler'] += array('outputFilters' => array());
    $params['handler']['outputFilters'] += Message::aliases();
    return $chain->next($self, $params, $chain);
});

Thank you!

from li3_mailer.

Related Issues (5)

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.