简体   繁体   中英

JDeveloper and Internationalization

I found difficulties to implement it in a simple web application. I put the l10n.properties files under the root WEB-INF, but I don't understand how I can read them. I used PropertiesResourceBundle.getBundle(baseName, locale) but I don't understand what I have to write for baseName. I read on some thread that I have to put the local files in the classpath: is it right? Where can I set the classpath in JDeveloper?

thanks in advance

Unless you need to read resource file on the back-end side (that means not directly in your web front-end), you should not under any circumstances use ResourceBundle.getBundle() and especially not PropertiesResourceBundle.getBundle() which is subclass of it.

Depending on the type of your application (whether it is JSP or JSF) you would access resources differently.
In case of simple JSP, you would use JSTL and fmt:message tags to translate UI just like here and countless questions on StackOverflow (just use the search engine in right upper corner of the screen).
In case of JSF/Facelets, you would need to set up appropriate variables in faces-config.xml, and simply use valid expression language queries. More on that could be found in this excellent tutorial .

Back to your original question, the base name that you pass to ResourceBundle.getBundle() (be sure not to use subclasses unless you really know what you are doing) is related to the path of the class you are accessing it from (that means it should be the same source directory). Another thing is what to pass here. Assuming that your resource file names are like messages.properties, messages_de.properties, messages_es_MX.properties, and similar, you would simply put "messages" for baseName, so the call in question would look like ResourceBundle.getBundle("messages", theLocale); where theLocale is your Locale object – this one should be detected (in JSP world it is a bit tricky, in JSF/Facelets it is as simple as Locale theLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); ).That's it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM