Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different languages in different parts of application

I have a multilingual Qt application, where I have the following problem

  1. The bulk of the UI should be translated to match the language of the system locale
  2. The application can also print various forms. The language of these forms should be independently selectable from the UI language (the forms will be handed over to people who often don't speak the local language)
  3. If possible, it would be nice to have the same capability as the previous point also for a dialog in the application.

In what way can I achieve this? All the examples I found deal with translating the entire application, but in my case, I need two independent translations (although possibly to the same language).

Would I need to replicate the fall-back mechanisms of QApplication::translate myself and use QTranslator::translate directly, or is there a more convenient way?

like image 929
Bart van Ingen Schenau Avatar asked May 02 '13 09:05

Bart van Ingen Schenau


People also ask

Can I use different programming languages in the same application?

Some languages are great for one task but not another, so working with multiple programming languages enables developers to use the right tool for the job. In this way, all development is polyglot; it's just the nature of the beast. The creation of a polyglot environment is often gradual and situational.

Which language is used in application?

Java, Python, C++, Kotlin, and Rust are popular app development languages ranked among the world's top 10 most preferred languages in 2022.

What language are most applications written in?

You write the mobile apps in Java and program against the Android SDK. The critics of Java say that Java needs a lot of "boilerplate" code to do a simple task, and the concepts like exceptions are difficult to understand. Thus far, this is the most widely used language for Android app development.

How do you create a multi language application?

Multilanguage support is easy done for android. Create a new values directory for the language with the suffix of the language code. For german: values-de or french: values-fr than copy your string. xml into that and translate each entry.


2 Answers

Let's assume you need one translation for whole app, and another for a dialog. What you need to do is to create two qm files: one, which contains translations of everything, except this dialog, and one, which contains translations only for this dialog. Now you can load/unload this qm files separately.

I guess you know how to change translation dynamically.

Update from comment:

To create separate qm files you could put all main sources in one directory, and all dialog sources into another and call lupdate -no-obsolete -recursive ../src/Form -ts Form_ru.ts, where ../src/Form is dialogs directory. Or even call lupdate -no-obsolete ../src/Form.ui ../src/Form.cpp ../src/Form.h -ts Form_ru.ts on files.

The result script would be something like this:

lupdate -no-obsolete -recursive ../test.pro -ts test_ru.ts
lupdate -no-obsolete ../Form.ui ../Form.cpp ../Form.h -ts Form_ru.ts
like image 88
Amartel Avatar answered Oct 24 '22 15:10

Amartel


As the QTranslator class has a virtual function for translate. You could inherit from QTranslator and overload the translate function to return the language string for each locale you want, depending on a flag you set in your inherited class.

You then set the flag to the locale you want to use just before creating the page for printing and then set it back after that.

like image 30
TheDarkKnight Avatar answered Oct 24 '22 15:10

TheDarkKnight