Solved

Muti-Lingual java program

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 82
JDeveloper 12c for 32 bit 4 84
Need to track down Infection in a Server 2008 domain user profile 7 51
jboss wildfly 10.1 10 81
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 …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

776 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