Chapter 8. Internalization and Localization

If you are planning to work with multiple languages, you need to add internalization support to your web applications. We will see how the i18n and l10n access can be embedded in our code to help design and develop web applications that enable easy localization for different cultures, regions, and languages. The topics that will be covered in this chapter are as follows:

  • The key principles
  • The Intl library
  • How to internationalize a web application
  • How to extract messages
  • How to use Google Translator Toolkit
  • How to use translated messages

The key principles

The development of globalized software is not a simple task. In general, the standard development process to create globalized software includes the following steps:

  • Internalization that covers designing and developing web applications
  • Localization that covers translating and customizing web applications for a specific locale

We will start designing and developing globalized software with the Intl library from the intl package available on the pub manager and follow some rules that will help us to easily translate and customize our application.

Executable code versus User Interface

All executable code must be separated from the programming code that implements the User Interface (UI). Also, code that describes the UI elements and the layout of the UI elements must be kept separated from the code that implements and manages them.

Numbers and dates

Various cultures have different ways to represent numbers and dates. You must avoid converting numbers and dates into strings directly.

Note

Converting numbers and dates must be done with special formatters.

Messages

Often, messages that contain individual pieces of text are used together to create complete sentences. In the process of localization, these pieces of text might go together in a different order. Using the message method of the Intl class allows you to display messages as simple expressions.

Measuring units and currencies

Measuring units such as meters and miles and currencies such as USD and Euro are ubiquitous and depend on the locale. The NumberFormat class contains special constructors for the quick creation of frequently used patterns that can be very handy to measure units and currencies.

Text input and layout

The size of the text on the screen is one of the biggest problems that affect programmers who develop globalized software. The main reason for this is that any assumption about the width of the text, the direction of its flow, and its position on the screen, if incorrect, can hamper well-structured layouts in a flash. Using the BidiFormatter class helps manage messages that contain text in both the text directionalities.

Formatting date and time

The locale determines how the date and time must be displayed. The DateFormat class has a big set of naming patterns that is useful to avoid mistakes and display data in the correct format.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.166.131