using Mail Plugin in a Service and i18n

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

using Mail Plugin in a Service and i18n

Luis Muniz-2
Hi,

I am thinking about creating a web service that will ultimately send an email via the grails mail plugin.

A web service howver will not have the users locale in the request, and the mail plugin will be invoked from a grails service.

The issue i see then is how to tell the template engine which local it has to use for i18n.

Has anyone solved this yet?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

bdrhoa
See getLocale() in

https://svns.maflt.org/lt/toolteam/ibidem/trunk/src/ibidem/grails-app/service/MessageManagerService.groovy
---------------------------
www.maf.org/rhoads
www.ontherhoads.org


On Sun, Nov 21, 2010 at 12:55 PM, Luis Muniz <[hidden email]> wrote:
Hi,

I am thinking about creating a web service that will ultimately send an email via the grails mail plugin.

A web service howver will not have the users locale in the request, and the mail plugin will be invoked from a grails service.

The issue i see then is how to tell the template engine which local it has to use for i18n.

Has anyone solved this yet?

Thanks

Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

Luis Muniz-2
Hi,

Thanks for your reply. However your svn repository seems to be authentication protected.

Is it similar to the one attached to this thread?

http://grails.1312388.n4.nabble.com/Reading-Messages-in-Services-td3048442.html

However, what I need to do is to set the locale to a specific value, because there is no real user logged in, so the locale is not initialized in the request.

Nevertheless, I think that this class may point me in the right direction, because I could probably use RequestContextHolder and setting the LocaleResolver attribute (DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)

see http://www.docjar.com/html/api/org/springframework/web/servlet/support/RequestContextUtils.java.html

So thanks again Brad, i will test this out.

Luis

On Sun, Nov 21, 2010 at 9:00 PM, Brad Rhoads <[hidden email]> wrote:
See getLocale() in

https://svns.maflt.org/lt/toolteam/ibidem/trunk/src/ibidem/grails-app/service/MessageManagerService.groovy
---------------------------
www.maf.org/rhoads
www.ontherhoads.org



On Sun, Nov 21, 2010 at 12:55 PM, Luis Muniz <[hidden email]> wrote:
Hi,

I am thinking about creating a web service that will ultimately send an email via the grails mail plugin.

A web service howver will not have the users locale in the request, and the mail plugin will be invoked from a grails service.

The issue i see then is how to tell the template engine which local it has to use for i18n.

Has anyone solved this yet?

Thanks


Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

bdrhoa
Hmmm...you need to authenticate just to browse? I'll have to check on that.

But, yes I was pointing to the same same file that I had attached in that other thread.

Hope it helps...
---------------------------
www.maf.org/rhoads
www.ontherhoads.org


On Sun, Nov 21, 2010 at 1:39 PM, Luis Muniz <[hidden email]> wrote:
Hi,

Thanks for your reply. However your svn repository seems to be authentication protected.

Is it similar to the one attached to this thread?

http://grails.1312388.n4.nabble.com/Reading-Messages-in-Services-td3048442.html

However, what I need to do is to set the locale to a specific value, because there is no real user logged in, so the locale is not initialized in the request.

Nevertheless, I think that this class may point me in the right direction, because I could probably use RequestContextHolder and setting the LocaleResolver attribute (DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)

see http://www.docjar.com/html/api/org/springframework/web/servlet/support/RequestContextUtils.java.html

So thanks again Brad, i will test this out.

Luis


On Sun, Nov 21, 2010 at 9:00 PM, Brad Rhoads <[hidden email]> wrote:
See getLocale() in

https://svns.maflt.org/lt/toolteam/ibidem/trunk/src/ibidem/grails-app/service/MessageManagerService.groovy
---------------------------
www.maf.org/rhoads
www.ontherhoads.org



On Sun, Nov 21, 2010 at 12:55 PM, Luis Muniz <[hidden email]> wrote:
Hi,

I am thinking about creating a web service that will ultimately send an email via the grails mail plugin.

A web service howver will not have the users locale in the request, and the mail plugin will be invoked from a grails service.

The issue i see then is how to tell the template engine which local it has to use for i18n.

Has anyone solved this yet?

Thanks



Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

Luis Muniz-2
No, i'm not saying tha you need to authenticate just to browse, sorry. But you need to have a session where a locale is stored to be able to use the i18n system, right?

On Mon, Nov 22, 2010 at 7:33 AM, Brad Rhoads <[hidden email]> wrote:
Hmmm...you need to authenticate just to browse? I'll have to check on that.

But, yes I was pointing to the same same file that I had attached in that other thread.

