Skip to content

Multi-language System for AuboCaps Guide

In the process of developing applications, multi-language switching is an essential feature, ARCS software currently supports Chinese/English switching.

Operation: Click Setting in the upper right corner of the main interface, select English or Chinese (Simplified) in Preferences->Language, and then click Apply and Restart in the lower right corner to complete the switching between English and Chinese in the ARCS software.

Goal: The developed plug-in switches between English and Chinese along with the system language of the ARCS software.

1. Loading process of plug-in translation

ARCS can automatically load the plugin's translation files, just place the qm file in the plugin's sibling directory when deploying, as shown below:

First, lay out the required controls on the interface

1.1 Generate translation file .ts file

First create a new translations folder in the project/src/ directory

​ Qt comes with a translation class QTranslator which can be used to switch between languages. Define a QTranslator object, which then loads a .qm file via the load method, which is actually the translation file.

​ The .qm file is generated from the .ts file, and we need to generate the translation file as a .ts file.

Determine the naming of translation files

(Recommended) Use plugin_zh_CN.ts to save Chinese translation files and plugin_en.ts to save English translation files.

Example: loadqrc_zh_CN.tsloadqrc_en.ts

Translation files need to be included in CMake

​ Modify the CMakeLists.txt file:

​ ①Add LinguistTools to find_package

​ ②Set the path to the translation file TS_FILES and create the translation file .ts file

​ ③The .tsfile needs to be added to add_library

The code is as follows:

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, re-CMake and Build the project, and then generate the .ts file for the translations in the project/src/translations/directory.

1.2 Use the linguist tool to translate .ts files

Use Qt's own linguist tool to open the translation file (.ts) generated above and translate some of the untranslated statements in the interface.

From the figure below, the statement labeled 1 has not been translated, so it needs to be manually translated at the location marked as 2. After completion, click the button marked as 3 to see that the current sentence has been translated.

Finish translating all the text and click on the Save button in the upper left corner

Completion of the English translation of the document in the same way

1.3 Package the plugin, ARCS loads the plugin zip package

Through the deploy.sh script to complete the plug-in packaging and compression, copy to arcs specified working directory, load the plug-in, select the system language for Chinese (simplified), you can complete the plug-in translation and loading process. The result is as follows:

2.Update process for plugin translations

Requirement: In the process of plugin development, sometimes after the Chinese and English translation function is done, the plugin may add other functions, which also need Chinese and English translation, and then you just need to update the original .ts translation file.

For example, after the above translation functionality has been done, create a new control called update translation test putton which needs to be translated asupdate translation test button.

First, find out where the .ts file is stored under the project, as shown in the figure below The .ts file for this test case is in the location shown in the figure below:

Open a terminal at the .ts file and use the command lupdate to update the Chinese and English .ts translation files, the general format of this command is lupdate -ts .ts file to be updated ,it is important to note that if the whole project adopts the management of CMAKE , manually write all the addresses of source code files related to translation contents as parameters after the command lupdate ,that is, the command format is lupdate source code file 1 source code file 2 ... If the whole project is managed by CMAKE, using lupdate to update the translation files, manually write the addresses of all the source code files related to the translation content as parameters to the lupdae command,i.e., the format of the command is lupdate source code file 1 source code file 2 ... -ts The .ts file to be updated'. However, if there are more source code files involved, use relative paths. For example, all the source code of this test project is stored in the src directory and the src file is in the parent directory of the .ts file directory.../* to access all files in the src directory.Therefore, this test project can use the following command to update the Chinese and English .ts translation files: (the relative path here, adjust the file structure according to their own project, use the absolute path to add each source code file).

lupdate ../* -ts loadqrc_zh_CN.ts

lupdate ../* -ts loadqrc_en.ts

Recompile the project

Open the .ts translation file again, and you can see that the information about the control you added has been added.

Follow step 1.2 again to complete the translation

Pack, load, done

So far, the update of the plugin translation has been completed.