File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes how to check locale? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to check locale?" Watch "how to check locale?" New topic

how to check locale?

gino jersey

Joined: May 24, 2005
Posts: 21
Hi all- I'm dping something fairly simple but can;t get it to do what I want:

I need to check the locale and have it go to different bracnh of logic. I have:

Locale loc = request.getLocale();
System.out.println("Locale: /" + loc );
System.out.println( loc.getLanguage()+"_"+loc.getCountry() );

if (loc.equals("ja")) {
.... // HERE FOR JA
else {
.... // ELSE LOGIC

I need to check for japanese. The display shows "ja", and that's what I check for in my If statment , and yet when I check it still goes to the ELSE logic.
Am I checking for it incorrectly?
What's the proper way to check for locale values.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19875

You are comparing a Locale to a String. This comparison always returns false (you are lucky it doesn't throw an exception). If you want to know if the Locale's language is "ja" then do this:
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
In your code loc is Locale type but you provide String to its equals(). So the equals() is always false.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I think its not a JSP question. :roll:
[ October 27, 2005: Message edited by: Adeel Ansari ]
It is sorta covered in the JavaRanch Style Guide.
subject: how to check locale?
It's not a secret anymore!