Solved

Muti-Lingual java program

Posted on 2004-09-13
2
178 Views
Last Modified: 2012-05-05
Hi,

Below is a program that asks for user input of language & Country and displays the message in that language. However, I am a having problem since it always displays in American English. If I hardcode the values then I don't have any issue. Please advise.

I have 3 properties files where translation is done.

Thanks
************************
import java.io.IOException;
import java.util.*;
public class test {

      public static void main(String[] args) throws IOException {
            String language;
            String country;
              byte[] byteLang = new byte[10];
              byte[] byteCoun = new byte[10];

            if (args.length != 2) {

              // User Input       
                System.in.read(byteLang);
                    System.in.read(byteCoun);
                    language = new String(byteLang);
                country = new String(byteCoun);

              // Hardcode Input       
                //language = new String("en");      // English
                //country = new String("US");            // USA
                //language = new String("fr");      // French
                //country = new String("FR");            // France
                //language = new String("de");      // German
                //country = new String("DE");            // Germany
            } else {
                language = new String(args[0]);
                country = new String(args[1]);
            }

            Locale currentLocale;
            ResourceBundle messages;

            currentLocale = new Locale(language, country);

            messages =
              ResourceBundle.getBundle("MessagesBundle",currentLocale);

            System.out.println(messages.getString("greetings"));
            System.out.println(messages.getString("inquiry"));
            System.out.println(messages.getString("farewell"));            
      }
}
************************
Properties files.

1. MessagesBundle_en_US.properties
greetings = Hello.
farewell = Goodbye.
inquiry = How are you?

2. MessagesBundle_fr_FR.properties
greetings = Bonjour.
farewell = Au revoir.
inquiry = Comment allez-vous?

3.MessagesBundle_de_DE.properties
greetings = Hallo.
farewell = Tschüß.
inquiry = Wie geht's?

************************
0
Comment
Question by:Mallp
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 12047716
Try

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter language code: ");
String language = in.readLine();
System.out.print("Enter country code: ");
String country = in.readLine();
Local currentLocale = new Locale(language, country);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12147850
8-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HSSFWorkbook cannot be resolved error 10 50
servlet  URL Rewriting 1 27
diffSum example 4 26
windows explorer path to command prompt 5 33
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now