Multi-language support framework oriented to embedded system and implementation method of multi-language support framework
Through the multi-language support framework for embedded systems, using tools and shell scripts to automatically manage and update translated files, the problems of low efficiency and poor accuracy of manual operation in traditional methods are solved, and efficient and accurate multi-language support is achieved.
Patent Information
- Application Number
- CN202510252190.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-05
- Publication Date
- 2025-04-04
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional multilingual support methods require manual management and update of translated files, which are inefficient and prone to omissions or errors, and cannot meet the needs of real-time updates.
A multilingual support framework for embedded systems is proposed. By initializing the multilingual support framework, loading the default language resource file and setting environment variables, using macros to mark the text to be translated and calling the target framework. When switching the translation language, use the tool to automatically extract the text to be translated to generate .pot files, translate and generate .po files, and compile them into .mo files. Shell scripts and tools are used to automatically merge new strings into .po files and update .mo files, ensuring the accuracy of the translated files through lexical analysis and translation database comparison.
It simplifies the management, update and maintenance of translated files, improves the efficiency of the generation of translated content, ensures the accuracy and completeness of the translated files, and improves the reliability and stability of multi-language switching of embedded systems.
Smart Images

Figure CN119759480A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a multi-language support framework for embedded systems and an implementation method thereof. Background Art
[0002] In the globalized technology environment, multi-language support for embedded systems has gradually become an important part of the development process. However, traditional multi-language support methods mainly rely on manual management and updating of translation files. This method requires developers or project teams to regularly maintain translation content and manually update corresponding translation files. With the continuous iteration and functional expansion of projects, translation files need to be updated frequently. Manual operation is inefficient and prone to omissions or errors, resulting in incomplete or inaccurate translation content. When using embedded systems, it is often necessary to switch to different language environments. The system should respond quickly to language switching requests and update the interface in real time. However, traditional solutions cannot meet the needs of real-time updates.
[0003] Therefore, how to provide a multi-language support framework for embedded systems and an implementation method thereof is a technical problem that is urgently needed to be solved by those skilled in the art. Summary of the invention
[0004] In view of this, the present invention proposes a multi-language support framework for embedded systems and its implementation method, aiming to solve the problems that multi-language support requires manual management and updating of translation files, multi-language switching is not timely enough and the translation is inaccurate.
[0005] In one aspect, the present invention provides a multi-language implementation method for an embedded system, comprising: Initialize the multi-language support framework, load the default language resource file and set the environment variables, specify a default language environment to get the target framework, use macros to mark the text to be translated and call the target framework; When switching the translation language, the default language resource file of the target framework is changed to the translation language resource file, the text to be translated is extracted from the source code of the application program by a first tool to generate a .pot file, the pot file is translated by a second tool to generate a .po file, and the .po file is compiled into a .mo file by a third tool; Creating a new computer program Shell script, detecting new character strings in the source code according to the Shell script, merging the new character strings into the .po file, and updating the .mo file to obtain a translation file; Using lexical analysis to check the spelling in the translation file to obtain a target translation file, comparing the target translation file with a translation database to determine whether the translation content of the target translation file is correct, and obtaining a final translation file; When the translation language changes, a callback function is used to notify the application, the application updates the interface and outputs information according to the translation language resource file, and the application calls a resource acquisition API to acquire the final translation file.
[0006] Furthermore, when loading the default language resource file and setting the environment variables, include: The bindtextdomain function is used to obtain the directory of the default language resource file, load the default language resource file, and set the LC_ALL environment variable.
[0007] Further, when switching the translation language, the default language resource file of the target framework is changed to the translation language resource file, and the first tool is used to extract the text to be translated from the source code of the application program to generate a .pot file, including: When switching the translation language, the default language resource file of the target framework is changed to the translation language resource file and the new environment variables are loaded for updating; A first command line tool xgettext is used to scan and obtain all text strings to be translated in the source code, and the text strings are stored in the .pot file.
[0008] Further, the .pot file is translated by a second tool to generate a .po file, and the .po file is compiled by a third tool into a .mo file, including: A second command line tool msginit is used to create a msgstr field based on the text string in the .pot file, a translation text corresponding to the msgstr field is generated into a .po file, and a third command line tool msgfmt is used to compile the .po file into a .mo file.
[0009] Furthermore, a new computer program Shell script is created, and according to the Shell script, a new string in the source code is detected, the new string is merged into the .po file, and the .mo file is updated to obtain a translation file, including: The shell script is established and scans the source code to find a new string containing a translation mark, and the extracted new string is compared with the text string. If a text string identical to the new string is found in the .pot file, the shell script removes the new string and continues to scan the source code. If a text string identical to the new string is not found in the .pot file, the shell script merges the new string into the .po file and updates the .mo file to obtain the translation file.
[0010] Furthermore, the shell script adds the new string to the .po file and updates the .mo file to obtain the translation file, including: The first command line tool xgettext is used to generate a new .pot file from the new character string, the msgmerge tool is used to merge the new .pot file with the .po file, and the msgstr field in the .po file is retained to obtain a new .po file, and the .mo file is updated based on the new .po file to obtain the translation file.
[0011] Further, the spelling in the translation file is checked by lexical analysis to obtain the target translation file, including: Extracting all the translation texts in the translation file, comparing the translation texts with the target language dictionary based on lexical analysis, and determining that the translation texts are correctly spelled if the translation texts exist in the target language dictionary, and determining that the translation texts are incorrectly spelled if the translation texts do not exist in the target language dictionary; When it is determined that the spelling is wrong, the checking tool is used to remove the wrong character string and compare it with the target language dictionary again until the translation text exists in the target language dictionary, thereby obtaining the target translation file.
[0012] Furthermore, the target translation file is compared with the translation database to determine whether the translation content of the target translation file is correct, and when the final translation file is obtained, it includes: Extract all msgstr fields from the target translation file, search all msgstr fields in the translation database, and determine whether the translation content of the target translation file is correct based on the vocabulary overlap; When the vocabulary overlap is greater than or equal to a preset overlap threshold, it is determined that the translation content of the target translation file is correct; When the vocabulary overlap is less than a preset overlap threshold, the translation content of the target translation file is determined to be erroneous. When the translation content of the target translation file is determined to be erroneous, the erroneous translation content is corrected according to the context of the target translation file to obtain the final translation file.
[0013] Furthermore, when the translation language changes, a callback function is used to notify the application, and the application updates the interface and outputs information according to the translation language resource file. When the application calls the resource acquisition API to obtain the final translation file, it includes: When the translation language changes, a callback function is used to pass parameters to the application, triggering the application's induction, sending the translation language resource file to the application, updating the interactive interface and the output information according to the translation language resource file, and using a resource acquisition API to send the final translation file to the application.
[0014] Compared with the prior art, the beneficial effects of the present invention are as follows: by using the first tool, the second tool, the third tool and the program script, the management, update and maintenance process of the translation file are simplified, and there is no need to manually process the string in the source code, and there is no need to manually update the translation file. Through the cooperation of the Shell script and the tool, the string can be automatically extracted and merged into the .po file and the update is completed, the generation efficiency of the translation content is improved, the conversion and file compilation between different languages are automatically processed, the time of manual operation is reduced, not only the time cost is saved, but also the errors in manual operation are avoided, and the accuracy and integrity of the translation file are ensured. Each time the translation file is updated, the translation file will be subjected to lexical analysis and translation database comparison to ensure the accuracy of the translation content, so that the update process of the translation file is efficient and standardized, and inconsistent translation content is prevented from affecting the stability of the embedded system, and the quality of the final translation file is ensured, thereby improving the reliability and stability of the multi-language switching of the embedded system. The application is notified in time to update the language resource file through the callback function, and the fluency of the language switching is guaranteed.
[0015] On the other hand, the present application also provides a multi-language support framework for embedded systems, which is used to apply the multi-language implementation method for embedded systems, including: Language initialization module: loads the default language resource file and sets the environment variables, specifies a default language environment to obtain a target framework, uses macros to mark the text to be translated and calls the target framework; Language translation module: when switching the translation language, the default language resource file of the target framework is changed to the translation language resource file, the text to be translated is extracted from the source code of the application by a first tool to generate a .pot file, the pot file is translated by a second tool to generate a .po file, and the .po file is compiled into a .mo file by a third tool; Creating a new computer program Shell script, detecting new character strings in the source code according to the Shell script, merging the new character strings into the .po file, and updating the .mo file to obtain a translation file; Language detection module: uses lexical analysis to check the spelling in the translation file to obtain a target translation file, compares the target translation file with the translation database, determines whether the translation content of the target translation file is correct, and obtains a final translation file; Language change module: when the translation language changes, a callback function is used to notify the application, the application updates the interface and outputs information according to the translation language resource file, and the application calls the resource acquisition API to obtain the final translation file.
[0016] It is understandable that the above-mentioned multi-language support framework for embedded systems and its implementation method have the same beneficial effects, which will not be described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings: Figure 1 A flowchart of a multi-language implementation method for an embedded system provided by an embodiment of the present invention; Figure 2 A schematic diagram of the structure of a multi-language support framework for embedded systems provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0018] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art. It should be noted that, in the absence of conflict, the embodiments of the present invention and the features described in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0019] See also Figure 1 As shown, in some embodiments of the present application, this embodiment provides a multi-language implementation method for an embedded system, including: S100: Initialize the multi-language support framework, load the default language resource file and set the environment variables, specify a default language environment to obtain the target framework, use macros to mark the text to be translated and call the target framework; S200: when switching the translation language, changing the default language resource file of the target framework to the translation language resource file, using a first tool to extract the text to be translated from the source code of the application to generate a .pot file, using a second tool to translate the pot file and generate a .po file, and using a third tool to compile the .po file into a .mo file; S300: creating a new computer program Shell script, detecting new character strings in the source code according to the Shell script, merging the new character strings into the .po file, and updating the .mo file to obtain a translation file; S400: Check the spelling in the translation file by lexical analysis to obtain a target translation file, compare the target translation file with the translation database, determine whether the translation content of the target translation file is correct, and obtain a final translation file; S500: When the translation language changes, a callback function is used to notify the application, the application updates the interface and output information according to the translation language resource file, and the application calls a resource acquisition API to obtain the final translation file.
[0020] Specifically, the multi-language support framework is initialized and the default language resource file is loaded. The default language resource file is stored in a standard format. The default language environment is specified by setting an environment variable, such as LANG=en_US.UTF-8, to ensure that the default language can be correctly identified and applied after the multi-language support framework is initialized to generate a target framework. All texts to be translated are marked by macro definitions, and the text content to be translated is marked as an extractable text string, which is convenient for locating and extracting text strings in subsequent processes. The target framework is called to implement multi-language support. When switching the translation language, the default language resource file of the target framework is changed to the translation language resource file, so that the desired translation language can be obtained, such as: changing English to French, using the first tool to extract all text content marked as to be translated from the source code, and the text content to be translated contains text strings. Use the first tool to generate a .pot file and use the second tool to translate the .pot file into a .po file. The .po file is a text file that is directly operated by the translation. Use the third tool to compile the .po file into a .mo file. The .mo file is in binary format. The .mo file is small in size and fast to read, which is convenient for the embedded system to directly use the translated language. During the iteration process of the project, some new text content that needs to be translated will be added. By introducing Shell scripts to automatically detect new strings in the source code, merge the detected new strings into the existing .po files, and update the .mo files to obtain the translation files, the automation capabilities for updating and managing translation files are improved.
[0021] It is understandable that lexical analysis is used to check spelling errors in translation files, especially for proper nouns, technical terms and phrases in complex language environments. The translation files are corrected according to the results of spelling check to generate optimized target translation files, ensuring the accuracy and consistency of the translation content and the accuracy of the translation. The target translation file is compared with the existing translation entries in the translation database to determine whether the translation content is accurate and consistent. The translation database contains all the translation content that has been manually reviewed and can be used as a reference standard. After the verification and comparison are completed, the final translation file is generated to meet the accuracy when the embedded system switches the language. When the language is changed, the callback function is used to notify the application when the language is switched, quickly triggering the application to switch the language resource file and update the interface display and output information, including menus, buttons and prompt information. Calling the resource acquisition API to load the final translation file ensures that all texts displayed on the interface are the latest translation results. Through the combination of automation tools and scripts, the efficiency of translation management is effectively improved, the risk of manual operation and errors is reduced, and the efficiency and accuracy of multi-language applications in embedded systems are improved.
[0022] In some embodiments of the present application, when loading the default language resource file and setting the environment variable, it includes: using the bindtextdomain function to obtain the directory of the default language resource file, loading the default language resource file, and setting the LC_ALL environment variable.
[0023] It is understandable that by using the bindtextdomain function to specify the storage directory of the default language resource file, the default language resource file can be accurately loaded without causing loading failure. By setting the LC_ALL environment variable to explicitly specify the language environment, such as en_US.UTF-8, each file in the language environment can run according to a unified language standard. By binding the default language resource file directory and setting the environment variable, the problem of inconsistent translation languages is avoided. Setting the environment variable improves the response speed, the convenience of language switching, and the level of centralized management of the default language resource file.
[0024] In some embodiments of the present application, when the translation language is switched, the default language resource file of the target framework is changed to the translation language resource file, and the first tool is used to extract the text to be translated from the source code of the application to generate a .pot file, including: when the translation language is switched, the default language resource file of the target framework is changed to the translation language resource file and new environment variables are loaded for update, and the first command line tool xgettext is used to scan and obtain all text strings to be translated in the source code, and the text strings are stored in the .pot file.
[0025] Specifically, when switching the translation language, the default language resource file of the target framework is replaced with the translation language resource file and the environment variables are updated, providing a suitable language environment for subsequent changes to the translation content. After changing the default language resource file, the first command line tool xgettext is used to extract all the text strings to be translated in the source code to generate a .pot file. The xgettext tool will recursively scan all files in the source code to find the text strings marked by macros to be translated, so as to clearly indicate which text strings need to be translated and improve the accuracy of multi-language translation. All extracted text strings will be stored in the .pot file. The .pot file is a text file in a standard format used for cross-language translation. It not only records all the text strings to be translated, but also provides context information of the text strings, which is convenient for subsequent translation and debugging.
[0026] It is understandable that by switching the translation language to generate a .pot file, the translation language can be switched dynamically without restarting the application. By loading the translation language resource file and updating the environment variables, it can quickly adapt to the needs of different languages, meet the translation needs of embedded systems for different languages, and realize automatic extraction with the help of the xgettext tool, avoiding the manual search and extraction of the text to be translated, reducing the risk of missing text or extraction errors, and improving the efficiency and accuracy of translation file generation. The .pot file provides a standardized translation template, improves the accuracy and consistency of the translation, and only needs to create the corresponding .po file based on the translation template and complete the translation, which simplifies the translation process and provides automatic search, which facilitates the subsequent maintenance of multi-language support.
[0027] In some embodiments of the present application, when a second tool is used to translate a .pot file and generate a .po file, and a third tool is used to compile the .po file into a .mo file, it includes: using a second command line tool msginit to create a msgstr field based on the text string in the .pot file, generating a .po file with the translated text corresponding to the msgstr field, and using a third command line tool msgfmt to compile the .po file into a .mo file.
[0028] It is understandable that the second command line tool msginit pairs each text string in the .pot file with an empty field msgstr, scans each record in the .pot file, and puts the text string together with the corresponding msgstr field into the .po file. The second command line tool msginit can quickly generate a .po file, reducing manual operations and repetitive work. The third command line tool msgfmt is used to compile the .po file into a .mo file. The .mo file is a binary format for applications to efficiently load and query text strings. The .mo file is small in size and fast to read, which can meet the needs of use in embedded system environments. The msgfmt tool places the generated .mo file in a specified folder for dynamic loading by the application. Through the standardized format of .po and .mo files, translation of multiple languages can be supported. The second command line tool msginit generates .po files and the third command line tool msgfmt compiles .mo files, which realizes the automation of the translation process. Only the text strings need to be translated, and the rest are completed by the command line tool, avoiding the risk of omissions and losses in manual management.
[0029] In some embodiments of the present application, a new computer program Shell script is created, and a new string in the source code is detected according to the Shell script, and the new string is merged into a .po file and a .mo file is updated to obtain a translation file, including: establishing a shell script and scanning the source code, looking for a new string containing a translation mark, comparing the extracted new string with the text string, if a text string identical to the new string is found in the .pot file, the shell script removes the new string and continues to scan the source code, if a text string identical to the new string is not found in the .pot file, the shell script merges the new string into the .po file and updates the .mo file to obtain a translation file. For embedded systems that need to frequently update translation files, a Shell script can be used to directly extract new strings and merge them with existing .po files, thereby improving the management efficiency of translation files, simplifying the update process and realizing automatic updates, saving time for updating multiple languages of embedded systems, and reducing costs.
[0030] It is understandable that the established Shell script will search for new strings containing translation marks in the source code and extract them. The Shell script will compare each extracted new string with the existing text string in the .pot file. If a text string identical to the new string is found in the .pot file, the script will determine that the new string has been included in the translation template, thereby skipping the new string and continuing to scan other strings containing translation marks in the source code to avoid repeated processing. If a text string matching the new string is not found in the .pot file, the Shell script will add the new string to the .po file. After completing the merging of the .po files, the Shell script will also automatically call the third command line tool msgfmt to compile the merged .po file into a new .mo file to obtain a translation file.
[0031] In some embodiments of the present application, when the shell script adds a new string to the .po file and updates the .mo file to obtain a translation file, it includes: using the first command line tool xgettext to generate a new .pot file with the new string, using the msgmerge tool to merge the new .pot file with the .po file, and retaining the msgstr field in the .po file to obtain a new .po file, and updating the .mo file based on the new .po file to obtain a translation file.
[0032] It can be understood that the first command line tool xgettext is used to generate a new .pot file from a new string, which is consistent with the above-mentioned implementation method of generating a .pot file, and will not be repeated here. The msgmerge tool is used to merge the newly generated .pot file with the existing .po file. The merging adds the new string in the new .pot file to the .po file, and the msgstr field corresponding to the new string will be marked as untranslated. At the same time, the existing msgstr field in the .po file is retained to obtain a merged new .po file. The new .po file is compiled using the third command line tool msgfmt to obtain the new .po file and update the original .mo file to obtain a translation file. The translation file contains all the translation texts of the desired translation language, which improves the automatic degree of multi-language for embedded systems.
[0033] In some embodiments of the present application, lexical analysis is used to check the spelling in the translation file to obtain the target translation file, including: extracting all the translated texts in the translation file, comparing the translated texts with the target language dictionary based on lexical analysis, if the translated text exists in the target language dictionary, it is determined that the spelling is correct, if the translated text does not exist in the target language dictionary, it is determined that the spelling is incorrect, when it is determined that the spelling is incorrect, using a checking tool to remove the incorrect character string and compare it with the target language dictionary again until the translated text exists in the target language dictionary, and the target translation file is obtained.
[0034] It is understandable that all the translated texts are extracted from the translation file, and the translated texts contain the original text strings and new strings. In order to check the spelling accuracy of the translated texts, all the text strings and new strings are extracted, and the extracted text strings and new strings are checked using lexical analysis. Lexical analysis is a language processing technology that determines the accuracy of spelling by comparing the strings with the target language dictionary one by one. The target language dictionary contains all the known strings in the language. If the text strings and new strings in the translated text appear in the target language dictionary, it is determined that the spelling is correct. If a text string or new string in the translated text does not exist in the target language dictionary, it is determined that the spelling is wrong. When a spelling error is detected, a spelling check tool is automatically used to identify the wrong string and remove the wrong string. After removing the wrong string, the corrected translated text is compared with the target language dictionary. If the text string and the new string in the translated text are still not in the target language dictionary, the spell check tool will continue to perform spelling correction until the text string and the new string in the translated text can be found in the target language dictionary, until all spelling errors are corrected and the target translation file is obtained, thereby improving the accuracy of multi-language applications in embedded systems and effectively avoiding translation errors.
[0035] In some embodiments of the present application, a target translation file is compared with a translation database to determine whether the translation content of the target translation file is correct, and when a final translation file is obtained, the method includes: extracting all msgstr fields from the target translation file, searching all msgstr fields in the translation database, and determining whether the translation content of the target translation file is correct according to the vocabulary overlap; when the vocabulary overlap is greater than or equal to a preset overlap threshold, the translation content of the target translation file is determined to be correct; when the vocabulary overlap is less than the preset overlap threshold, the translation content of the target translation file is determined to be wrong; when the translation content of the target translation file is determined to be wrong, the wrong translation content is corrected according to the context of the target translation file to obtain a final translation file.
[0036] Specifically, all msgstr fields are extracted from the target translation file, which contain the actual content of the translation. The extracted msgstr fields are compared with all the translation contents in the translation database, which is a vocabulary database containing known standard translations. The vocabulary overlap between the target translation file and the standard translation in the translation database is calculated to determine whether the translation content of the target translation file is correct. The vocabulary overlap refers to the matching degree of the same vocabulary or term in the target translation file and the standard translation in the translation database. The matching between the same vocabulary or term includes word form restoration, synonym matching and case matching. The higher the vocabulary overlap, the higher the accuracy of the target translation file. The preset overlap threshold is set to 90%. When the vocabulary overlap is greater than or equal to 90%, the translation content of the target translation file is considered to be correct. When the vocabulary overlap is less than 90%, the translation content of the target translation file is determined to be wrong. When the translation content is determined to be wrong, the wrong translation content is replaced according to the context of the target translation file, and the target translation file is finally formed.
[0037] It can be understood that terminology consistency checking can automatically and objectively determine the accuracy of the translation content, improve the quality of multi-language translation of embedded systems, automatically correct errors when they are found, reduce manual intervention, and form a reliable and accurate target translation file, thereby providing high-quality translation support for multi-language embedded systems.
[0038] In some embodiments of the present application, when the translation language changes, a callback function is used to notify the application, the application updates the interface and output information according to the translation language resource file, and the application calls the resource acquisition API to obtain the final translation file, including: when the translation language changes, a callback function is used to pass parameters to the application, triggering the application's sensing, sending the translation language resource file to the application, updating the interactive interface and output information according to the translation language resource file, and using the resource acquisition API to send the final translation file to the application.
[0039] It is understandable that when the translation language changes, the corresponding parameters are passed to the application through the callback function, triggering the application's induction of the language change. It ensures that the application can respond in real time when switching languages. The role of the callback function is to notify the application that the current translation language has changed and send the translation language resource file to the application. The application updates the interface and output information according to the translation language resource file. The application will call the resource acquisition API to obtain the final translation file to ensure that the interface interaction and output information of the embedded system can correctly display the translation language of the final translation file. When switching the translation language, the callback function can immediately notify the application, triggering the application to change the interactive interface and update the output information. According to the loading of the translation language resource file, it can adapt to the needs of multiple languages, reduce manual operations and intervention, reduce the error rate, and improve the accuracy and flexibility of implementing multiple languages for embedded systems.
[0040] In summary, the beneficial effects of the present invention are: by using the first tool, the second tool, the third tool and the program script, the management, update and maintenance process of the translation file are simplified, and there is no need to manually process the string in the source code, and there is no need to manually update the translation file. Through the cooperation of Shell script and tool, the string can be automatically extracted and merged into the .po file and the update is completed, the generation efficiency of the translation content is improved, the conversion and file compilation between different languages are automatically processed, the time of manual operation is reduced, not only the time cost is saved, but also the error in the manual operation is avoided, and the accuracy and integrity of the translation file are ensured. Each time the translation file is updated, the translation file will be compared with the translation database to ensure the accuracy of the translation content, so that the update process of the translation file is efficient and standardized, and the inconsistent translation content is prevented from affecting the stability of the embedded system, and the quality of the final translation file is ensured, thereby improving the reliability and stability of the multi-language switching of the embedded system. The application is notified in time to update the language resource file through the callback function, and the fluency of the language switching is guaranteed.
[0041] In another preferred embodiment based on the above embodiment, refer to Figure 2 As shown, this embodiment provides a multi-language support framework for embedded systems, which is used to apply the multi-language implementation method for embedded systems, including: Language initialization module: load the default language resource file and set the environment variables, specify a default language environment to get the target framework, use macros to mark the text to be translated and call the target framework; Language translation module: when switching the translation language, the default language resource file of the target framework is changed to the translation language resource file, the first tool is used to extract the text to be translated from the source code of the application to generate a .pot file, the second tool is used to translate the pot file and generate a .po file, and the third tool is used to compile the .po file into a .mo file; Create a new computer program Shell script, detect new strings in the source code according to the Shell script, merge them into the .po file and update the .mo file to obtain the translation file; Language detection module: uses lexical analysis to check the spelling in the translation file to obtain the target translation file, compares the target translation file with the translation database, determines whether the translation content of the target translation file is correct, and obtains the final translation file; Language change module: When the translation language changes, a callback function is used to notify the application. The application updates the interface and output information according to the translation language resource file. The application calls the resource acquisition API to obtain the final translation file.
[0042] It can be understood that the language initialization module loads the default language resource file and sets the environment variable, specifies a default language environment to obtain the target framework, sets an initial language environment, and the language translation module replaces the default language resource file of the target framework with the translation language resource file, generates a .pot file by extracting the text to be translated in the source code, and then translates and generates a .po file, and finally compiles the .po file into a .mo file to complete the generation of the translation content. The newly created Shell script can automatically detect new strings in the source code, merge them into the original .po file and update the .mo file, ensuring the real-time update of the translation file without manual operation, improving the efficiency of translation, and reducing the risk of human omission of certain translation items. The language detection module uses lexical analysis technology to check the spelling in the translation file, and compares it with the translation database to determine the accuracy of the translation content and obtain the final translation file. The language change module notifies the application of language changes through the callback function, and the application updates the interface and output information according to the translation language resource file to ensure that the user interface is consistent with the translation language and ensure the fluency and timeliness of language switching.
[0043] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0044] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0045] These computer program instructions may also be stored in a computer-readable storage device that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable storage device produce a product including an instruction device that implements the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0046] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0047] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A multi-language implementation method for embedded systems, characterized in that: include: Initialize the multi-language support framework, load the default language resource file and set the environment variables, specify a default language environment to get the target framework, use macros to mark the text to be translated and call the target framework; When switching the translation language, the default language resource file of the target framework is changed to the translation language resource file, the text to be translated is extracted from the source code of the application program by a first tool to generate a .pot file, the pot file is translated by a second tool to generate a .po file, and the .po file is compiled into a .mo file by a third tool; Creating a new computer program Shell script, detecting new character strings in the source code according to the Shell script, merging the new character strings into the .po file, and updating the .mo file to obtain a translation file; Using lexical analysis to check the spelling in the translation file to obtain a target translation file, comparing the target translation file with a translation database to determine whether the translation content of the target translation file is correct, and obtaining a final translation file; When the translation language changes, a callback function is used to notify the application, the application updates the interface and outputs information according to the translation language resource file, and the application calls a resource acquisition API to acquire the final translation file.
2. The multi-language implementation method for embedded systems according to claim 1, characterized in that: When the default language resource file is loaded and the environment variables are set, include: The bindtextdomain function is used to obtain the directory of the default language resource file, load the default language resource file, and set the LC_ALL environment variable.
3. The multi-language implementation method for embedded systems according to claim 2, characterized in that: When switching the translation language, the default language resource file of the target framework is changed to the translation language resource file, and the first tool is used to extract the text to be translated from the source code of the application program to generate a .pot file, including: When switching the translation language, the default language resource file of the target framework is changed to the translation language resource file and the new environment variables are loaded for updating; A first command line tool xgettext is used to scan and obtain all text strings to be translated in the source code, and the text strings are stored in the .pot file.
4. The multi-language implementation method for embedded systems according to claim 3, characterized in that: The .pot file is translated by a second tool to generate a .po file, and the .po file is compiled by a third tool into a .mo file, including: A second command line tool msginit is used to create a msgstr field based on the text string in the .pot file, a translation text corresponding to the msgstr field is generated into a .po file, and a third command line tool msgfmt is used to compile the .po file into a .mo file.
5. The multi-language implementation method for embedded systems according to claim 4, characterized in that: Creating a new computer program Shell script, detecting a new string in the source code according to the Shell script, merging the new string into the .po file and updating the .mo file to obtain a translation file, comprising: The shell script is established and scans the source code to find a new string containing a translation mark, and the extracted new string is compared with the text string. If a text string identical to the new string is found in the .pot file, the shell script removes the new string and continues to scan the source code. If a text string identical to the new string is not found in the .pot file, the shell script merges the new string into the .po file and updates the .mo file to obtain the translation file.
6. The multi-language implementation method for embedded systems according to claim 5, characterized in that: The shell script adds the new string to the .po file and updates the .mo file to obtain the translation file, including: The first command line tool xgettext is used to generate a new .pot file from the new character string, the msgmerge tool is used to merge the new .pot file with the .po file, and the msgstr field in the .po file is retained to obtain a new .po file, and the .mo file is updated based on the new .po file to obtain the translation file.
7. The multi-language implementation method for embedded systems according to claim 6, characterized in that: The spelling in the translation file is checked by lexical analysis to obtain the target translation file, including: Extracting all the translation texts in the translation file, comparing the translation texts with the target language dictionary based on lexical analysis, and determining that the translation texts are correctly spelled if the translation texts exist in the target language dictionary, and determining that the translation texts are incorrectly spelled if the translation texts do not exist in the target language dictionary; When it is determined that the spelling is wrong, the checking tool is used to remove the wrong character string and compare it with the target language dictionary again until the translation text exists in the target language dictionary, thereby obtaining the target translation file.
8. The multi-language implementation method for embedded systems according to claim 7, characterized in that: The target translation file is compared with the translation database to determine whether the translation content of the target translation file is correct, and when the final translation file is obtained, it includes: Extract all msgstr fields from the target translation file, search all msgstr fields in the translation database, and determine whether the translation content of the target translation file is correct based on the vocabulary overlap; When the vocabulary overlap is greater than or equal to a preset overlap threshold, it is determined that the translation content of the target translation file is correct; When the vocabulary overlap is less than a preset overlap threshold, the translation content of the target translation file is determined to be erroneous. When the translation content of the target translation file is determined to be erroneous, the erroneous translation content is corrected according to the context of the target translation file to obtain the final translation file.
9. The multi-language implementation method for embedded systems according to claim 8, characterized in that: When the translation language changes, a callback function is used to notify the application, and the application updates the interface and outputs information according to the translation language resource file. When the application calls the resource acquisition API to obtain the final translation file, it includes: When the translation language changes, a callback function is used to pass parameters to the application, triggering the application's induction, sending the translation language resource file to the application, updating the interactive interface and the output information according to the translation language resource file, and using a resource acquisition API to send the final translation file to the application.
10. A multi-language support framework for embedded systems, applied to the multi-language implementation method for embedded systems as claimed in any one of claims 1 to 9, characterized in that: include: Language initialization module: loads the default language resource file and sets the environment variables, specifies a default language environment to obtain a target framework, uses macros to mark the text to be translated and calls the target framework; Language translation module: when switching the translation language, the default language resource file of the target framework is changed to the translation language resource file, the text to be translated is extracted from the source code of the application by a first tool to generate a .pot file, the pot file is translated by a second tool to generate a .po file, and the .po file is compiled into a .mo file by a third tool; Creating a new computer program Shell script, detecting new character strings in the source code according to the Shell script, merging the new character strings into the .po file, and updating the .mo file to obtain a translation file; Language detection module: uses lexical analysis to check the spelling in the translation file to obtain a target translation file, compares the target translation file with the translation database, determines whether the translation content of the target translation file is correct, and obtains a final translation file; Language change module: when the translation language changes, a callback function is used to notify the application, the application updates the interface and outputs information according to the translation language resource file, and the application calls the resource acquisition API to obtain the final translation file.
Citation Information
Patent Citations
Rapid development and maintenance system and method for embedded type network device interface language
CN102981851A
Code translation method and device, computer equipment and storage medium
CN110134404A
Operating system entry translation method and device and computer readable storage medium
CN114638240A
Method for checking multi-language definition
CN118605889A
Natural language translation and localization
EP3392782A1
Cited By
Embedded translation system and method with content auditing mechanism
CN121212166A