0

I am trying to test localization of date formats in a web app. I am running a Tomcat 7 webserver, with the JSTL argument <fmt:setLocale value="${pageContext.request.locale.language}_${pageContext.request.locale.country}" /> on the page to set the date format. I am running the local server from Intellij, with the JVM arguments of -Duser.language=en -Duser.region=GB yet every time I run the app the locale comes out as en_US. What can I do to test the locale format change?

EDIT: I have also tried editing my client locale in chrome using chrome://settings/languages and FireFox using the Quick Locale Switcher add-on.

sparks
  • 736
  • 1
  • 9
  • 29
  • Read the javadoc of HttpServletRequest.getLocale(), and understand that the locale of the JVM has nothing to do with the locale of the request: http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getLocale%28%29 – JB Nizet May 26 '15 at 17:28
  • @JBNizet `Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.` If you see the edit, I have changed my client locale as per @BalusC's suggestion and am still seeing the same behavior, which makes me think its returning the server default locale. How can I get around this? – sparks May 26 '15 at 18:11
  • Do some debugging. Add `${pageContext.request.locale}` to the JSP. Check what is printed. If the correct locale is printed, then post a complete minimal JSP reproducing the problem, telle us what you expect it to display and what is displays instead. – JB Nizet May 26 '15 at 18:16

1 Answers1

2

You need to change the client locale, not the server locale. It's the client who's interested in localized web page, not the server. The server has just to respond accordingly on client's request.

How to change the client locale depends on the client used. In Chrome for example, you can manage it in chrome://settings/languages.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Okay, so if it isn't obvious by now, I'm crap at web-dev. I have gone into the chrome language settings and added other languages (british english, german, polish) and set them as the defining languages. (currently the red squiglies are telling me this isn't proper Polish. Yet my locale on the page still says `en_US`. I have already also tried the Quick Locale Switcher Firefox add-on, which results in similar results. – sparks May 26 '15 at 18:08
  • 1
    Then JSTL localization is done wrong. You can find a mini tutorial in answer of http://stackoverflow.com/questions/4276061/how-to-internationalize-a-java-web-application – BalusC May 26 '15 at 18:11