Localization
During application development, language switching is an essential feature. The AUBO Scope software currently supports switching between Chinese and English, and plugins developed for it must also switch languages in accordance with the AUBO Scope software's system language.
During plugin development, TS files are first generated using Qt Creator. TS files are the files that implement the translation functionality. There will be as many TS files as there are languages that the AUBO Scope software system can switch between. After generating the TS files, use the Qt Linguist tool to translate all TS files. Finally, repackage the plugin and load it into the AUBO Scope software to enable the plugin to switch languages along with the AUBO Scope software's system language.
Switching Languages in AUBO Scope Software
Launch the AUBO Scope software and click the [Settings] button in the upper-right corner of the home page.
In the [Settings] interface, click "Preferences > Basic Settings", select either [Chinese] or [English], then click [Apply and Restart] in the lower right corner. The language switch in AUBO Scope software will be completed after restart.
Generation, Loading, and Updating of Translation Files
Generating Translation Files
Open Qt Creator, load the plugin project, and arrange the controls in the interface.
Create a new "translations" folder under the plugin's
src
directory.Determine the naming convention for translation files.
(Recommended) Use "plugin_name_zh_CN.ts" for Chinese translation files and "plugin_name_en.ts" for English translation files.
For example: myplugin_zh_CN.ts、myplugin_en.ts
odify the
CMakeLists.txt
file to include translation files in CMake.Add
LinguistTools
translation tool infind_package
.Set the translation file path
TS_FILES
and create the translation.ts
files.Add
.ts
translation files inadd_library
.Specific code:
find_package(Qt5 REQUIRED COMPONENTS Core Widgets LinguistTools)
set(TS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/translations/loadqrc_zh_CN.ts ${CMAKE_CURRENT_SOURCE_DIR}/src/translations/loadqrc_en.ts) set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION ${PLUGIN_OUTPUT_PATH}/loadqrc) qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src ${TS_FILES})
add_library(loadqrc SHARED ${_srcs} ${program_src} ${install_src} ${QM_FILES} src/activator.cpp src/resource.qrc)
Save the
CMakeLists.txt
file, perform CMake and Build again for the project. After completion, the corresponding .ts translation files will be generated in theproject/src/translations
directory.
Translating Translation Files
Open Qt Linguist and open the .ts file.
As shown in the image, position [1] indicates untranslated phrases; after selecting an untranslated phrase, enter the translation content in position [2]; after entering the translation, click the button at position [3] to mark the phrase as translated.
fter completing all phrase translations, click [Save] in the upper left corner.
Package Plugin
Complete the plugin packaging and compression through the deploy.sh
script, copy it to the specified arcs working directory, load the plugin, select Simplified Chinese as the system language to complete the plugin translation loading process. The results are shown below:
Update Translation Files
During plugin development, sometimes after completing the translation functionality for various languages, the plugin may add other features that need translation. In such cases, you only need to update the .ts files.
Below is an example of adding a control "update translation test button" to demonstrate the steps for updating translation files:
Open Qt Creator and add a new control in the plugin project, named "update translation test button".
Locate the .ts files in the project. The storage location of the .ts files in this test case is shown in the image.
Open terminal at the .ts file location and use the
lupdate
command to update the .ts files.General format of the
lupdate
command:lupdate -ts translation_file_to_update.ts
If the entire plugin project is managed by CMake, manually add all source code file addresses related to translation content:
lupdate sourcefile1 sourcefile2 ... -ts ts_file_to_update.ts
If there are many source code files involved, you can use relative paths. Users can adjust according to their project file structure or use absolute paths. In this test project, all source code is stored in the
src
directory, which is in the parent directory of the .ts files. Use../*
in the .ts file directory to access all files in thesrc
directory:lupdate ../* -ts loadqrc_zh_CN.ts lupdate ../* -ts loadqrc_en.ts
Recompile the project.
Open the .ts file again to check if the newly added control information has been added.
Translate the files, refer to Translating Translation Files for specific operations.
Package the plugin and load it into AUBO Scope to complete the update.
AUBO Scope software can automatically load plugin translation files. During deployment, simply place the qm files in the plugin statistics directory.