Solved

Muti-Lingual java program

Posted on 2004-09-13
2
177 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 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

12 Experts available now in Live!

Get 1:1 Help Now