wood burning stoves
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

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
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: 19738

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 ]
I agree. Here's the link: http://aspose.com/file-tools
subject: how to check locale?
It's not a secret anymore!