Qt Internationalization

Embracing Internationalization in Software Applications

By Chris Rizzitello

Today’s market is global and many companies have begun to fully embrace Internationalization in their applications. If you are not familiar, Internationalization is the process of designing a software application in a way that it can be easily adapted for use in languages and locales other than the one it was created for. Here's the Wiki definition: Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. 

Here’s how it works in its most basic form. An application provides a translation into a different language, say from English to French. When done correctly, French-speaking users will feel as if the application was written specifically for their locale. An application can even translate the same language, for instance English spoken in North America (en_US) and English spoken in Britain (en_GB) — the same, but different. 

Creating a Product With Localization Support

Localization is more than simply translating the text of one language into another. (Again, here's the Wiki definition: Localization is the process of adapting internationalized software for a specific region or language by translating text and adding locale-specific components.)

After all, there’s more to a locale than just language. The same word or symbol can carry different meanings depending on locale. Our shared cultural experiences shape our expectations about how we should interact with certain items. Small details like the shape of an object or colors used on it can subconsciously influence the expectations of your users, and failing to recognize that can lead to poor localization practices.  

Here’s an example. Consider this simple check mark.

What does it mean? Well, that depends on where you’re from. In U.S. schools, for instance, the checkmark is used to indicate a correct answer on an assignment. Wrong answers are usually circled. But, in Japan a circle is used to indicate a correct answer on an assignment while an X indicates a wrong answer. 

These small differences can lead to some big confusion if not handled correctly. Look at what happened with Sony’s Playstation game console for one example of this confusion. Its controller would feature symbols on the buttons instead of letters used by previous systems. The Playstation’s developers chose to use O and X among their symbols based upon the tests markings used in Japan. 

Games made in Japan would use the completely natural O and X to represent Accept and Reject. But outside Japan, O and X would represent Reject and Accept — the opposite! While many games were translated they were not localized and this small detail was rarely considered. Not only was the symbol wrong for some locals but the color used was also an issue. 

Here’s another example of poor localization practice that does not target a specific application but something I have seen to often: using icons based on a gesture. This is never a good idea if you’re planning to have localizations of your application. The common gesture for “Okay” — the thumb touching the pointer finger in a circle w/ palm facing outward — means a wide range of things depending on the locale. You could be saying anything from okay to calling a person something offensive. The “V” or “Peace” gesture is another that has several meanings depending upon the locale. Takeaway: be very careful with gestures.

Other Challenges

What if your application had to be usable in several languages but you were not able to restart the application to execute the change? How would you make it happen? Qt offers a solution.

When you use Qt to develop your application you can make this change happen rather easily — the Qt Event system will create a language change event when the user selects the language from the menu. As developers. we can then update the GUI to use the new strings. If you are using a UI file you should also call retranslateUi for your UI. This will update the strings used in the UI. If you’re making custom widgets, it is a bit more involving as when you create them it should be created with the language change in mind. 

In a simple widget you may code something like: 

void MyClass::changeEvent(QEvent *e)
{
    if (e->type() != QEvent::LanguageChange)

        return;

    myButton->setText(tr(“ok”));
}

This will make sure that when a Language Change event happens, the text on myButton is updated. Since this might not always work well within your code structure, you will need to consider how you set the strings in your widget so that when the languageChange event happens all your strings can be updated with the new translations. 

You can also use QTranslators to translate parts of an application. For example, I have used them within applications to translate only specific widgets in cases when I need a label in local language and the content in a specific language. 

Best Practices

These are just some of the things to consider when localizing your application. The success of your localization and the amount of time it requires depends greatly on one thing: whether you’re developing using the best practices for Internationalization. 

Using Qt can help you solve critical issues because it provides the precise tools necessary to most effectively localize your application, making the process painless. To learn more about using Qt for localization, register for ICS’ live webinar on August 22. I’ll teach you exactly how to create localized applications using Qt. 

References: 

https://en.wikipedia.org/wiki/PlayStation_controller

https://jpninfo.com/51476

https://en.wikipedia.org/wiki/OK_gesture

https://doc.qt.io/qt-5/internationalization.html

https://en.wikipedia.org/wiki/V_sign