Building a good software for yourself is easy. Building a good software for other people can be challenging. Building a good software for other people who are from a different culture and have a different background can be quite an achievement.
Welcome to the world of internationalization (i18n) and localization (l10n). This world can be confusing for many programmers. It is the task to enable your software to be used by people from other countries that are using different customs, different languages, different ways of displaying and entering numbers and dates. It can be as broad as people in a different social context that might requires a different approach in your software.
Text
The first steps normally involves translating your text expressions in different languages to be used throughout your software. A good way to do it is to have your text expressions in a separate file so that they can be manipulated easily and sent to a professional translator or a community member that is translating which is often the case with open source project.
Each expression is assigned an id that is called from your code. For instance, let say that you have the following content in your English text expressions file:
loginError=Your login is invalid, please try again
In your code, you could call a function whenever you need that text expression like this:
print getLocalText("loginError")
Using this method, it is easy to have different files for each languages you want to support and simply change a variable in your application to get the corresponding text expression. You could have a French text expressions file with this line:
loginError=Votre accès est incorrecte, veuillez réessayer
You might also need to replace sub-expressions with values from your code. For example, you might want to include the login name in that login error message.
loginError=The login name %s is invalid, please try again
Many languages already offer some functions to ease the internationalization and localization development regarding text expressions. gettext is one of them and it already supports sub-expression replacements.
So far so good, but there are many subtleties. What about plural forms, gender forms, right-to-left languages, polite forms. There are solution for these other problems, but that will be left to the reader as an exercise.
Date, time, number and money
Another important point with internationalization and localization is format. People from different cultures have different ways to format date, time, number and money. That could play an important role in displaying those type of information but also in the way it is accepted as an input from the user.
The same date can be formatted in different ways depending. For example, here is the current date, April 5th 2008, displayed in its long form in various cultures:
- United-States of America (English): Saturday, April 05, 2008
- Canada (English): April 5, 2008
- Australia (English): Saturday, 5 April 2008
- Canada (French): 5 avril 2008
- France (French): samedi 5 avril 2008
- Switzerland (French): samedi, 5. avril 2008
- Mexico (Spanish): sábado, 05 de abril de 2008
People expect date to be formatted in the way they know and it is the main reason why we should care about it. It is the same for time, number and money.
Solutions
Many languages comes with built-in libraries or modules to manage those situation. In the .NET world, you have the System.Globalization namespace, in Java, you have the Locale class that can be used with different methods to format your data. You also have the ICU project for C/C++ and Java providing many interesting functionalities. In the Python world, you have many different options including a wrapper around the ICU libraries and Babel.
Many solutions are available but one thing is for sure: internationalization and localization is expensive. It is long, tedious and error-prone. Each time you add or modify a text expression, you have to send it to your translators. Each time you add a new field for date, time, number or money, you have to be careful on how you display it and how you are going to accept input from it.
In my case, I often do French/English translation directly while I program since I know both but that is as far I as can go. We cannot expect every programmers to translate as they develop. For the rest, a professional translator has to be paid to do it.
Post a Comment