1

I'm writing simple www application using jsp and servlets on Tomcat 7.0. It's multilingual and i want to externalize all messages for easy translation. I am trying to achieve this using fmt:message tag. This is my test page:

SimplePage.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<fmt:setLocale value="en_US" scope="application" />
<fmt:setBundle basename="localization.message" var="b" />
<html>
<body>
    <fmt:message key="key1" bundle="${b}" />
</body>

message_en_US.properties

key1=test

Output of page is:

???key1???

I've put message_en_US.properties into source folder named "localization". I've tried also putting it into WEB-INF, WebContent and src (with changing basename of bundle) - result is the same. I appreciate any help.

phi293
  • 35
  • 5
  • Related: http://stackoverflow.com/questions/4276061/how-to-internationalize-a-java-web-application/4278571#4278571 – BalusC Mar 21 '13 at 15:56

1 Answers1

1

If you have it in a source folder named localization you don't need to prefix it with localization.

<fmt:setBundle basename="message" var="b" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • How exactly does this answer the concrete problem? OP doesn't seem to have done anything wrong with regard to this. – BalusC Mar 21 '13 at 15:44
  • Well... but it is working now, i mean since i deleted localization prefix. But i wonder is this right place to keep my localization files? – phi293 Mar 21 '13 at 15:52
  • @BalusC It works for me too. I'm doubting myself now, but the `fmt` library and its `bundle` tag uses classpath resources to evaluate your bundles. So putting them in source folder is one way to do it. – Sotirios Delimanolis Mar 21 '13 at 15:54
  • OP mentioned that it's placed in a source folder named `localization`, which I interpreted as package `localization`, then the basename of `localization.message` should be right. But apparently that fixed it. Look like there's some confusion/misgrasping of terms used. – BalusC Mar 21 '13 at 15:55
  • No, he said `into source folder named "localization". ` – Sotirios Delimanolis Mar 21 '13 at 15:55