Download the JDK
Search the Tutorials
Hide the TOC
Trail: Internationalization
Lesson: Introduction
Section: A Quick Example
Introduction
A Quick Example
Before Internationalization
After Internationalization
Running the Sample Program
Internationalizing the Sample Program
Checklist
Home Page > Internationalization > Introduction
After Internationalization

> The source code for the internationalized program follows. Notice that the text of the messages is not hardcoded.

> >     import java.util.*;

> >     public class I18NSample {

> >         static public void main(String[] args) {

> >             String language;
> >             String country;

> >             if (args.length != 2) {
> >                 language = new String("en");
> >                 country = new String("US");
> >             } 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"));
> >         }
> >     }

> To compile and run this program, you need these source files:
> - ``I18NSample.java``
> - ``MessagesBundle.properties``
> - ``MessagesBundle_de_DE.properties``
> - ``MessagesBundle_en_US.properties``
> - ``MessagesBundle_fr_FR.properties``

Previous page: Before Internationalization
Next page: Running the Sample Program