Solved

Muti-Lingual java program

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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 “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

860 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