How about this? @Inject private PersistentLocale persistentLocale; @Inject private RequestGlobals requestGlobals;
public Locale getCurrentLocale() { Locale locale = persistentLocale.get(); return locale != null ? locale : requestGlobals.getRequest().getLocale(); } Quoting Christoph Jaeger <[EMAIL PROTECTED]>: > Hi, > > I use PersistentLocale to switch my pages to different languages. It > works great. I have several links on the top of the page, each one > switching to a different language. When a user clicks "DE", he will get > the German version. > > I also want to show the user which language is currently selected. I do > this by disabling the link for the currently selected language, and > marking it in a different color. Disabling make sense, as switching to > the language already selected, is a nop. > > Now comes the problem: before the user clicks one of the language links, > the PersistenLocale injected into my component tells me: no locale > selected (persistentLocale.get()==null). This is ok, because no > persistent locale was yet set. But I have a hard time finding out which > locale Tapestry is using right now. Calling Locale.getDefault() gives me > "en_US", but the content displayed on my pages is actually the German > one. So how do I ask Tapestry: "Which locale are you using for this > request?" (I also need this to do some localized date formatting at a > different place in my application). > > One thing that comes to my mind would be a key in MyApp.properties, > called "current_language", with "current_language: de" in > MyApp_de.properties, "current_language: en" in MyApp_en.properties and > so on, then use Messages to query the key to know which language is > selected. But there must be a simpler, cleaner solution. > > Best Regards, > > Christoph Jäger > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]