Solved

Muti-Lingual java program

Posted on 2004-09-13
2
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 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