ParaView comes with a localization system that handles the complete language introspection workflow, from translation searching in the source code to language selection in the settings.
The theoretical workflow for a single language runs as follows:
translations
shared folder of ParaView.Interface Language
section.In practice, the process is slightly more complex since we use an official translation source repository that is updated by a translations CMS, for simplifying contributions.
Most of the steps are done using two of the Qt5's linguist utilities:
lupdate
, a source file parser that can parse C++ and Qt's UI files for translatable strings, and then generates a .ts file from itlrelease
, a .ts file compiler, that generates the .qm files.These utilities are invoked in the ParaView CMake build system and in the official ts repository respectively.
<language>_<COUNTRY>
. It is a language's national variant.All the source code in ParaView should ideally be translatable. A string is translatable if it can be found by lupdate.
Strings displayed in the ParaView client can come from three main sources:
Qt's UI files are automatically found by lupdate, so if a string shall not be translated (ie ParaView's name !) it has to have its translatable
property disabled in Qt Designer.
An exhaustive guide to translatable source code using Qt5 can be found here.
For setting the translatable property of a string in the most common cases:
Q_OBJECT
macro, you can use the tr(<explicitStringToTranslate>)
method of QObject
, without specifying this->
before (example).Q_OBJECT
macro, or does not inherit from QObject
, you can either:
QT_TRANSLATE_NOOP(<contextName>, <explicitStringToTranslate>)
.All these methods requires the include of QCoreApplication
.
Some examples:
The XML format is not natively supported by lupdate. Therefore, CMake/XML_translations_header_generator.py
was developed. It transforms proxy XMLs into C++ headers in order to be found by lupdate.
In a C++ code that displays text from the XML, it is now mandatory to use the context "ServerManagerXML" so that the translation can be found at runtime. E.g.: QCoreApplication::translate("ServerManagerXML", <translated XML element>));
.
Currently translatable XML fields are:
label
, which can be an attribute of any elementmenu_label
, which can be an attribute of any elementDocumentation
element's contentlong_help
attributeshort_help
attribute*Property
's name
sThis behavior can be extended by adding new elements or attributes to parse in the python utility.
The plugin TranslationsTesting
, bundled with ParaView, is built by default when enabling the PARAVIEW_BUILD_TRANSLATIONS
option. It will search though the main window for untranslated strings and print a warning if found.
This plugin is meant to be run through ctest, with the TranslationsTesting
test. It might be slow since it uses Regexes for its widget-ignore list (hopefully this list will be empty, otherwise, you will have the time to admire the improved version of ParaView).
Some source strings could not, or should not be translatable (ie ParaView's name !). ParaView translatability is tested on the ParaView's Gitlab CI, so if a string cannot be translated, the widget/action containing it has to be be added on the ignore list of the plugin.
The ignore list is located at Plugins/TranslationsTesting/pqTranslationsTesting.h
. You can use either
TRANSLATION_IGNORE_STRINGS
to ignore a precise widget/action, orTRANSLATION_IGNORE_REGEXES
to ignore a range of widgets.Both lists take pairs of strings: the first element is the name of the widget and the second is the attribute to ignore or an empty string to ignore all attributes.
The tested Qt attributes are text, toolTip
, windowTitle
, placeholderText
, text
and label
.
When PARAVIEW_BUILD_TRANSLATIONS
is enabled, translations source files are built in the given PARAVIEW_TRANSLATIONS_DIRECTORY
. A specific build target localization
can be used separatly from the ALL target to build them.
There is an official paraview-translations repository containing up-to-date source files.
The target files_update
will complete all ts files of all languages with the source strings. A single language can also be updated using the special target <locale>_update
.
After this step, translators can fill ts files with translations using Qt Linguist or any other tool supporting ts files.
Source files can be compiled into qm files using the CMake process of the translations repository. Each locale with a folder in the translations repository is a valid target that will create a qm.
It is also possible to compile ts files manually using lrelease. The command is lrelease <input files> -qm <outputQm>
.
Qm files can be loaded from the general settings. If a qm is found by ParaView, the language it provides will be available in the Interface language
Combobox. The selected language is saved in the settings, and a restart is required.
By default, ParaView searches for qms in the translations
shared folder. The environment variable PV_TRANSLATIONS_DIR
can provide other searching paths. When multiple qm files have the same language, the first qm found will be used, using the PV_TRANSLATIONS_DIR
paths first, and the default path after.
The locale can also be forced using the PV_TRANSLATIONS_LOCALE
environment variable.