Hi,

On Feb 5, 2010, at 00:30 , cordenier christophe wrote:

Hi

2010/2/5 Christoph Jäger <christoph.jae...@polleninfo.org>

Hi,

I use org.apache.tapestry5.ioc.Messages to get the translated strings for my web application from the property files for my pages. This works great.

Now, I want to use the same mechanism in two different places in my
application:

1. A user can click a button to generate some graphic or Excel file
containing data. Some strings on the graphic (like title, ...) and in the Excel file need to be translated, too. So in the code, which creates the
graphic or Excel file, I pass the org.apache.tapestry5.ioc.Messages
instance, which was injected into my page to do the translations. This also works great. But: sometimes the language used for the graphic or Excel file is different from the language used on the web page. How can I make the Messages instance switch the language, or request a new Messages instance from Tapestry, with the language (Locale) needed for the graphic / Excel
file?


You can use LocalizationSetter.setNonPeristentLocaleFromLocaleName to change
the locale without affecting the client locale current locale.

Tried this out with some simple code in a Tapestry page:

...
@Inject
private Messages messages;

@Inject
private LocalizationSetter localizationSetter;

public String getMixedLanguageContent()
{
  String str=messages.get("apple");
  localizationSetter.setNonPeristentLocaleFromLocaleName("de");
  str=str+", "+messages.get("apple");
  return str;
}
...

${mixedLanguageContent} in the .tml file.

but it seems the Messages instance does no change the locale just by using a localizationSetter, as the ouput is:

apple, apple

instead of

apple, Apfel



2. The application runs some scheduler, which will create reminder emails once every day. The emails are create from a template, which is filled with some translated strings. Is there an easy way to ask Tapestry for a Messages instance (with a given Locale, and based on some class (to query the right .properties file) as if it were injected into a page), in this background
job, which just runs inside a web application, but does not have any
connection to an actual web request?


Have a look at
http://tapestry.apache.org/tapestry5/tapestry-ioc/parallel.html

This document describes a mechanism for running threads. I will probably use some Spring functionality for scheduling my threads, so this part is already handled. The only thing missing is how to get hold of a Messages instance for a given Locale and a given class, without being a Tapestry page and relying on injection? Is there a way to let Tapestry inject this Messages instance into my Spring managed classes? Or is there something like MessagesUtil.getMessages(Locale locale, Class clazz) to request the appropriate Messages instance from Tapestry?

Thanks,

Christoph Jäger


Regards,
Christophe.

Developer of wooki @wookicentral.com



Best Regards,

Christoph Jäger
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org




--
Regards,
Christophe Cordenier.

Developer of wooki @wookicentral.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to