Getting locale attribute from session.
Hello, I'm new user of struts framework and I have a problem. I would like to make an internationalized application with _everything_ internationalized. This means that I have a nice graphics (menu too) on my pages in several language versions. I would like to obtain a LOCALE key (object) from session (inserted there by tag). And here is the problem: to be perfect, I would like to get this key by the name which is stored in org.apache.struts.action.Action.LOCALE_KEY constant. How to access the key? I've made my entering (index.jsp) file as a template file and I check the locale via and tags. But inside these tags I have to use directly the org.apache.struts.action.LOCALE keyword - it's not possible to ask for key name (by asking I mean getting the value of org.apache.struts.action.Action.LOCALE_KEY). Or is it possible? If someone knows, please help me. I have tried to check archives for this, but with no success (for what I want is hard to find right keywords... - BTW, I like the archive, it helped me several times) Thank you very much. With regards --jerry
Re: Getting locale attribute from session.
"Juraj Kazda" <[EMAIL PROTECTED]> wrote: > Hello, > > I'm new user of struts framework and I have a problem. > > I would like to make an internationalized application with _everything_ > internationalized. This means that I have a nice graphics (menu too) on > my pages in several language versions. I would like to obtain a LOCALE > key (object) from session (inserted there by > tag). And here is the problem: to be perfect, I would like to get this > key by the name which is stored in > org.apache.struts.action.Action.LOCALE_KEY constant. How to access the > key? The key is just a constant, have a look in the sources. But I do not think this is the right way to do it. You could use inside the href attributes of the images instead. If you want to hse the tag , which I'd reccomend to you, have a look at the attributes pageKey or srcKey, they use message resources. In this way you can create message resources files with names of the pictures in different languages: and in the files specify the names of those pictures: ApplicationResources_en.properties: picture.save=/images/save.gif ApplicationResources_de.properties: picture.save=/images/speichern.gif ApplicationResources_sk.properties: picture.save=/images/ulozit.gif ... > I've made my entering (index.jsp) file as a template file and I check > the locale via and tags. But inside these > tags I have to use directly the org.apache.struts.action.LOCALE keyword > - it's not possible to ask for key name (by asking I mean getting the > value of org.apache.struts.action.Action.LOCALE_KEY). Or is it possible? > > If someone knows, please help me. Here a scriplet, how to get the locale if you need it for something, where you cannot use taglibs (like getting Format etc.) <% Locale locale = (Locale) pageContext.getAttribute(Action.LOCALE_KEY, PageContext.SESSION_SCOPE); if (null == locale) { locale = request.getLocale(); } DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale); %> -- gR
Re: Getting locale attribute from session.
There is an easy way to internationalize your graphics without having to mess around with the Locale yourself. Consider that you might normally create an image link like this: but you want the HREF to the link to be different for different Locales. First, change your tag to: and then, in your application resources files, define something like this (assuming we're in the en_GB Locale): image.key=image_en_GB.gif Now, you've appropriately internationalized your images, just like does for your text strings. Craig On Tue, 14 Aug 2001, Juraj Kazda wrote: > Hello, > > I'm new user of struts framework and I have a problem. > > I would like to make an internationalized application with _everything_ > internationalized. This means that I have a nice graphics (menu too) on > my pages in several language versions. I would like to obtain a LOCALE > key (object) from session (inserted there by > tag). And here is the problem: to be perfect, I would like to get this > key by the name which is stored in > org.apache.struts.action.Action.LOCALE_KEY constant. How to access the > key? > > I've made my entering (index.jsp) file as a template file and I check > the locale via and tags. But inside these > tags I have to use directly the org.apache.struts.action.LOCALE keyword > - it's not possible to ask for key name (by asking I mean getting the > value of org.apache.struts.action.Action.LOCALE_KEY). Or is it possible? > > If someone knows, please help me. > > I have tried to check archives for this, but with no success (for what I > want is hard to find right keywords... - BTW, I like the archive, it > helped me several times) > > Thank you very much. > > With regards > > --jerry > > >