Multilingual adaptation methods, devices and computer equipment
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-21
- Publication Date
- 2026-08-14
AI Technical Summary
该方法的操作流程繁琐,导致源代码的多语言适配的效率低下
[0019]与相关技术相比,在本实施例中提供的多语言适配方法、装置和计算机设备,从源代码文件集合中获取源语言对应的多个源语言字符串,生成每个源语言字符串对应的标识,再以每个源语言字符串对应的标识为键名、每个源语言字符串为键值,构建第一键值对,并根据第一键值对更新源语言对应的当前源语言文件,得到更新源语言文件。接着,根据更新源语言文件确定多个待翻译源语言字符串,将每个待翻译源语言字符串翻译为目标语言对应的目标语言字符串,并根据每个目标语言字符串、以及每个目标语言字符串对应的待翻译源语言字符串对应的键名,更新目标语言对应的当前目标语言文件,得到更新目标语言文件。随后,确定每个源语言字符串对应的国际化代码,并将源代码文件中的每个源语言字符串替换为每个源语言字符串对应的国际化代码,得到更新源代码文件;其中,国际化代码用于指示更新源代码文件基于更新源语言文件和更新目标语言文件进行多语言切换。
Smart Images

Figure CN122570002A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, and in particular to multilingual adaptation methods, apparatus and computer equipment. Background Technology
[0002] With the increasing globalization of web development, more and more web applications need to support multiple languages. Internationalization (i18n) enables the same code to dynamically adapt to the needs of users in different languages or regions, making its implementation crucial.
[0003] However, current internationalization solutions typically rely on developers searching for hard-coded text in the code, manually extracting the text and configuring multilingual resources. This method is cumbersome and leads to inefficiency in adapting the source code to multiple languages.
[0004] There is currently no effective solution to the problem of low efficiency in multilingual adaptation of source code in related technologies. Summary of the Invention
[0005] This embodiment provides a multilingual adaptation method, apparatus, and computer device, aiming to improve the efficiency of multilingual adaptation of source code.
[0006] Firstly, this embodiment provides a multilingual adaptation method, which includes:
[0007] Extract multiple source language strings corresponding to the source language from the source code file collection, and generate an identifier for each source language string;
[0008] Using the identifier corresponding to each source language string as the key name and each source language string as the key value, construct a first key-value pair, and update the current source language file corresponding to the source language according to the first key-value pair to obtain the updated source language file;
[0009] Based on the updated source language file, multiple source language strings to be translated are determined, and each source language string to be translated is translated into the target language string corresponding to the target language.
[0010] Based on each target language string and the key name corresponding to the source language string to be translated for each target language string, update the current target language file corresponding to the target language to obtain the updated target language file;
[0011] The internationalization code corresponding to each source language string is determined, and each source language string in the source code file is replaced with the internationalization code corresponding to each source language string to obtain an updated source code file; wherein, the internationalization code is used to instruct the updated source code file to perform multilingual switching based on the updated source language file and the updated target language file.
[0012] Secondly, this embodiment provides a multilingual adaptation device, which includes:
[0013] The generation module is used to obtain multiple source language strings corresponding to the source language from the source code file collection and generate an identifier for each source language string;
[0014] The first update module is used to construct a first key-value pair with the identifier corresponding to each source language string as the key name and each source language string as the key value, and update the current source language file corresponding to the source language according to the first key-value pair to obtain the updated source language file;
[0015] The translation module is used to determine multiple source language strings to be translated based on the updated source language file, and to translate each source language string to be translated into the target language string corresponding to the target language.
[0016] The second update module is used to update the current target language file corresponding to the target language according to each target language string and the key name corresponding to the source language string to be translated for each target language string, so as to obtain the updated target language file;
[0017] The third update module is used to determine the internationalization code corresponding to each source language string, and replace each source language string in the source code file with the internationalization code corresponding to each source language string to obtain an updated source code file; wherein, the internationalization code is used to instruct the updated source code file to perform multilingual switching based on the updated source language file and the updated target language file.
[0018] Thirdly, this embodiment provides a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the multilingual adaptation method described in the first aspect above.
[0019] Compared with related technologies, the multilingual adaptation method, apparatus, and computer device provided in this embodiment obtain multiple source language strings corresponding to the source language from a set of source code files, generate an identifier corresponding to each source language string, construct a first key-value pair using the identifier corresponding to each source language string as the key name and each source language string as the key value, and update the current source language file corresponding to the source language according to the first key-value pair to obtain an updated source language file. Next, multiple source language strings to be translated are determined based on the updated source language file, each source language string to be translated is translated into a target language string corresponding to the target language, and the current target language file corresponding to the target language is updated according to each target language string and the key name corresponding to the source language string to be translated, to obtain an updated target language file. Subsequently, the internationalization code corresponding to each source language string is determined, and each source language string in the source code file is replaced with the internationalization code corresponding to each source language string to obtain an updated source code file; wherein, the internationalization code is used to instruct the updated source code file to perform multilingual switching based on the updated source language file and the updated target language file.
[0020] In this way, by automatically extracting source language strings from the source code file collection and generating unique identifiers, the first key-value pair is constructed to update the source language file, avoiding the need for manual searching and defining key names one by one, significantly reducing the risk of omissions or duplicate definitions. Furthermore, based on the updated source language file, strings to be translated are selected, and the target language file is updated by associating the translated target language strings with the same key name, ensuring consistent mapping between the source and target languages. This eliminates the need for manual alignment of translation entries, reducing the complexity of maintaining multilingual files. Finally, the source language strings in the source code are automatically replaced with corresponding internationalization code, enabling runtime to dynamically load and update the source language file or the corresponding strings in the target language file according to the current language environment, achieving multilingual switching. This eliminates the need for developers to manually intervene in each step, greatly improving the efficiency of multilingual adaptation of the source code, and facilitating synchronous updates when adding, deleting, or modifying language resources.
[0021] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description
[0022] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments of this application and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0023] Figure 1 This is a flowchart of an embodiment of the multilingual adaptation method provided in this application;
[0024] Figure 2 This is a flowchart of Embodiment 2 of the multilingual adaptation method provided in this application;
[0025] Figure 3 This is a flowchart of Embodiment 3 of the multilingual adaptation method provided in this application;
[0026] Figure 4 This is a flowchart of Embodiment 4 of the multilingual adaptation method provided in this application;
[0027] Figure 5 This is a flowchart of Embodiment 5 of the multilingual adaptation method provided in this application;
[0028] Figure 6 This is a flowchart of Embodiment Six of the Multilingual Adaptation Method provided in this application;
[0029] Figure 7 This is a flowchart of Embodiment Seven of the Multilingual Adaptation Method provided in this application;
[0030] Figure 8 This is a flowchart of Embodiment 8 of the multilingual adaptation method provided in this application;
[0031] Figure 9 This is a flowchart of Embodiment Nine of the Multilingual Adaptation Method provided in this application;
[0032] Figure 10 This is a structural block diagram of the multilingual adapter provided in this application. Detailed Implementation
[0033] To better understand the purpose, technical solution, and advantages of this application, the application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0034] Unless otherwise defined, the technical or scientific terms used in this application shall have the general meaning understood by one of ordinary skill in the art to which this application pertains. Words such as “a,” “an,” “an,” “the,” “the,” and “these” used in this application do not indicate quantitative limitation and may be singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or modules (units) is not limited to the listed steps or modules (units) but may include steps or modules (units) not listed, or may include other steps or modules (units) inherent to these processes, methods, products, or devices. Words such as “connected,” “linked,” and “coupled” used in this application are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. “Multiple” used in this application refers to two or more. “And / or” describes the relationship between related objects, indicating that three relationships may exist; for example, “A and / or B” can represent: A alone, A and B simultaneously, and B alone. Normally, the character " / " indicates that the objects before and after it are in an "or" relationship. The terms "first," "second," "third," etc., used in this application are merely to distinguish similar objects and do not represent a specific order of objects.
[0035] The following specific embodiments are given to illustrate the technical solution of this application in detail.
[0036] Figure 1 This is a flowchart of an embodiment of the multilingual adaptation method provided in this application. Please refer to... Figure 1 The method provided in this embodiment may include the following steps:
[0037] Step S101: Obtain multiple source language strings corresponding to the source language from the source code file collection, and generate an identifier corresponding to each source language string.
[0038] It should be noted that the source code file collection includes multiple source code files, such as Vue component files (.vue), JavaScript script files (.js), etc. The source code in this type of file is various business code that needs to be internationalized (i18n), covering development scenarios such as web applications, mobile H5 applications, and mini-program front-ends.
[0039] Specifically, in scenarios such as projects requiring multilingual capabilities, source code updates, new business functions, or new target language adaptation requirements, the process iterates through each source code file in the source code file collection. Static analysis (e.g., regular expression matching) is used to parse the content of each source code file to extract multiple source language strings corresponding to the source language in each file. These source language strings are hard-coded strings that need to be internationalized. The source language is the basic native language set for the current project, including but not limited to Chinese, English, Korean, and Japanese. For example, if the source language is set to Chinese, the source language string might be text such as "Login," "Please enter username," or "Please select departure city."
[0040] Furthermore, for each extracted source language string, it can be processed using hash algorithms, character encoding (e.g., Base64 encoding), or custom encoding rules (e.g., module name_serial number) to generate a unique identifier for each source language string.
[0041] It should be understood that identifiers within the same project scope should not be duplicated. If the source language string content is the same, the generated identifier will be the same to avoid subsequent duplicate translations of the same source language string.
[0042] Step S102: Construct a first key-value pair using the identifier corresponding to each source language string as the key name and each source language string as the key value, and update the current source language file corresponding to the source language according to the first key-value pair to obtain the updated source language file.
[0043] Specifically, a first key-value pair is constructed based on each source language string and its corresponding identifier. The first key-value pair uses the identifier corresponding to each source language string as the key name and the source language string itself as the key value. For example, if the source language string is "Please select departure city", and its corresponding identifier is "auto.tran15efc64c8e8760bc", then the first key-value pair would be: "auto.tran15efc64c8e8760bc"; "Please select departure city".
[0044] Furthermore, retrieve the current source language file corresponding to the source language in the project. It should be noted that source language files are typically in JSON format, for example, the Chinese language pack zh-CN.json. Also, the current source language file can be an empty file that does not store any key-value pairs, or a non-empty file that already contains several source language key-value pairs. Each key-value pair in the file uses the identifier corresponding to the source language string as the key and the source language string as the value.
[0045] Next, the first key-value pair is stored in the current source language file to update the current source language file, resulting in the updated source language file.
[0046] Step S103: Determine multiple source language strings to be translated based on the updated source language file, and translate each source language string to be translated into the target language string corresponding to the target language.
[0047] In this step, all key names in the updated source language file and all key names in the current target language file are extracted. All key names in the updated source language file are compared one by one with all key names in the current target language file to filter out key names that exist only in the updated source language file and are not recorded in the current target language file. The source language string corresponding to each of the filtered key names is determined as the source language string to be translated.
[0048] It should be noted that the target languages mentioned above refer to languages other than the source language that the project needs to adapt to, including but not limited to Chinese, English, Korean, and Japanese. Referring back to the previous examples, if the source language is set to Chinese, the target language can be English, Korean, Japanese, etc. Similarly, if the source language is set to Korean, the target language can be Chinese, English, Japanese, etc.
[0049] It should be understood that the current target language file and the source language file usually maintain the same format. The current target language file can be an empty file that does not store any text data, or it can be a non-empty file that already contains several target language key-value pairs. Each key-value pair in the file uses an identifier as the key name and the corresponding target language string as the key value.
[0050] Furthermore, the pre-configured translation interface is invoked to translate each source language string to be translated into the target language string corresponding to the target language.
[0051] Step S104: Based on each target language string and the key name corresponding to the source language string to be translated for each target language string, update the current target language file corresponding to the target language to obtain the updated target language file.
[0052] Specifically, based on each target language string and the key name corresponding to the source language string to be translated for each target language string, a third key-value pair is constructed, and the third key-value pair is stored in the current target language file corresponding to the target language to update the current target language file and obtain the updated target language file.
[0053] Based on the previous example, the source language and target language are Chinese and English, respectively. If the first key-value pair is: "auto.tran15efc64c8e8760bc"; "Please select departure city", then the corresponding third key-value pair is: "auto.tran15efc64c8e8760bc"; "Please select departure city".
[0054] Step S105: Determine the internationalization code corresponding to each source language string, and replace each source language string in the source code file with the internationalization code corresponding to each source language string to obtain the updated source code file; wherein, the internationalization code is used to instruct the updated source code file to perform multilingual switching based on the updated source language file and the updated target language file.
[0055] Specifically, based on the pre-configured internationalized function call format, the identifier corresponding to each source language string is converted into the corresponding internationalized code. For example, if the identifier corresponding to the source language string is "auto.tran15efc64c8e8760bc", then the generated internationalized code is: .
[0056] Then, the source code file is traversed, and each source language string in the source code file is replaced with the internationalization code corresponding to that source language string in order to obtain an updated source code file.
[0057] It should be noted that the internationalization code includes an identifier corresponding to the source language string. This identifier is used to accurately associate and index the corresponding string data in the source language file or the target language file during the actual runtime of the source code file update. In practice, based on the user's selected target language, the matching string content in the corresponding language file can be automatically loaded, thereby achieving dynamic multilingual switching display of the updated source code file.
[0058] The multilingual adaptation method provided in this embodiment obtains multiple source language strings corresponding to the source language from a set of source code files, generates an identifier for each source language string, constructs a first key-value pair using the identifier as the key name and each source language string as the key value, and updates the current source language file corresponding to the source language based on the first key-value pair to obtain an updated source language file. Further, multiple source language strings to be translated are determined based on the updated source language file, each source language string to be translated is translated into a target language string corresponding to the target language, and the current target language file corresponding to the target language is updated based on each target language string and the key name corresponding to each target language string's source language string to be translated, to obtain an updated target language file. Subsequently, the internationalization code corresponding to each source language string is determined, and each source language string in the source code file is replaced with the corresponding internationalization code to obtain an updated source code file; wherein, the internationalization code is used to instruct the updated source code file to perform multilingual switching based on the updated source language file and the updated target language file. In this way, by automatically extracting source language strings from the source code file collection and generating unique identifiers, the first key-value pair is constructed to update the source language file, avoiding the need for manual searching and defining key names one by one, significantly reducing the risk of omissions or duplicate definitions. Next, based on the updated source language file, strings to be translated are selected, and the target language file is updated by associating the translated target language strings with the same key name, ensuring consistent mapping between the source and target languages. This eliminates the need for manual alignment of translation entries, reducing the complexity of maintaining multilingual files. Finally, the source language strings in the source code are automatically replaced with corresponding internationalization code, enabling runtime to dynamically load and update the source language file or the corresponding strings in the target language file according to the current language environment, achieving multilingual switching. This eliminates the need for developers to manually intervene in each step, greatly improving the efficiency of multilingual adaptation of the source code, and facilitating synchronous updates when adding, deleting, or modifying language resources.
[0059] Figure 2 The flowchart for Embodiment 2 of the multilingual adaptation method provided in this application is shown below. Please refer to... Figure 2 Based on the above embodiments, multiple source language strings corresponding to the source language are obtained from the source code file set, including:
[0060] Step S201: Select multiple specified source code files from the source code file set that meet the specified conditions.
[0061] Specifically, the source code file set is filtered according to preset specified conditions to remove source code files that do not meet the specified conditions, ultimately resulting in multiple specified source code files to be internationalized. The specified conditions can be used to indicate the types of source code files to be retained, and / or to indicate the directories of files to be excluded.
[0062] For example, taking a typical front-end project, the set of source code files is all files under the project's `src` directory. The specified criteria are: only filter out `.vue` component files and `.js` script files; and during the filtering process, skip the `node_modules`, `.git`, `dist`, `build`, `assets`, `utils`, `plugins`, `filters`, `router`, and `api` directories. These skipped directories can be modified through the `SKIPPED_DIRECTORIES` constant. All files that meet the requirements after filtering according to these criteria constitute the specified source code files to be internationalized.
[0063] Step S202: For each specified source code file, extract the target source code from the specified source code file according to the extraction rules corresponding to the file category of the specified source code file, and generate the abstract syntax tree corresponding to the target source code.
[0064] Specifically, for each selected source code file, the target source code is extracted from the file based on the corresponding extraction rules matched according to the file's category. After code extraction, the extracted target source code is parsed into an abstract syntax tree using a specified parsing tool (e.g., @babel / parser, Acorn, Espree, Meriyah, etc.). Configurable parsing plugins adaptable to multiple syntaxes are available, including but not limited to Vue, JSX, and TypeScript parsing plugins.
[0065] For example, for a specified source code file in .vue format, first read the entire file content, then extract only the relevant parts according to the Vue file extraction rules. <script>标签内的代码作为目标源代码,同时记录<script>内容在整个Vue文件中的字符起始偏移量(offset)。将<script>内容输入指定解析工具解析为抽象语法树,此时抽象语法树中的节点的位置信息(包括节点的起始位置start和结束位置end)是相对于<script>内容起始位置的。随后,将节点的起始位置start和结束位置end分别加上offset,从而将节点的位置信息还原为其在整个Vue文件中的绝对位置。再例如,针对.js格式的指定源代码文件,直接读取文件全部内容作为目标源代码,其字符起始偏移量为0。将整个.js文件的内容输入指定解析工具解析为抽象语法树,此时抽象语法树中的节点的位置信息即为节点在.js文件中的绝对位置。
[0066] 步骤S203,针对每个抽象语法树,识别抽象语法树中的多个初始字符串节点。
[0067] 在本步骤中,通过预设的字符串提取函数对每个抽象语法树进行处理,以识别抽象语法树中包含文本内容的多个初始字符串节点。并且,在识别过程中,同步记录每个初始字符串节点中的字符串在相应源代码中的起始位置、结束位置以及行号。
[0068] 步骤S204,对多个初始字符串节点进行过滤,得到多个目标字符串节点,并从多个目标字符串节点中提取多个源语言字符串;其中,多个目标字符串节点包括字符串字面量节点和模板字面量节点。
[0069] 在本步骤中,按照预设的过滤条件对识别出的所有初始字符串节点进行筛选,得到多个目标字符串节点,该多个目标字符串节点包括字符串字面量节点和模板字面量节点。
[0070] 需要说明的是,过滤条件可以为基于文本特征校验的筛选规则和基于正则规则匹配的筛选规则。具体实现时,校验每个初始字符串节点对应的字符串内容本身的文本特征,以过滤多个初始字符串节点中的空字符串节点、文件路径字符串节点、统一资源定位符(URL)字符串节点等。并且,通过预设正则规则匹配各个初始字符串节点对应的字符串格式,以过滤多个初始字符串节点中的纯英文标识符字符串节点、ES6模板变量字符串节点、用户界面(UI)组件中的通知消息字符串节点等无需国际化的字符串节点。
[0071] 本实施例提供的方法,通过按文件类型筛选待处理代码文件,结合抽象语法树精准识别字符串节点,再基于预设的过滤条件剔除空字符串、文件路径、URL、纯英文标识符、ES6模板变量及UI通知消息等无需国际化的节点,从而提取出需要翻译的源语言字符串。以此,避免无效字符串对后续多语言文件的干扰,同时能够减少后续字符串翻译量,提升语言文件更新效率。
[0072] 图3为本申请提供的多语言适配方法实施例三的流程图。请参照图3,在上述实施例的基础上,确定每个源语言字符串对应的国际化代码,包括:
[0073] 步骤S301,针对每个源语言字符串,根据源语言字符串对应的抽象语言树,确定源语言字符串在抽象语法树对应的目标指定源代码文件中的位置信息,得到源语言字符串的位置信息。
[0074] 具体的,针对每个源语言字符串,从源语言字符串对应的抽象语言树中获取该源语言字符串对应的字符串节点的起始位置start和结束位置end。若文件为.js格式(offset为0),则字符串节点的起始位置start和结束位置end为该源语言字符串在文件中的绝对位置;若文件为.vue格式,则将字符串节点的起始位置start和结束位置end分别加上前述记录的offset,得到该源语言字符串在整个.vue文件中的绝对位置。同时,可根据源语言字符串的绝对位置信息计算源语言字符串在目标指定源代码文件中的行号,并将源语言字符串在目标指定源代码文件中的绝对位置、行号作为源语言字符串的位置信息。
[0075] 步骤S302,根据源语言字符串的位置信息,从目标指定源代码文件中查找源语言字符串的上下文代码,并根据目标指定源代码文件的文件类别、以及上下文代码,确定源语言字符串对应的实际嵌入场景。
[0076] 在本步骤中,根据源语言字符串的位置信息,定位并提取该源语言字符串在目标指定源代码文件中的上下文代码,并结合目标指定源代码文件的文件类别,对上下文代码的语法结构与代码环境进行分析,以确定源语言字符串对应的实际嵌入场景。
[0077] 具体实现时,在目标指定源代码文件为.vue文件时,根据上下文代码检测源语言字符串是否位于<template>标签内、是否处于箭头函数上下文、是否属于props默认值配置场景。其中,若检测到源语言字符串未位于<script>标签内,则确定实际嵌入场景为Vue模板场景;若检测到源语言字符串位于<script>标签内,且未处于箭头函数上下文,则确定实际嵌入场景为Vue脚本(普通函数)场景;若检测到源语言字符串位于<script>标签内,且处于箭头函数上下文,则确定实际嵌入场景为Vue脚本(箭头函数)场景;若检测到源语言字符串位于Vue组件的props定义中的default函数内部,则确定实际嵌入场景为Props默认值配置场景。
[0078] 在目标指定源代码文件为.js文件时,根据上下文代码检测源语言字符串是否处于箭头函数上下文。其中,若检测到源语言字符串未处于箭头函数上下文,则确定实际嵌入场景为JS文件(普通函数)场景;若检测到源语言字符串处于箭头函数上下文,则确定实际嵌入场景为JS文件(箭头函数)场景。
[0079] 步骤S303,从预设的国际化函数调用格式与嵌入场景的对应关系中查找实际嵌入场景对应的目标国际化函数调用格式。
[0080] 具体实现时,例如,预设的国际化函数调用格式与嵌入场景的对应关系,包括:(1)Vue模板场景:;(2)Vue脚本(普通函数)场景:;(3)Vue脚本(箭头函数)场景:;(4)Props默认值配置场景:;(5)JS文件(普通函数)场景:;(6)JS文件(箭头函数)场景:。其中,key为源语言字符串对应的标识。
[0081] 步骤S304,根据目标国际化函数调用格式,将源语言字符串对应的标识转换为初始国际化代码,并将初始国际化代码确定为源语言字符串对应的国际化代码。
[0082] 具体的,按照查找得到的目标国际化函数调用格式,将源语言字符串对应的标识转换为初始国际化代码,以使国际化代码适配源语言字符串的实际嵌入场景,确保后续替换后的代码语法正确。
[0083] 本实施例提供的方法,通过获取每个源语言字符串在相应源代码文件中的位置信息,并根据源代码文件类别与源语言字符串的上下文代码,识别出源语言字符串对应的实际嵌入场景,进而预设的对应关系查找确定匹配的国际化函数调用格式。以此,针对不同源语言字符串对应的实际嵌入场景匹配国际化函数调用格式,避免替换后的代码出现语法错误、函数调用异常等问题。
[0084] 图4为本申请提供的多语言适配方法实施例四的流程图。请参照图4,在上述实施例的基础上,根据更新源语言文件确定多个待翻译源语言字符串,包括:
[0085] 步骤S401,获取多个指定源代码文件中的所有国际化代码,并提取各个国际化代码中的键名,得到第一键名集合。
[0086] 具体的,遍历各个指定源代码文件,获取指定源代码文件中的所有国际化代码,并从各个国际化代码中提取出键名,得到第一键名集合。
[0087] 需要说明的是,上述国际化代码所采用的函数包括但不限于、i18n.t()、、__()、t()。例如,国际化代码可为、i18n.t('auto.tran2a3b4c5d6e7f8g9h')等。
[0088] 步骤S402,提取当前目标语言文件中的所有键名,得到第二键名集合。
[0089] 具体的,获取项目中当前已存在的目标语言文件,并从当前目标语言文件中提取出所有键名,得到第二键名集合。
[0090] 步骤S403,确定第一键名集合与第二键名集合的第一差集。
[0091] 具体的,将第一键名集合和第二键名集合进行差集运算,得到第一键名集合与第二键名集合的第一差集。该第一差集中的第一键名为仅存在于第一键名集合中、未在第二键名集合中记录的键名。
[0092] 步骤S404,从更新源语言文件中查找第一差集中的各个第一键名对应的源语言字符串,并将查找到的源语言字符串确定为多个待翻译源语言字符串。
[0093] 在本步骤中,根据第一差集中的所有第一键名,在更新后的源语言文件中进行匹配查询,获取每个第一键名对应的源语言字符串,并将匹配查询到的源语言字符串确定为待翻译源语言字符串。
[0094] 本实施例提供的方法,通过提取源代码文件与目标语言文件中的键名并进行差集运算,筛选出代码中新增使用且尚未翻译的源语言字符串,从而能够精准识别增量待翻译数据,避免重复翻译和人工核对产生的误差,大幅提升多语言翻译的处理效率。同时,能够保证源语言文件与目标语言文件的键名同步,确保多语言适配的完整性和准确性。
[0095] 图5为本申请提供的多语言适配方法实施例五的流程图。请参照图5,在上述实施例的基础上,对多个初始字符串节点进行过滤,得到多个目标字符串节点,包括:
[0096] 步骤S501,按照第一过滤条件对多个初始字符串节点进行过滤,得到多个备选字符串节点。
[0097] 在本实施例中,第一过滤条件包括但不限于基于字符串内容特征、正则表达式匹配、代码行文本以及字符串位置信息组合构建的多层过滤规则。
[0098] 具体实现时,按照第一过滤条件对多个初始字符串节点进行过滤,得到多个备选字符串节点。过滤规则包括:过滤空字符串或纯空格对应的字符串节点;通过正则匹配过滤纯英文标识符格式的字符串节点、以及包含ES6模板变量插值的字符串节点;根据字符串内容过滤文件路径、URL链接格式的字符串节点;根据字符串所在行文本与位置信息,过滤处于三元表达式中的字符串节点;根据字符串所在位置前的文件内容与字符串位置,过滤位于代码注释中的字符串节点;通过行文本正则匹配,过滤Element UI等前端UI框架的消息通知组件内的字符串节点。
[0099] 步骤S502,针对每个备选字符串节点,在抽象语法树中查找备选字符串节点的父节点,并在父节点满足第二过滤条件时,将备选字符串节点确定为无效节点;其中,第二过滤条件包括:父节点为函数调用节点、且父节点对应的调用函数为国际化函数或父节点对应的调用对象为控制台对象。
[0100] 具体的,针对每个备选字符串节点,在抽象语法树中查找该备选字符串节点的父节点,基于抽象语法树的语法结构校验父节点的类型与调用关系。当父节点为函数调用节点(CallExpression)时,判断节点的调用属性。若调用函数为等国际化函数,表明该备选字符串已完成国际化,无需重复处理;若调用对象为console控制台对象,表明该备选字符串为日志输出类文本。在满足上述任一情况时,将该备选字符串节点标记为无效节点。
[0101] 步骤S503,将多个备选字符串节点中的无效节点剔除,得到多个目标字符串节点。
[0102] 具体的,将多个备选字符串节点中的无效节点剔除,剩余的字符串节点即为最终的目标字符串节点。
[0103] 本实施例提供的方法,通过多维过滤条件对初始字符串节点进行筛选,避免代码格式变化影响节点筛选,从而提升字符串阶段筛选的准确性与鲁棒性,最终精准提取出需国际化处理的目标字符串节点。
[0104] 图6为本申请提供的多语言适配方法实施例六的流程图。请参照图6,在上述实施例的基础上,生成每个源语言字符串对应的标识,包括:
[0105] 步骤S601,针对每个源语言字符串,对源语言字符串进行哈希运算,得到源语言字符串对应的原始哈希值。
[0106] 具体的,通过哈希算法对每个源语言字符串进行运算,得到源语言字符串对应的原始哈希值。其中,哈希算法包括但不限于MD5哈希算法、SHA-1哈希算法、SHA-256哈希算法。
[0107] 步骤S602,根据预设的截取策略从原始哈希值中截取部分哈希值;其中,截取策略用于指示从原始哈希值中的预设起始位置开始截取预设位数的值作为部分哈希值。
[0108] 具体实现时,例如,按照预设的截取规则,从原始哈希值的首位起始位置开始精准截取前16位字符作为部分哈希值。需要说明的是,截取的预设起始位置和预设位数的值可根据实际应用需求灵活调整。
[0109] 步骤S603,根据预设前缀、以及部分哈希值,生成源语言字符串对应的标识。
[0110] 具体的,将预设前缀与截取的部分哈希值进行拼接,得到源语言字符串对应的标识。其中,预设前缀可根据实际应用需求进行自定义配置,以适配不同项目的使用需求。
[0111] 例如,预设前缀为"auto.tran”,截取的部分哈希值为"15efc64c8e8760bc”,则最终生成的标识为"auto.tran15efc64c8e8760bc”。
[0112] 本实施例提供的方法,通过哈希运算生成唯一原始值后截取部分哈希值,并将截取的部分哈希值与预设前缀进行拼接,得到源语言字符串对应的标识,以此确保源语言字符串与表示的唯一对应关系。同时,结合预设前缀可实现键名的统一规范化管理。
[0113] 图7为本申请提供的多语言适配方法实施例七的流程图。请参照图7,在上述实施例的基础上,当前源语言文件包括多个分组,不同分组对应不同类别的键名;根据第一键值对更新源语言对应的当前源语言文件,得到更新源语言文件,包括:
[0114] 步骤S701,提取当前源语言文件中的所有键名,得到第三键名集合。
[0115] 需要说明的是,当前源语言文件内置多个分组,不同分组对应不同类别的键名。例如,可根据键名的前缀字段确定分组名。结合前面的例子,分组名可以为auto。
[0116] 具体的,若当前源语言文件未存储任何键值对数据,则第三键名集合为空集。若当前源语言文件已包含若干源语言键值对,则提取出当前源语言文件中的所有键名进行汇总,得到第三键名集合。
[0117] 步骤S702,提取第一键值对中的所有键名,得到第四键名集合。
[0118] 具体的,遍历第一键值对中的所有键名并提取,将提取出的所有键名进行汇总,得到第四键名集合。
[0119] 步骤S703,确定第三键名集合与第四键名集合的第二差集。
[0120] 具体的,将第三键名集合和第四键名集合进行差集运算,得到第三键名集合与第四键名集合的第二差集。该第二差集中的第二键名为仅存在于第四键名集合中、未在第三键名集合中记录的键名。
[0121] 步骤S704,根据第二差集中的每个第二键名所属的类别,确定每个第二键名对应的分组,并将每个第二键名、以及每个第二键名对应的源语言字符串关联写入每个第二键名对应的分组中,得到更新源语言文件。
[0122] 具体实现时,可根据第二键名的前缀字段确定该第二键名所属的类别,并根据该第二键名所属的类别确定其对应的分组。例如,第二键名"auto.tran15efc64c8e8760bc”归类至auto分组。
[0123] 进一步的,根据每个第二键名、以及每个第二键名对应的源语言字符串,构建新的键值对,并将新的键值对写入该第二键名对应的分组中,得到更新源语言文件。
[0124] 本实施例提供的方法,通过提取当前源语言文件与第一键值对中的键名集合,并计算两者的差集,以精准识别出新增的键名,从而仅将未记录的键名及其对应的源语言字符串按类别分组写入源语言文件。这样,在避免键名重复的同时,实现源语言文件的增量更新。不仅如此,根据键名类别自动归类到对应分组,使语言文件结构清晰,以便于后续查找与维护。
[0125] 图8为本申请提供的多语言适配方法实施例八的流程图。请参照图8,在上述实施例的基础上,将每个待翻译源语言字符串翻译为目标语言对应的目标语言字符串,包括:
[0126] 步骤S801,针对每个待翻译源语言字符串,在检测到本地翻译缓存中存在待翻译源语言字符串对应的目标键名时,从本地翻译缓存中提取目标键名对应的目标语言字符串。
[0127] 具体的,针对每个待翻译源语言字符串,预先检测到本地翻译缓存中是否存在待翻译源语言字符串对应的目标键名。若本地翻译缓存中存在待翻译源语言字符串对应的目标键名,则直接从缓存中读取目标语言字符串。
[0128] 需要说明的是,在每次目标语言文件更新后,将本次翻译得到的目标语言字符串及其对应的键名保存至本地翻译缓存中。
[0129] 步骤S802,在检测到本地翻译缓存中不存在待翻译源语言字符串对应的键名时,调用预配置的翻译接口对待翻译源语言字符串进行翻译,得到翻译结果;其中,翻译结果用于表征待翻译源语言字符串是否翻译成功、以及在翻译成功时,翻译结果包括待翻译源语言字符串对应的目标语言字符串。
[0130] 具体的,若本地翻译缓存中不存在待翻译源语言字符串对应的目标键名,则调用预配置的第三方翻译接口对待翻译源语言字符串进行翻译,并接收返回的翻译结果。
[0131] 需要说明的是,翻译结果用于表征待翻译源语言字符串是否翻译成功。并且,在翻译成功时,翻译结果包括待翻译源语言字符串对应的目标语言字符串;在翻译失败时,翻译结果包括翻译失败的标记信息。
[0132] 步骤S803,在翻译结果表征翻译成功时,从翻译结果中提取待翻译源语言字符串对应的目标语言字符串。
[0133] 具体的,当翻译结果表征翻译成功,从翻译结果中提取待翻译源语言字符串对应的目标语言字符串,将其作为有效翻译数据。
[0134] 步骤S804,在翻译结果表征翻译失败时,再次调用翻译接口对待翻译源语言字符串进行翻译。
[0135] 具体的,当翻译结果携带翻译失败的标记信息时,触发补偿翻译机制,以再次调用翻译接口对待翻译源语言字符串进行翻译,直至返回的翻译结果表征翻译成功,或直至补偿翻译次数大于最大翻译次数(例如,最大翻译次数为5次)。
[0136] 可选的,可将每轮翻译失败的待翻译源语言字符串进行汇总,得到待补偿翻译列表。按照预设规则清除该字符串的失效缓存,并在预设时长(例如,3秒)后,重新调用翻译接口执行翻译,直至翻译成功或达到最大翻译次数。若最终的翻译结果仍表征翻译失败,则保留翻译失败的标记信息,并等待人工介入处理。
[0137] 需要说明的是,在完成全部翻译与更新操作后,执行文件清理与格式化操作。具体实现时,删除翻译过程中生成的备份文件、翻译缓存文件,对源语言文件和目标语言文件进行统一格式化规整,并合并文件中的重复模块,保证多语言文件格式统一且结构规范,以此完成多语言文件的标准化构建与更新。
[0138] 本实施例提供的方法,通过优先查询本地翻译缓存,避免相同源语言字符串的重复翻译,从而减少翻译接口调用次数。并且,在缓存未命中时调用预配置的翻译接口,并针对翻译失败的情况引入重试机制,同时支持将失败项汇总后延时补偿翻译,直至成功或保留标记供人工介入。这样,有效提升翻译过程的效率与成功率,从而确保目标语言文件生成的完整性和稳定性。
[0139] 下面通过优选实施例对本实施例进行描述和说明。
[0140] 图9为本申请提供的多语言适配方法实施例九的流程图,如图9所示,该多语言适配方法包括如下步骤:
[0141] 步骤S901,从源代码文件集合中筛选满足指定条件的多个指定源代码文件,并针对每个指定源代码文件,根据指定源代码文件的文件类别对应的提取规则从指定源代码文件中提取目标源代码,生成目标源代码对应的抽象语法树。
[0142] 步骤S902,针对每个抽象语法树,识别抽象语法树中的多个初始字符串节点;对多个初始字符串节点进行过滤,得到多个目标字符串节点,并从多个目标字符串节点中提取多个源语言字符串;其中,多个目标字符串节点包括字符串字面量节点和模板字面量节点。
[0143] 步骤S903,针对每个源语言字符串,对源语言字符串进行哈希运算,得到源语言字符串对应的原始哈希值;根据预设的截取策略从原始哈希值中截取部分哈希值;其中,截取策略用于指示从原始哈希值中的预设起始位置开始截取预设位数的值作为部分哈希值;根据预设前缀以及部分哈希值,生成源语言字符串对应的标识。
[0144] 步骤S904,以每个源语言字符串对应的标识为键名、每个源语言字符串为键值,构建第一键值对,并根据第一键值对更新源语言对应的当前源语言文件,得到更新源语言文件。
[0145] 步骤S905,获取多个指定源代码文件中的所有国际化代码,并提取各个国际化代码中的键名,得到第一键名集合;提取当前目标语言文件中的所有键名,得到第二键名集合;确定第一键名集合与第二键名集合的第一差集;从更新源语言文件中查找第一差集中的各个第一键名对应的源语言字符串,并将查找到的源语言字符串确定为多个待翻译源语言字符串。
[0146] 步骤S906,将每个待翻译源语言字符串翻译为目标语言对应的目标语言字符串;根据每个目标语言字符串、以及每个目标语言字符串对应的待翻译源语言字符串对应的键名,更新目标语言对应的当前目标语言文件,得到更新目标语言文件。
[0147] 步骤S907,针对每个源语言字符串,根据源语言字符串对应的抽象语言树,确定源语言字符串在抽象语法树对应的目标指定源代码文件中的位置信息,得到源语言字符串的位置信息。
[0148] 步骤S908,根据源语言字符串的位置信息,从目标指定源代码文件中查找源语言字符串的上下文代码,并根据目标指定源代码文件的文件类别、以及上下文代码,确定源语言字符串对应的实际嵌入场景。
[0149] 步骤S909,从预设的国际化函数调用格式与嵌入场景的对应关系中查找实际嵌入场景对应的目标国际化函数调用格式;根据目标国际化函数调用格式,将源语言字符串对应的标识转换为初始国际化代码,并将初始国际化代码确定为源语言字符串对应的国际化代码;将源代码文件中的每个源语言字符串替换为对应的国际化代码,得到更新源代码文件。
[0150] 需要说明的是,在上述流程中或者附图的流程图中示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行,并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。
[0151] 在本实施例中还提供了一种多语言适配装置,该装置用于实现上述实施例及优选实施方式,已经进行过说明的不再赘述。以下所使用的术语"模块”、"单元”、"子单元”等可以实现预定功能的软件和 / 或硬件的组合。尽管在以下实施例中所描述的装置较佳地以软件来实现,但是硬件,或者软件和硬件的组合的实现也是可能并被构想的。
[0152] 图10是本实施例的多语言适配装置的结构框图,如图10所示,该多语言适配装置包括:
[0153] 生成模块10,用于从源代码文件集合中获取源语言对应的多个源语言字符串,并生成每个源语言字符串对应的标识;
[0154] 第一更新模块20,用于以每个源语言字符串对应的标识为键名、每个源语言字符串为键值,构建第一键值对,并根据第一键值对更新源语言对应的当前源语言文件,得到更新源语言文件;
[0155] 翻译模块30,用于根据更新源语言文件确定多个待翻译源语言字符串,并将每个待翻译源语言字符串翻译为目标语言对应的目标语言字符串;
[0156] 第二更新模块40,用于根据每个目标语言字符串、以及每个目标语言字符串对应的待翻译源语言字符串对应的键名,更新目标语言对应的当前目标语言文件,得到更新目标语言文件;
[0157] 第三更新模块50,用于确定每个源语言字符串对应的国际化代码,并将源代码文件中的每个源语言字符串替换为每个源语言字符串对应的国际化代码,得到更新源代码文件;其中,国际化代码用于指示更新源代码文件基于更新源语言文件和更新目标语言文件进行多语言切换。
[0158] 可选的,在一种可能的实现方式中,生成模块10,具体用于:
[0159] 从源代码文件集合中筛选满足指定条件的多个指定源代码文件;
[0160] 针对每个指定源代码文件,根据指定源代码文件的文件类别对应的提取规则从指定源代码文件中提取目标源代码,并生成目标源代码对应的抽象语法树;
[0161] 针对每个抽象语法树,识别抽象语法树中的多个初始字符串节点;
[0162] 对多个初始字符串节点进行过滤,得到多个目标字符串节点,并从多个目标字符串节点中提取多个源语言字符串;其中,多个目标字符串节点包括字符串字面量节点和模板字面量节点。
[0163] 可选的,在一种可能的实现方式中,第三更新模块50,具体用于:
[0164] 针对每个源语言字符串,根据源语言字符串对应的抽象语言树,确定源语言字符串在抽象语法树对应的目标指定源代码文件中的位置信息,得到源语言字符串的位置信息;
[0165] 根据源语言字符串的位置信息,从目标指定源代码文件中查找源语言字符串的上下文代码,并根据目标指定源代码文件的文件类别、以及上下文代码,确定源语言字符串对应的实际嵌入场景;
[0166] 从预设的国际化函数调用格式与嵌入场景的对应关系中查找实际嵌入场景对应的目标国际化函数调用格式;
[0167] 根据目标国际化函数调用格式,将源语言字符串对应的标识转换为初始国际化代码,并将初始国际化代码确定为源语言字符串对应的国际化代码。
[0168] 可选的,在一种可能的实现方式中,翻译模块30,具体用于:
[0169] 获取多个指定源代码文件中的所有国际化代码,并提取各个国际化代码中的键名,得到第一键名集合;
[0170] 提取当前目标语言文件中的所有键名,得到第二键名集合;
[0171] 确定第一键名集合与第二键名集合的第一差集;
[0172] 从更新源语言文件中查找第一差集中的各个第一键名对应的源语言字符串,并将查找到的源语言字符串确定为多个待翻译源语言字符串。
[0173] 可选的,在一种可能的实现方式中,生成模块10,具体用于:
[0174] 按照第一过滤条件对多个初始字符串节点进行过滤,得到多个备选字符串节点;
[0175] 针对每个备选字符串节点,在抽象语法树中查找备选字符串节点的父节点,并在父节点满足第二过滤条件时,将备选字符串节点确定为无效节点;其中,第二过滤条件包括:父节点为函数调用节点、且父节点对应的调用函数为国际化函数或父节点对应的调用对象为控制台对象;
[0176] 将多个备选字符串节点中的无效节点剔除,得到多个目标字符串节点。
[0177] 可选的,在一种可能的实现方式中,生成模块10,具体用于:
[0178] 针对每个源语言字符串,对源语言字符串进行哈希运算,得到源语言字符串对应的原始哈希值;
[0179] 根据预设的截取策略从原始哈希值中截取部分哈希值;其中,截取策略用于指示从原始哈希值中的预设起始位置开始截取预设位数的值作为部分哈希值;
[0180] 根据预设前缀、以及部分哈希值,生成源语言字符串对应的标识。
[0181] 可选的,在一种可能的实现方式中,第一更新模块20,具体用于:
[0182] 提取当前源语言文件中的所有键名,得到第三键名集合;
[0183] 提取第一键值对中的所有键名,得到第四键名集合;
[0184] 确定第三键名集合与第四键名集合的第二差集;
[0185] 根据第二差集中的每个第二键名所属的类别,确定每个第二键名对应的分组,并将每个第二键名、以及每个第二键名对应的源语言字符串关联写入每个第二键名对应的分组中,得到更新源语言文件。
[0186] 可选的,在一种可能的实现方式中,翻译模块30,具体用于:
[0187] 针对每个待翻译源语言字符串,在检测到本地翻译缓存中存在待翻译源语言字符串对应的目标键名时,从本地翻译缓存中提取目标键名对应的目标语言字符串;
[0188] 在检测到本地翻译缓存中不存在待翻译源语言字符串对应的键名时,调用预配置的翻译接口对待翻译源语言字符串进行翻译,得到翻译结果;其中,翻译结果用于表征待翻译源语言字符串是否翻译成功、以及在翻译成功时,翻译结果包括待翻译源语言字符串对应的目标语言字符串;
[0189] 在翻译结果表征翻译成功时,从翻译结果中提取待翻译源语言字符串对应的目标语言字符串;
[0190] 在翻译结果表征翻译失败时,再次调用翻译接口对待翻译源语言字符串进行翻译。
[0191] 需要说明的是,上述各个模块可以是功能模块也可以是程序模块,既可以通过软件来实现,也可以通过硬件来实现。对于通过硬件来实现的模块而言,上述各个模块可以位于同一处理器中;或者上述各个模块还可以按照任意组合的形式分别位于不同的处理器中。
[0192] 在本实施例中还提供了一种计算机设备,包括存储器和处理器,该存储器中存储有计算机程序,该处理器被设置为运行计算机程序以执行上述任一项方法实施例中的步骤。
[0193] 可选地,上述计算机设备还可以包括传输设备以及输入输出设备,其中,该传输设备和上述处理器连接,该输入输出设备和上述处理器连接。
[0194] 需要说明的是,在本实施例中的具体示例可以参考上述实施例及可选实施方式中所描述的示例,在本实施例中不再赘述。
[0195] 此外,结合上述实施例中提供的多语言适配方法,在本实施例中还可以提供一种存储介质来实现。该存储介质上存储有计算机程序;该计算机程序被处理器执行时实现上述实施例中的任意一种多语言适配方法。
[0196] 应该明白的是,这里描述的具体实施例只是用来解释这个应用,而不是用来对它进行限定。根据本申请提供的实施例,本领域普通技术人员在不进行创造性劳动的情况下得到的所有其它实施例,均属本申请保护范围。
[0197] 显然,附图只是本申请的一些例子或实施例,对本领域的普通技术人员来说,也可以根据这些附图将本申请适用于其他类似情况,但无需付出创造性劳动。另外,可以理解的是,尽管在此开发过程中所做的工作可能是复杂和漫长的,但是,对于本领域的普通技术人员来说,根据本申请披露的技术内容进行的某些设计、制造或生产等更改仅是常规的技术手段,不应被视为本申请公开的内容不足。
[0198] "实施例”一词在本申请中指的是结合实施例描述的具体特征、结构或特性可以包括在本申请的至少一个实施例中。该短语出现在说明书中的各个位置并不一定意味着相同的实施例,也不意味着与其它实施例相互排斥而具有独立性或可供选择。本领域的普通技术人员能够清楚或隐含地理解的是,本申请中描述的实施例在没有冲突的情况下,可以与其它实施例结合。
[0199] 以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对专利保护范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请的保护范围应以所附权利要求为准。< / script>
Claims
1. A multilingual adaptation method, characterized in that, The multilingual adaptation method includes: Extract multiple source language strings corresponding to the source language from the source code file collection, and generate an identifier for each source language string; Using the identifier corresponding to each source language string as the key name and each source language string as the key value, construct a first key-value pair, and update the current source language file corresponding to the source language according to the first key-value pair to obtain the updated source language file; Based on the updated source language file, multiple source language strings to be translated are determined, and each source language string to be translated is translated into the target language string corresponding to the target language. Based on each target language string and the key name corresponding to the source language string to be translated for each target language string, update the current target language file corresponding to the target language to obtain the updated target language file; The internationalization code corresponding to each source language string is determined, and each source language string in the source code file is replaced with the internationalization code corresponding to each source language string to obtain an updated source code file; wherein, the internationalization code is used to instruct the updated source code file to perform multilingual switching based on the updated source language file and the updated target language file.
2. The multilingual adaptation method according to claim 1, characterized in that, The step of obtaining multiple source language strings corresponding to the source language from the source code file collection includes: Filter a collection of source code files to select multiple specified source code files that meet specified criteria; For each specified source code file, the target source code is extracted from the specified source code file according to the extraction rules corresponding to the file category of the specified source code file, and an abstract syntax tree corresponding to the target source code is generated; For each abstract syntax tree, identify multiple initial string nodes in the abstract syntax tree; The multiple initial string nodes are filtered to obtain multiple target string nodes, and the multiple source language strings are extracted from the multiple target string nodes; wherein, the multiple target string nodes include string literal nodes and template literal nodes.
3. The multilingual adaptation method according to claim 2, characterized in that, Determining the internationalization code corresponding to each source language string includes: For each source language string, the position information of the source language string in the target specified source code file corresponding to the abstract language tree is determined according to the abstract language tree corresponding to the source language string, and the position information of the source language string is obtained. Based on the location information of the source language string, the context code of the source language string is found in the target specified source code file, and the actual embedding scenario corresponding to the source language string is determined according to the file category of the target specified source code file and the context code; Find the target internationalized function call format corresponding to the actual embedded scenario from the preset correspondence between internationalized function call formats and embedded scenarios; Based on the target internationalized function call format, the identifier corresponding to the source language string is converted into initial internationalization code, and the initial internationalization code is determined as the internationalization code corresponding to the source language string.
4. The multilingual adaptation method according to claim 2, characterized in that, The step of determining multiple source language strings to be translated based on the updated source language file includes: Obtain all internationalized code from the specified source code files, and extract the key names from each internationalized code to obtain a first key name set; Extract all key names from the current target language file to obtain a second key name set; Determine the first difference between the first set of key names and the second set of key names; The source language strings corresponding to each first key name in the first difference set are searched in the updated source language file, and the searched source language strings are determined as the plurality of source language strings to be translated.
5. The multilingual adaptation method according to claim 2, characterized in that, The filtering of the multiple initial string nodes to obtain multiple target string nodes includes: The multiple initial string nodes are filtered according to the first filtering condition to obtain multiple candidate string nodes; For each candidate string node, the parent node of the candidate string node is searched in the abstract syntax tree, and the candidate string node is determined to be an invalid node when the parent node meets the second filtering condition; wherein, the second filtering condition includes: the parent node is a function call node, and the calling function corresponding to the parent node is an internationalized function or the calling object corresponding to the parent node is a console object; Invalid nodes are removed from the plurality of candidate string nodes to obtain the plurality of target string nodes.
6. The multilingual adaptation method according to claim 1, characterized in that, The generation of the identifier corresponding to each source language string includes: For each source language string, perform a hash operation on the source language string to obtain the original hash value corresponding to the source language string; A portion of the hash value is extracted from the original hash value according to a preset truncation strategy; wherein, the truncation strategy is used to indicate that a value of a preset number of bits is extracted from the original hash value starting from a preset start position as the portion of the hash value; Based on the preset prefix and the partial hash value, an identifier corresponding to the source language string is generated.
7. The multilingual adaptation method according to claim 1, characterized in that, The current source language file includes multiple groups, with different groups corresponding to different categories of key names; updating the current source language file corresponding to the source language based on the first key-value pair to obtain the updated source language file includes: Extract all key names from the current source language file to obtain a third key name set; Extract all key names from the first key-value pair to obtain the fourth key name set; Determine the second difference between the third set of key names and the fourth set of key names; Based on the category to which each second key name belongs in the second difference set, determine the group corresponding to each second key name, and associate each second key name and the source language string corresponding to each second key name into the group corresponding to each second key name to obtain the updated source language file.
8. The multilingual adaptation method according to claim 1, characterized in that, The process of translating each source language string into the target language string includes: For each source language string to be translated, when the target key name corresponding to the source language string to be translated is detected in the local translation cache, the target language string corresponding to the target key name is extracted from the local translation cache; When it is detected that the key name corresponding to the source language string to be translated does not exist in the local translation cache, the pre-configured translation interface is called to translate the source language string to be translated and a translation result is obtained; wherein, the translation result is used to indicate whether the source language string to be translated is translated successfully, and when the translation is successful, the translation result includes the target language string corresponding to the source language string to be translated; When the translation result indicates that the translation is successful, the target language string corresponding to the source language string to be translated is extracted from the translation result; When the translation result indicates that the translation has failed, the translation interface is called again to translate the source language string to be translated.
9. A multilingual adaptation device, characterized in that, The multilingual adaptation device includes: The generation module is used to obtain multiple source language strings corresponding to the source language from the source code file collection and generate an identifier for each source language string; The first update module is used to construct a first key-value pair with the identifier corresponding to each source language string as the key name and each source language string as the key value, and update the current source language file corresponding to the source language according to the first key-value pair to obtain the updated source language file; The translation module is used to determine multiple source language strings to be translated based on the updated source language file, and translate each source language string to be translated into the target language string corresponding to the target language. The second update module is used to update the current target language file corresponding to the target language according to each target language string and the key name corresponding to the source language string to be translated for each target language string, so as to obtain the updated target language file; The third update module is used to determine the internationalization code corresponding to each source language string, and replace each source language string in the source code file with the internationalization code corresponding to each source language string to obtain an updated source code file; wherein, the internationalization code is used to instruct the updated source code file to perform multilingual switching based on the updated source language file and the updated target language file.
10. A computer device, comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the steps of the multilingual adaptation method according to any one of claims 1 to 8.