Créer un site internet

Java Internationalization

First Easy Application For Internationalization

If you're new to internationalizing software, then, this chapter is for you.

By a simple example you'll learn how Locale and ResourceBundle objects work together and how to use properties files:

  1. Before Internationalization:

Simply, lets consider the following program:  (which is NOT internationalized): and analyze the underlined information

public class NotI18N

{

static public void main(String[] args)

{

        System.out.println("Hello.");
        System.out.println("How are you?");
        System.out.println("Goodbye.");
  }

  }

  1. After Internationalization:

Let's suppose that we want to Internationalize our code into three language French, English and German:

In order to insure that we need to create four property files: (each one contains the content below)

  • MessagesBundle.properties:

greetings = Hello.
farewell = Goodbye.
inquiry = How are you?

  • MessagesBundle_de_DE.properties:

greetings = Hallo.
farewell = Tschüß.
inquiry = Wie geht's?

  • MessagesBundle_en_US.properties:

greetings = Hello.
farewell = Goodbye.
inquiry = How are you?

 

  • MessagesBundle_fr_FR.properties:

greetings = Bonjour.
farewell = Au revoir.
inquiry = Comment allez-vous?

 

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"));
    }
}

 

Internationalization - Introduction

Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes. Sometimes the term internationalization is abbreviated as i18n, because there are 18 letters between the first "i" and the last "n."

An internationalized program has the following characteristics:

  • With the addition of localized data, the same executable can run worldwide.
  • Textual elements, such as status messages and the GUI component labels, are not hardcoded in the program. Instead they are stored outside the source code and retrieved dynamically.
  • Support for new languages does not require recompilation.
  • Culturally-dependent data, such as dates and currencies, appear in formats that conform to the end user's region and language.
  • It can be localized quickly.

Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text. The term localization is often abbreviated as l10n, because there are 10 letters between the "l" and the "n."

The primary task of localization is translating the user interface elements and documentation. Localization involves not only changing the language interaction, but also other relevant changes such as display of numbers, dates, currency, and so on. Other types of data, such as sounds and images, may require localization if they are culturally sensitive. The better internationalized an application is, the easier it is to localize it for a particular language and character encoding scheme