Hope it helps...

---------------------------
www.maf.org/rhoads
www.ontherhoads.org


On Sun, Nov 21, 2010 at 1:39 PM, Luis Muniz <[hidden email]> wrote:
Hi,

Thanks for your reply. However your svn repository seems to be authentication protected.

Is it similar to the one attached to this thread?

http://grails.1312388.n4.nabble.com/Reading-Messages-in-Services-td3048442.html

However, what I need to do is to set the locale to a specific value, because there is no real user logged in, so the locale is not initialized in the request.

Nevertheless, I think that this class may point me in the right direction, because I could probably use RequestContextHolder and setting the LocaleResolver attribute (DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)

see http://www.docjar.com/html/api/org/springframework/web/servlet/support/RequestContextUtils.java.html

So thanks again Brad, i will test this out.

Luis


On Sun, Nov 21, 2010 at 9:00 PM, Brad Rhoads <[hidden email]> wrote:
See getLocale() in

https://svns.maflt.org/lt/toolteam/ibidem/trunk/src/ibidem/grails-app/service/MessageManagerService.groovy
---------------------------
www.maf.org/rhoads
www.ontherhoads.org



On Sun, Nov 21, 2010 at 12:55 PM, Luis Muniz <[hidden email]> wrote:
Hi,

I am thinking about creating a web service that will ultimately send an email via the grails mail plugin.

A web service howver will not have the users locale in the request, and the mail plugin will be invoked from a grails service.

The issue i see then is how to tell the template engine which local it has to use for i18n.

Has anyone solved this yet?

Thanks




Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

bdrhoa
I think you could manually create a locale object and then call messageSource.getMessage.

---------------------------
www.maf.org/rhoads
www.ontherhoads.org


On Mon, Nov 22, 2010 at 3:20 AM, Luis Muniz <[hidden email]> wrote:
No, i'm not saying tha you need to authenticate just to browse, sorry. But you need to have a session where a locale is stored to be able to use the i18n system, right?


On Mon, Nov 22, 2010 at 7:33 AM, Brad Rhoads <[hidden email]> wrote:
Hmmm...you need to authenticate just to browse? I'll have to check on that.

But, yes I was pointing to the same same file that I had attached in that other thread.

Hope it helps...

---------------------------
www.maf.org/rhoads
www.ontherhoads.org


On Sun, Nov 21, 2010 at 1:39 PM, Luis Muniz <[hidden email]> wrote:
Hi,

Thanks for your reply. However your svn repository seems to be authentication protected.

Is it similar to the one attached to this thread?

http://grails.1312388.n4.nabble.com/Reading-Messages-in-Services-td3048442.html

However, what I need to do is to set the locale to a specific value, because there is no real user logged in, so the locale is not initialized in the request.

Nevertheless, I think that this class may point me in the right direction, because I could probably use RequestContextHolder and setting the LocaleResolver attribute (DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)

see http://www.docjar.com/html/api/org/springframework/web/servlet/support/RequestContextUtils.java.html

So thanks again Brad, i will test this out.

Luis


On Sun, Nov 21, 2010 at 9:00 PM, Brad Rhoads <[hidden email]> wrote:
See getLocale() in

https://svns.maflt.org/lt/toolteam/ibidem/trunk/src/ibidem/grails-app/service/MessageManagerService.groovy
---------------------------
www.maf.org/rhoads
www.ontherhoads.org



On Sun, Nov 21, 2010 at 12:55 PM, Luis Muniz <[hidden email]> wrote:
Hi,

I am thinking about creating a web service that will ultimately send an email via the grails mail plugin.

A web service howver will not have the users locale in the request, and the mail plugin will be invoked from a grails service.

The issue i see then is how to tell the template engine which local it has to use for i18n.

Has anyone solved this yet?

Thanks





Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

Luis Muniz-2

True, but I would like to avoid that, I would like to build my email templates like GSP pages, taking advantage of the built-in i18n niceties, and before generating an email, add the necessary locale to the context of the GSP engine and then render the email.

In any case I will post my progress into this thread for future reference.

On Mon, Nov 22, 2010 at 4:10 PM, Brad Rhoads <[hidden email]> wrote:
I think you could manually create a locale object and then call messageSource.getMessage.


---------------------------
www.maf.org/rhoads
www.ontherhoads.org


On Mon, Nov 22, 2010 at 3:20 AM, Luis Muniz <[hidden email]> wrote:
No, i'm not saying tha you need to authenticate just to browse, sorry. But you need to have a session where a locale is stored to be able to use the i18n system, right?


On Mon, Nov 22, 2010 at 7:33 AM, Brad Rhoads <[hidden email]> wrote:
Hmmm...you need to authenticate just to browse? I'll have to check on that.

But, yes I was pointing to the same same file that I had attached in that other thread.

Hope it helps...

---------------------------
www.maf.org/rhoads
www.ontherhoads.org


On Sun, Nov 21, 2010 at 1:39 PM, Luis Muniz <[hidden email]> wrote:
Hi,

Thanks for your reply. However your svn repository seems to be authentication protected.

Is it similar to the one attached to this thread?

http://grails.1312388.n4.nabble.com/Reading-Messages-in-Services-td3048442.html

However, what I need to do is to set the locale to a specific value, because there is no real user logged in, so the locale is not initialized in the request.

Nevertheless, I think that this class may point me in the right direction, because I could probably use RequestContextHolder and setting the LocaleResolver attribute (DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)

see http://www.docjar.com/html/api/org/springframework/web/servlet/support/RequestContextUtils.java.html

So thanks again Brad, i will test this out.

Luis


On Sun, Nov 21, 2010 at 9:00 PM, Brad Rhoads <[hidden email]> wrote:
See getLocale() in

https://svns.maflt.org/lt/toolteam/ibidem/trunk/src/ibidem/grails-app/service/MessageManagerService.groovy
---------------------------
www.maf.org/rhoads
www.ontherhoads.org



On Sun, Nov 21, 2010 at 12:55 PM, Luis Muniz <[hidden email]> wrote:
Hi,

I am thinking about creating a web service that will ultimately send an email via the grails mail plugin.

A web service howver will not have the users locale in the request, and the mail plugin will be invoked from a grails service.

The issue i see then is how to tell the template engine which local it has to use for i18n.

Has anyone solved this yet?

Thanks






Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

ld@ldaley.com

On 23/11/2010, at 1:27 AM, Luis Muniz wrote:

> True, but I would like to avoid that, I would like to build my email templates like GSP pages, taking advantage of the built-in i18n niceties, and before generating an email, add the necessary locale to the context of the GSP engine and then render the email.

You will have to bind a mock request and set the session locale manually.

For binding a mock request, see:

https://github.com/gpc/grails-rendering/blob/master/grails-app/services/grails/plugin/rendering/document/XhtmlDocumentService.groovy#L70

You can then use the Spring RequestContextUtils class to get the LocaleResolver, on which you can explicitly set the locale.

http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/web/servlet/support/RequestContextUtils.html
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

Luis Muniz-2
Aha! thanks about the link to the mock request, I was about to Expando my way to it.

Luis

On Tue, Nov 23, 2010 at 12:20 AM, Luke Daley <[hidden email]> wrote:

On 23/11/2010, at 1:27 AM, Luis Muniz wrote:

> True, but I would like to avoid that, I would like to build my email templates like GSP pages, taking advantage of the built-in i18n niceties, and before generating an email, add the necessary locale to the context of the GSP engine and then render the email.

You will have to bind a mock request and set the session locale manually.

For binding a mock request, see:

https://github.com/gpc/grails-rendering/blob/master/grails-app/services/grails/plugin/rendering/document/XhtmlDocumentService.groovy#L70

You can then use the Spring RequestContextUtils class to get the LocaleResolver, on which you can explicitly set the locale.

http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/web/servlet/support/RequestContextUtils.html
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: using Mail Plugin in a Service and i18n

elvanor
I had exactly the same problem and solved it by mocking too. More details on this previous thread:

http://markmail.org/message/uvn2igttgsapsqpe

On Tue, Nov 23, 2010 at 9:51 AM, Luis Muniz <[hidden email]> wrote:
Aha! thanks about the link to the mock request, I was about to Expando my way to it.

Luis


On Tue, Nov 23, 2010 at 12:20 AM, Luke Daley <[hidden email]> wrote:

On 23/11/2010, at 1:27 AM, Luis Muniz wrote:

> True, but I would like to avoid that, I would like to build my email templates like GSP pages, taking advantage of the built-in i18n niceties, and before generating an email, add the necessary locale to the context of the GSP engine and then render the email.

You will have to bind a mock request and set the session locale manually.

For binding a mock request, see:

https://github.com/gpc/grails-rendering/blob/master/grails-app/services/grails/plugin/rendering/document/XhtmlDocumentService.groovy#L70

You can then use the Spring RequestContextUtils class to get the LocaleResolver, on which you can explicitly set the locale.

http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/web/servlet/support/RequestContextUtils.html
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email