Movatterモバイル変換


[0]ホーム

URL:


CN117234507A - Code processing method, device, equipment and readable storage medium - Google Patents

Code processing method, device, equipment and readable storage medium
Download PDF

Info

Publication number
CN117234507A
CN117234507ACN202311182822.1ACN202311182822ACN117234507ACN 117234507 ACN117234507 ACN 117234507ACN 202311182822 ACN202311182822 ACN 202311182822ACN 117234507 ACN117234507 ACN 117234507A
Authority
CN
China
Prior art keywords
character
code
syntax tree
identifier
abstract syntax
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311182822.1A
Other languages
Chinese (zh)
Inventor
刘彬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Geely Holding Group Co Ltd
Zhejiang Zeekr Intelligent Technology Co Ltd
Original Assignee
Zhejiang Geely Holding Group Co Ltd
Zhejiang Zeekr Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Geely Holding Group Co Ltd, Zhejiang Zeekr Intelligent Technology Co LtdfiledCriticalZhejiang Geely Holding Group Co Ltd
Priority to CN202311182822.1ApriorityCriticalpatent/CN117234507A/en
Publication of CN117234507ApublicationCriticalpatent/CN117234507A/en
Pendinglegal-statusCriticalCurrent

Links

Landscapes

Abstract

Translated fromChinese

本申请提供一种代码处理方法、装置、设备及可读存储介质,通过将遍历待处理代码文件的抽象语法树的各个节点,将节点中所包括的第一语言类型的字符替换为语言切换调用指令,满足代码中的各种类型的字符替换需求,并基于修改后的抽象语法树生成包含语言切换调用指令的代码文件,从而实现了根据用户选定语言动态切换页面的语言,提高了处理效率。

This application provides a code processing method, device, equipment and readable storage medium. By traversing each node of the abstract syntax tree of the code file to be processed, the characters of the first language type included in the node are replaced with language switching calls. instructions to meet various types of character replacement needs in the code, and generate code files containing language switching call instructions based on the modified abstract syntax tree, thereby realizing dynamic switching of the language of the page according to the user-selected language, improving processing efficiency .

Description

Translated fromChinese
代码处理方法、装置、设备及可读存储介质Code processing methods, devices, equipment and readable storage media

技术领域Technical field

本申请涉及计算机技术领域,尤其涉及一种代码处理方法、装置、设备及可读存储介质。The present application relates to the field of computer technology, and in particular, to a code processing method, device, equipment and readable storage medium.

背景技术Background technique

国际化配置是指对一种产品或服务进行改造使之易适应不同区域要求的过程,要求从产品中抽离所有地域语言,国家/地区和文化相关的元素。现有的较多网站或者移动应用都需要实现国际化,支持以多种不同的语言进行展示用户界面(例如英语、中文、法语等)。International configuration refers to the process of transforming a product or service to easily adapt to different regional requirements, requiring the extraction of all regional language, country/region and culture-related elements from the product. Many existing websites or mobile applications need to be internationalized and support user interface display in multiple different languages (such as English, Chinese, French, etc.).

传统的国际化实现方式是增加内容完全相同、仅展示语言不同的页面,根据用户的需要而切换至相应语言的页面。然而该方式随着支持的语言种类的增加、以及需设置的页面数量的增加,容易导致代码冗余以及维护工作量增大,增加开发成本。The traditional way to implement internationalization is to add pages with the same content but only display different languages, and switch to the page in the corresponding language according to the user's needs. However, as the types of languages supported and the number of pages that need to be set increase, this method can easily lead to code redundancy, increase maintenance workload, and increase development costs.

相关技术中的另一种国际化实现方式是遍历应用程序的全部源代码文件,通过正则表达式匹配源代码文件中的字符串,将源代码中所匹配到的字符串修改为用户指定的语言类型的字符串,从而实现显示界面的语言切换。该方式虽然缓解了代码冗余,但是正则匹配的匹配场景有限、效率较低,对于复杂的源代码文件无法覆盖各种情况下的字符串替换,影响用户体验。Another way to implement internationalization in related technologies is to traverse all source code files of the application, match strings in the source code files through regular expressions, and modify the matched strings in the source code to the language specified by the user. Type of string to achieve language switching of the display interface. Although this method alleviates code redundancy, regular matching has limited matching scenarios and low efficiency. It cannot cover string replacement in various situations for complex source code files, affecting the user experience.

发明内容Contents of the invention

有鉴于此,为解决上述技术问题,本申请提供一种代码处理方法、装置、设备及可读存储介质。In view of this, in order to solve the above technical problems, this application provides a code processing method, device, equipment and readable storage medium.

具体地,本申请是通过如下技术方案实现的:Specifically, this application is implemented through the following technical solutions:

根据本申请实施例的第一方面,提供一种代码处理方法,所述方法包括:According to a first aspect of the embodiment of the present application, a code processing method is provided, the method includes:

获取待处理代码的第一抽象语法树;其中,所述待处理代码中包括第一字符,所述第一字符为第一语言类型的字符;Obtain the first abstract syntax tree of the code to be processed; wherein the code to be processed includes a first character, and the first character is a character of the first language type;

遍历所述第一抽象语法树的节点,从所述第一抽象语法树的节点中确定出内容包含所述第一字符的目标节点;Traverse the nodes of the first abstract syntax tree, and determine the target node whose content contains the first character from the nodes of the first abstract syntax tree;

将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,以生成第二抽象语法树;所述调用指令至少包括所述第一字符的标识符;Replace the first character in the target node with a calling instruction of the language switching program to generate a second abstract syntax tree; the calling instruction at least includes an identifier of the first character;

根据所述第二抽象语法树,生成与所述待处理代码对应的目标代码,所述目标代码用于在运行过程中将所述第一字符由第一语言类型切换为目标语言类型。According to the second abstract syntax tree, a target code corresponding to the code to be processed is generated, and the target code is used to switch the first character from the first language type to the target language type during operation.

可选地,所述待处理代码包括vue代码;所述第一抽象语法树包括vue模板抽象语法树和脚本抽象语法树;Optionally, the code to be processed includes vue code; the first abstract syntax tree includes a vue template abstract syntax tree and a script abstract syntax tree;

所述获取待处理代码的第一抽象语法树,包括:Obtaining the first abstract syntax tree of the code to be processed includes:

获取所述vue代码中的模板代码和脚本代码;Get the template code and script code in the vue code;

分别获取所述模板代码对应的vue模板抽象语法树、以及所述脚本代码对应的脚本抽象语法树。Obtain respectively the vue template abstract syntax tree corresponding to the template code and the script abstract syntax tree corresponding to the script code.

可选地,所述将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,包括:Optionally, replacing the first character in the target node with a calling instruction of the language switching program includes:

获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;

根据预设的标识符生成方法,确定所述第一字符的标识符;Determine the identifier of the first character according to a preset identifier generation method;

响应于第一文件中不包括所述第一字符的标识符,将第一字符的标识符以及所述第一字符写入所述第一文件;其中,所述第一文件用于存储字符的标识符以及在第一语言类型下的第二字符;In response to the first file not including the identifier of the first character, writing the identifier of the first character and the first character into the first file; wherein the first file is used to store the character The identifier and the second character in the first language type;

根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.

可选地,所述将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,包括:Optionally, replacing the first character in the target node with a calling instruction of the language switching program includes:

获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;

响应于检测到第二文件中包括所述第一字符,根据所述第二文件获取所述第一字符的标识符;所述第二文件包括预存储字符的标识符以及在第一语言类型下的第三字符;In response to detecting that the first character is included in the second file, obtaining an identifier of the first character according to the second file; the second file includes an identifier of a pre-stored character and in the first language type the third character;

根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.

可选地,响应于匹配到的所述第一字符包括包含变量的字符串,则所述语言切换程序的调用指令还包括所述变量的名称与变量取值。Optionally, in response to the matched first character including a string containing a variable, the calling instruction of the language switching program further includes the name of the variable and the variable value.

根据本申请实施例的第二方面,提供一种代码处理装置,所述装置包括:According to a second aspect of the embodiment of the present application, a code processing device is provided, and the device includes:

第一语法树获取模块,用于获取待处理代码的第一抽象语法树;其中,所述待处理代码中包括第一字符,所述第一字符为第一语言类型的字符;The first syntax tree acquisition module is used to acquire the first abstract syntax tree of the code to be processed; wherein the code to be processed includes a first character, and the first character is a character of the first language type;

目标节点确定模块,用于遍历所述第一抽象语法树的节点,从所述第一抽象语法树的节点中确定出内容包含所述第一字符的目标节点;A target node determination module, configured to traverse the nodes of the first abstract syntax tree and determine the target node whose content contains the first character from the nodes of the first abstract syntax tree;

第二语法树获取模块,用于将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,以生成第二抽象语法树;所述调用指令至少包括所述第一字符的标识符;A second syntax tree acquisition module is used to replace the first character in the target node with a calling instruction of the language switching program to generate a second abstract syntax tree; the calling instruction at least includes the first character identifier;

目标代码生成模块,用于根据所述第二抽象语法树,生成与所述待处理代码对应的目标代码,所述目标代码用于在运行过程中将所述第一字符由第一语言类型切换为目标语言类型。A target code generation module, configured to generate target code corresponding to the code to be processed according to the second abstract syntax tree, the target code being used to switch the first character from the first language type during operation is the target language type.

可选地,所述待处理代码包括vue代码;所述第一抽象语法树包括vue模板抽象语法树和脚本抽象语法树;所述第一语法树获取模块具体用于:Optionally, the code to be processed includes vue code; the first abstract syntax tree includes a vue template abstract syntax tree and a script abstract syntax tree; the first syntax tree acquisition module is specifically used to:

获取所述vue代码中的模板代码和脚本代码;Get the template code and script code in the vue code;

分别获取所述模板代码对应的vue模板抽象语法树、以及所述脚本代码对应的脚本抽象语法树。Obtain respectively the vue template abstract syntax tree corresponding to the template code and the script abstract syntax tree corresponding to the script code.

可选地,所述第二抽象语法树获取模块具体用于:Optionally, the second abstract syntax tree acquisition module is specifically used to:

获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;

根据预设的标识符生成方法,确定所述第一字符的标识符;Determine the identifier of the first character according to a preset identifier generation method;

响应于第一文件中不包括所述第一字符的标识符,将第一字符的标识符以及所述第一字符写入所述第一文件;其中,所述第一文件用于存储字符的标识符以及在第一语言类型下的第二字符;In response to the first file not including the identifier of the first character, writing the identifier of the first character and the first character into the first file; wherein the first file is used to store the character The identifier and the second character in the first language type;

根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.

可选地,所述第二抽象语法树获取模块具体用于:Optionally, the second abstract syntax tree acquisition module is specifically used to:

获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;

响应于检测到第二文件中包括所述第一字符,根据所述第二文件获取所述第一字符的标识符;所述第二文件包括预存储字符的标识符以及在第一语言类型下的第三字符;In response to detecting that the first character is included in the second file, obtaining an identifier of the first character according to the second file; the second file includes an identifier of a pre-stored character and in the first language type the third character;

根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.

可选地,响应于匹配到的所述第一字符包括包含变量的字符串,则所述语言切换程序的调用指令还包括所述变量的名称与变量取值。Optionally, in response to the matched first character including a string containing a variable, the calling instruction of the language switching program further includes the name of the variable and the variable value.

根据本申请实施例的第三方面,提供一种电子设备,所述电子设备包括:存储器和处理器;所述存储器,用于存储计算机程序;所述处理器,用于通过调用所述计算机程序,执行上述代码处理方法。According to a third aspect of the embodiment of the present application, an electronic device is provided. The electronic device includes: a memory and a processor; the memory is used to store a computer program; the processor is used to call the computer program by , execute the above code processing method.

根据本申请实施例的第四方面,提供一种计算机可读存储介质,其上存储有计算机程序,所述程序被处理器执行时实现上述代码处理方法。According to a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the above code processing method is implemented.

本申请实施例提供的技术方案可以包括以下有益效果:The technical solutions provided by the embodiments of this application may include the following beneficial effects:

在本申请提供的技术方案中,通过将遍历待处理代码文件的抽象语法树的各个节点,将节点中所包括的第一语言类型的字符替换为语言切换调用指令,满足代码中的各种类型的字符替换需求,并基于修改后的抽象语法树生成包含语言切换调用指令的代码文件,从而实现了根据用户选定语言动态切换页面的语言,提高了处理效率。In the technical solution provided by this application, by traversing each node of the abstract syntax tree of the code file to be processed, and replacing the characters of the first language type included in the node with a language switching call instruction, various types of code in the code can be satisfied. The character replacement requirements are met, and a code file containing language switching call instructions is generated based on the modified abstract syntax tree, thereby realizing dynamic switching of the language of the page according to the language selected by the user, and improving processing efficiency.

应当理解的是,以上的一般描述和后文的细节描述仅是示例性的和解释性的,并不能限制本申请。此外,本申请中的任一实施例并不需要达到上述的全部效果。It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and do not limit the application. In addition, any embodiment in the present application does not need to achieve all the above effects.

附图说明Description of drawings

此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本申请的实施例,并与说明书一起用于解释本申请的原理。The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.

图1是本申请一示例性实施例示出的一种代码处理方法流程示意图;Figure 1 is a schematic flowchart of a code processing method according to an exemplary embodiment of the present application;

图2是本申请一示例性实施例示出的另一种代码处理方法流程示意图;Figure 2 is a schematic flowchart of another code processing method according to an exemplary embodiment of the present application;

图3是本申请一示例性实施例示出的一种代码处理装置的结构示意图;Figure 3 is a schematic structural diagram of a code processing device according to an exemplary embodiment of the present application;

图4是本申请一示例性实施例示出的一种电子设备的硬件示意图。FIG. 4 is a hardware schematic diagram of an electronic device according to an exemplary embodiment of the present application.

具体实施方式Detailed ways

这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本申请相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本申请的一些方面相一致的装置和方法的例子。Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this application. Rather, they are merely examples of apparatus and methods consistent with aspects of the application as detailed in the appended claims.

在本申请使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本申请。在本申请和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the appended claims, the singular forms "a," "the" and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It will also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

应当理解,尽管在本申请可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本申请范围的情况下,第一分类阈值也可以被称为第二分类阈值,类似地,第二分类阈值也可以被称为第一分类阈值。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。It should be understood that although the terms first, second, third, etc. may be used in this application to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of the present application, the first classification threshold may also be called a second classification threshold, and similarly, the second classification threshold may also be called a first classification threshold. Depending on the context, the word "if" as used herein may be interpreted as "when" or "when" or "in response to determining."

目前,为使产品适应不同地区用户的使用需求,产品国际化开发已经成为常见的一种设计方式,以提供多语言支持的产品。At present, in order to adapt products to the needs of users in different regions, product international development has become a common design method to provide products with multi-language support.

相关技术中的国际化开发主要包括增加各种语言的产品界面配置或正则匹配替换字符的方式实现。具体地,一种是在产品开发时通过增加内容完全相同、仅展示语言不同的页面,比如说,支持的语言包括中文、英文以及俄语,则对于产品每个显示页面分别配置中文、英文以及俄语这三种语言版本的代码文件,从而在获取到用户指定的目标语言时,切换显示相应语言的界面。International development in related technologies mainly includes adding product interface configurations in various languages or implementing regular matching and replacement characters. Specifically, one is to add pages with exactly the same content but different display languages during product development. For example, if the supported languages include Chinese, English and Russian, then each display page of the product will be configured in Chinese, English and Russian respectively. Code files in these three languages, so that when the target language specified by the user is obtained, the interface in the corresponding language can be switched to display.

此种增加各种语言的界面的方式对于支持的语言较少、产品的显示页面较少的情况可以快速解决问题,但是,随着支持的语言种类的增加、以及需设置的页面数量的增加,实现不同语种的显示界面所增加的代码较多,且由于同一页面的不同语种代码仅展示语言不同,容易造成代码冗余并对日常代码维护工作带来困难,增加开发成本,影响程序运行效率。This method of adding interfaces in various languages can quickly solve the problem when there are fewer supported languages and fewer product display pages. However, as the number of supported languages increases and the number of pages that need to be set increases, Implementing display interfaces in different languages requires a lot of code, and since different language codes on the same page only display different languages, it is easy to cause code redundancy and bring difficulties to daily code maintenance, increase development costs, and affect program operation efficiency.

另一种国际化实现方式是遍历产品的全部源代码文件,利用预先设置的正则表达式分别对各个源代码文件中的源代码进行字符匹配,将匹配到字符串修改为用户指定的语言类型的字符串,从而实现显示界面的语言切换。比如说,开发者语言为中文,用户期望显示英文界面,则通过正则表达式匹配源代码中的中文字符,并将所述中文字符替换成对应的英文字符,运行替换后的源代码的显示界面即为英文界面。Another way to implement internationalization is to traverse all the source code files of the product, use preset regular expressions to perform character matching on the source code in each source code file, and modify the matched string to the language type specified by the user. String to achieve language switching of the display interface. For example, if the developer's language is Chinese and the user expects to display an English interface, then the Chinese characters in the source code are matched through regular expressions, the Chinese characters are replaced with the corresponding English characters, and the display interface of the replaced source code is run. That is the English interface.

但是,由于产品源代码的设计复杂以及语法多样性,正则表达式的配置繁琐且在源代码中匹配字符的可匹配场景有限,如匹配包含变量的字符串、vue语法编写代码、函数调用返回值等无法进行字符匹配及替换,导致语言切换后的界面存在字符替换不完全的问题,带来不好的用户体验。However, due to the complex design and grammatical diversity of the product source code, the configuration of regular expressions is cumbersome and the matching scenarios for matching characters in the source code are limited, such as matching strings containing variables, writing code in Vue syntax, and function call return values. Character matching and replacement cannot be performed, resulting in incomplete character replacement in the interface after language switching, resulting in a bad user experience.

有鉴于此,为解决上述技术问题,本申请提供了一种代码处理方法,该方法应用于产品前端页面开发的源代码处理,参见图1所示,所述方法可以包括以下步骤:In view of this, in order to solve the above technical problems, this application provides a code processing method, which is applied to source code processing for product front-end page development, as shown in Figure 1. The method may include the following steps:

S101,获取待处理代码的第一抽象语法树;其中,所述待处理代码中包括第一字符,所述第一字符为第一语言类型的字符;S101. Obtain the first abstract syntax tree of the code to be processed; wherein the code to be processed includes a first character, and the first character is a character of the first language type;

其中,所述第一语言类型是指开发者在开发产品的前端页面时所采用的页面显示语言种类,如编写产品的前端页面对应的源代码时使用中文实现页面显示,则所述第一语言类型为中文。Among them, the first language type refers to the page display language type used by developers when developing the front-end page of the product. For example, when writing the source code corresponding to the front-end page of the product, Chinese is used to implement page display, then the first language The type is Chinese.

产品国际化要求产品支持不同语言下的页面显示,基于页面显示是通过运行相应的代码文件实现的,则页面上所显示的第一语言类型的字符对应存在于产品的源代码文件中,因此,对于包含产品的各个页面所显示的字符的源代码文件,将该源代码文件中的代码作为待处理代码,该待处理代码可以包括但不限于vue代码、JavaScript代码。Product internationalization requires that the product support page display in different languages. Based on the fact that page display is achieved by running the corresponding code file, the characters of the first language type displayed on the page correspond to the source code file of the product. Therefore, For the source code file that contains the characters displayed on each page of the product, the code in the source code file is used as the code to be processed. The code to be processed can include but is not limited to Vue code and JavaScript code.

抽象语法树(abstract syntax tree,AST)是源代码的抽象语法结构的树状表示,树上的每个节点都表示源代码中的一种结构,其根节点和叶子节点所包括的节点内容对应于源代码,但是抽象语法树并不会表示出真实语法出现的每一个细节,比如说,嵌套括号被隐含在树的结构中,并没有以节点的形式呈现,又或者if-condition-then这种条件跳转语句可以使用带有三个分支的节点来表示。Abstract syntax tree (AST) is a tree representation of the abstract syntax structure of the source code. Each node on the tree represents a structure in the source code, and its root node corresponds to the node content included in the leaf node. in the source code, but the abstract syntax tree does not represent every detail of the real syntax. For example, nested brackets are implicit in the structure of the tree and are not presented in the form of nodes, or if-condition- Then this kind of conditional jump statement can be represented by a node with three branches.

该待处理代码的第一抽象语法树可以通过相关技术中的抽象语法树获取方式实现,通常利用词法分析和语法分析提取出源代码的结构,并以树状形式表示该结构。在本实施例实现过程中,可以设置语法树生成工具链,依据待处理代码的类型通过相应的生成工具对该待处理代码进行解析处理,从而得到与待处理代码文件对应的第一抽象语法树。The first abstract syntax tree of the code to be processed can be realized by obtaining an abstract syntax tree in related technologies. Usually, lexical analysis and syntax analysis are used to extract the structure of the source code, and the structure is represented in a tree form. During the implementation of this embodiment, a syntax tree generation tool chain can be set up, and the code to be processed is parsed through the corresponding generation tool according to the type of the code to be processed, thereby obtaining the first abstract syntax tree corresponding to the code file to be processed. .

示例性的,该待处理代码为vue代码,则可以通过用于解析vue代码的工具vue-eslint-parser分析该待处理代码文件,生成对应的抽象语法树。For example, if the code to be processed is Vue code, the code file to be processed can be analyzed by vue-eslint-parser, a tool for parsing Vue code, and the corresponding abstract syntax tree can be generated.

S102,遍历所述第一抽象语法树的节点,从所述第一抽象语法树的节点中确定出内容包含所述第一字符的目标节点;S102, traverse the nodes of the first abstract syntax tree, and determine the target node whose content contains the first character from the nodes of the first abstract syntax tree;

抽象语法树的节点包括根节点和叶子节点,可以按照深度或广度遍历该语法树的全部节点,对当前遍历到的节点可以根据节点的类型、属性、方法或字段等节点信息判断该节点是否包括文本内容,若该节点包含文本内容,则提取其文本内容并进一步判断是否包括第一语言类型的第一字符;若所述文本内容中包括第一字符,则确定当前遍历到的该节点为目标节点。The nodes of the abstract syntax tree include root nodes and leaf nodes. All nodes of the syntax tree can be traversed according to depth or breadth. For the currently traversed node, it can be judged whether the node includes node information such as type, attribute, method or field. Text content, if the node contains text content, extract its text content and further determine whether it includes the first character of the first language type; if the text content includes the first character, determine that the currently traversed node is the target node.

其中,对于获取到的节点所包括的文本内容,可以使用正则表达式或者同一码Unicode编码范围判断该文本内容是否包括第一语言类型的字符。例如,假设第一语言类型为中文,则对于包含文本内容的节点,判断该文本内容中是否包括中文字符。若使用正则表达式进行判断,先将获取的文本内容转换为字符串类型,根据汉字Unicode编码的范围[\u4e00-\u9fff]设置正则表达式,对转换得到的字符串进行中文字符匹配。Wherein, for the text content included in the obtained node, a regular expression or a Unicode encoding range of the same code can be used to determine whether the text content includes characters of the first language type. For example, assuming that the first language type is Chinese, for a node containing text content, determine whether the text content includes Chinese characters. If regular expressions are used for judgment, first convert the obtained text content into a string type, set the regular expression according to the Chinese character Unicode encoding range [\u4e00-\u9fff], and match Chinese characters on the converted string.

S103,将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,以生成第二抽象语法树;所述调用指令至少包括所述第一字符的标识符;S103. Replace the first character in the target node with the calling instruction of the language switching program to generate a second abstract syntax tree; the calling instruction at least includes the identifier of the first character;

所述第一字符的标识符用于唯一标识该第一字符,并且对于该第一字符在不同语言类型下的翻译文本,该翻译文本的标识符与所述第一字符的标识符相同,从而实现依据该唯一标识符可以获取到同一字符对应于各种语言类型下的文本。例如,对中文字符“注册”生成唯一标识符A,则“注册”一词对应的英文、俄语等其他语言类型下的翻译文本的唯一标识符也为A。The identifier of the first character is used to uniquely identify the first character, and for the translated text of the first character in different language types, the identifier of the translated text is the same as the identifier of the first character, so that The implementation can obtain text corresponding to the same character in various language types based on the unique identifier. For example, if the unique identifier A is generated for the Chinese character "registration", then the unique identifier of the translated text corresponding to the word "registration" in English, Russian and other language types is also A.

在本实施例中,该语言切换程序用于根据接收到的标识符,实现同一字符对应于不同语种下的文本之间的切换,从而实现多语言支持。所述调用指令用于调用该语言切换程序,并且调用指令中包括所述第一字符的标识符,以将该标识符传递给所述语言切换程序,从而实现该第一字符在不同语言下的文本之间的切换。In this embodiment, the language switching program is used to switch between texts corresponding to the same character in different languages according to the received identifier, thereby achieving multi-language support. The calling instruction is used to call the language switching program, and the calling instruction includes the identifier of the first character to pass the identifier to the language switching program, thereby realizing the switching of the first character in different languages. Switch between texts.

示例地,所述调用指令可以是$t()函数,其中t()函数即为所述语言切换程序。假设目标节点包括中文字符“注册”且其标识符为A,则包括标识符的调用指令为$t(A)。For example, the calling instruction may be the $t() function, where the t() function is the language switching program. Assume that the target node includes the Chinese character "registration" and its identifier is A, then the calling instruction including the identifier is $t(A).

上述将第一字符替换为调用指令是指对目标节点进行修改,修改后的目标节点不再包括第一字符而是包括该调用指令,其中该调用指令的位置与原第一字符的位置相对应。比如,目标节点中包括的第一字符为{{注册}},则替换为调用指令后的目标节点可以包括{{$t(A)}}。The above-mentioned replacement of the first character with the calling instruction refers to modifying the target node. The modified target node no longer includes the first character but includes the calling instruction, where the position of the calling instruction corresponds to the position of the original first character. . For example, if the first character included in the target node is {{Registration}}, then the target node after the calling instruction can be replaced with {{$t(A)}}.

将第一抽象语法树的全部目标节点中的第一字符均替换为对应的调用指令后,替换的抽象语法树即为第二抽象语法树。也即,第一抽象语法树和第二抽象语法树的区别在于:第一抽象语法树中所包括的全部第一字符对应于第二抽象语法树为相应调用指令,并且,对于两颗树中的同一节点,第二抽象语法树中节点包括的调用指令中的标识符唯一标识第一抽象语法树中的节点包括的第一字符。After the first characters in all target nodes of the first abstract syntax tree are replaced with corresponding calling instructions, the replaced abstract syntax tree is the second abstract syntax tree. That is, the difference between the first abstract syntax tree and the second abstract syntax tree is that all the first characters included in the first abstract syntax tree correspond to the corresponding calling instructions in the second abstract syntax tree, and, for the two trees, of the same node, the identifier in the calling instruction included in the node in the second abstract syntax tree uniquely identifies the first character included in the node in the first abstract syntax tree.

可以理解的是,步骤S102和步骤S103可以同步执行或者异步执行。其中,同步运行是指:在对于所述第一抽象语法树的节点进行遍历时,对当前节点获取其文本内容匹配到第一语言类型的第一字符时,确定该当前节点为目标节点,并对该目标节点中匹配到的第一字符将其替换为对应的调用指令,并在替换完成后遍历下一个节点。异步执行是指:在对于所述第一抽象语法树的节点进行遍历并确定当前节点为目标节点时,记录该目标节点的位置信息或添加目标节点的属性标记;在完成对第一抽象语法树的节点遍历后,依据所统计的目标节点,逐个目标节点进行遍历并实现对目标节点的修改,将其中的第一字符替换为调用指令。It can be understood that step S102 and step S103 can be executed synchronously or asynchronously. Wherein, synchronous operation means: when traversing the nodes of the first abstract syntax tree, when obtaining the text content of the current node that matches the first character of the first language type, determining the current node as the target node, and Replace the first matched character in the target node with the corresponding calling instruction, and traverse the next node after the replacement is completed. Asynchronous execution means: when traversing the nodes of the first abstract syntax tree and determining the current node as the target node, recording the location information of the target node or adding attribute tags of the target node; after completing the first abstract syntax tree After traversing the nodes, according to the counted target nodes, traverse the target nodes one by one and modify the target nodes, replacing the first character with the calling instruction.

S104,根据所述第二抽象语法树,生成与所述待处理代码对应的目标代码,所述目标代码用于在运行过程中将所述第一字符由第一语言类型切换为目标语言类型。S104. According to the second abstract syntax tree, generate a target code corresponding to the code to be processed. The target code is used to switch the first character from the first language type to the target language type during operation.

所述根据抽象语法树生成目标代码是指将语法树转换回源代码的过程,可以通过相关技术的手段实现。示例性的,可以采用基于Visual Studio Code的babel插件中的生成器(generator)获取抽象语法树对应的源代码。The generation of target code based on the abstract syntax tree refers to the process of converting the syntax tree back to the source code, which can be achieved by means of related technologies. For example, the generator in the babel plug-in based on Visual Studio Code can be used to obtain the source code corresponding to the abstract syntax tree.

根据所述第二抽象语法树生成的目标代码是包括语言切换程序的调用指令的代码,该目标代码与所述待处理代码一一对应,目标代码和待处理代码文件的主要区别在于:待处理代码中的第一语言类型的第一字符被替换成包含该第一字符的标识符的语言切换程序的调用指令。The target code generated according to the second abstract syntax tree is a code that includes the calling instruction of the language switching program. The target code corresponds one-to-one with the code to be processed. The main difference between the target code and the code file to be processed is: to be processed The first character of the first language type in the code is replaced by a call instruction of the language switching program containing the identifier of the first character.

在上述实施例中,开发者在编写产品页面的开发源代码时使用第一语言类型的字符实现页面显示,本申请获取与该产品页面显示相关的待处理代码,并生成该待处理代码对应的第一抽象语法树,通过遍历第一抽象语法树的节点,将各个节点所包括的第一语言类型的字符替换为对应的调用指令,并根据替换后的第二抽象语法树转换回与待处理代码对应的目标代码。通过将待处理的源代码文件解析为抽象语法树,基于该抽象语法树匹配第一语言类型的第一字符,可以准确的识别出所述源代码所包括的全部第一字符;基于该目标代码包括语言切换程序的调用指令,在目标代码运行时可以根据用户指定的目标语言类型,基于调用指令中的标识符获取目标语言类型的字符文本并将其展示在产品页面,从而实现了产品页面由第一语言类型至目标语言类型的切换,并且包含调用指令的目标代码可以灵活的适应各种语言下的页面显示切换,减少了代码量和日常维护工作量,提高了处理效率。In the above embodiment, the developer uses the characters of the first language type to realize the page display when writing the development source code of the product page. This application obtains the code to be processed related to the display of the product page, and generates the code corresponding to the code to be processed. The first abstract syntax tree traverses the nodes of the first abstract syntax tree, replaces the characters of the first language type included in each node with the corresponding calling instructions, and converts back to the to-be-processed character according to the replaced second abstract syntax tree. The target code corresponding to the code. By parsing the source code file to be processed into an abstract syntax tree, and matching the first characters of the first language type based on the abstract syntax tree, all first characters included in the source code can be accurately identified; based on the target code Including the calling instruction of the language switching program, when the target code is running, according to the target language type specified by the user, the character text of the target language type can be obtained based on the identifier in the calling instruction and displayed on the product page, thus realizing the product page. Switching from the first language type to the target language type, and the target code containing the calling instructions can flexibly adapt to page display switching in various languages, reducing the amount of code and daily maintenance workload, and improving processing efficiency.

在一些实施例中,所述待处理代码可以通过获取下述方式获取:In some embodiments, the code to be processed can be obtained by obtaining:

依据配置文件或者命令行,获取开发者预配置的待过滤文件的存储路径信息以及待忽略文件信息,所述待忽略文件信息是指需要从所述存储路径信息所指示的文件中去除的文件信息;According to the configuration file or command line, obtain the storage path information of the files to be filtered and the file information to be ignored pre-configured by the developer. The file information to be ignored refers to the file information that needs to be removed from the files indicated by the storage path information. ;

从所述存储路径信息中获取到第一代码文件,并从所述第一代码文件中去除所述待忽略文件,得到第二代码文件;Obtain a first code file from the storage path information, and remove the file to be ignored from the first code file to obtain a second code file;

遍历所述第二代码文件,响应于所述第二代码文件中的代码包括第一语言类型的第一字符,则确定该第二代码文件中的代码为待处理代码。The second code file is traversed, and in response to the code in the second code file including the first character of the first language type, it is determined that the code in the second code file is the code to be processed.

在本公开实施例中,通过预先设置的存储路径信息以及待忽略文件信息可以准确地确定出需要进行字符替换为指令的待处理代码文件,提高了代码处理效率。In the embodiment of the present disclosure, the code file to be processed that requires character replacement with instructions can be accurately determined through the preset storage path information and the file information to be ignored, which improves the code processing efficiency.

在一些实施例中,所述待处理代码包括vue代码;上述步骤S101所述的获取待处理代码的第一抽象语法树,可以包括下述实现步骤:In some embodiments, the code to be processed includes Vue code; obtaining the first abstract syntax tree of the code to be processed in the above step S101 may include the following implementation steps:

获取所述vue代码中的模板代码和脚本代码;分别获取所述模板代码对应的vue模板抽象语法树、以及所述脚本代码对应的脚本抽象语法树。Obtain the template code and script code in the vue code; obtain the vue template abstract syntax tree corresponding to the template code and the script abstract syntax tree corresponding to the script code respectively.

Vue代码是指使用vue框架编写的前端代码,用于构建用户界面的JavaScript框架,通常包括模板代码template、脚本代码Script和样式代码CSS;其中,所述模板代码使用HTML标记和特定的vue语法,定义用户界面的结构和展示逻辑;所述脚本代码遵循标准的JavaScript语法,包含数据对象、方法、计算属性和生命周期钩子函数等内容,定义和管理应用程序的逻辑和行为;所述样式代码用于定义组件的样式。Vue code refers to the front-end code written using the vue framework, a JavaScript framework used to build the user interface, usually including template code template, script code Script and style code CSS; where the template code uses HTML tags and specific vue syntax, Define the structure and display logic of the user interface; the script code follows standard JavaScript syntax, including data objects, methods, calculated properties, life cycle hook functions, etc., and defines and manages the logic and behavior of the application; the style code is used Used to define the style of a component.

在获取vue代码的抽象语法树时,基于其中的模板代码与脚本代码采用不同的语法,则两个代码生成抽象语法树的过程不同,因此,先解析vue代码获取模板代码和脚本代码,并分别对模板代码和脚本代码进行解析,获取对应给的vue模板抽象语法树以及脚本抽象语法树。When obtaining the abstract syntax tree of the vue code, based on the fact that the template code and the script code use different syntax, the two codes generate the abstract syntax tree differently. Therefore, the vue code is first parsed to obtain the template code and script code, and then they are Parse the template code and script code to obtain the corresponding vue template abstract syntax tree and script abstract syntax tree.

示例性地,可以通过Vue提供的工具包@vue/compiler-sfc对所述vue代码进行解析,提取模板代码和脚本代码,并且可以生成模板代码对应的vue模板抽象语法树;对于所述脚本代码,可以通过@babel/parser编译脚本源码,获得对应的脚本抽象语法树。For example, the Vue code can be parsed through the toolkit @vue/compiler-sfc provided by Vue, the template code and script code can be extracted, and the Vue template abstract syntax tree corresponding to the template code can be generated; for the script code , you can compile the script source code through @babel/parser to obtain the corresponding script abstract syntax tree.

在本公开实施例中,针对于基于vue框架开发的产品页面,可以获取相应的待处理的vue代码以及js代码,基于vue代码的结构特性分别获取模板抽象语法树和脚本抽象语法树,从而实现对vue语法编写的源代码中的字符匹配以及替换为调用指令。In the embodiment of the present disclosure, for product pages developed based on the vue framework, the corresponding vue code and js code to be processed can be obtained, and the template abstract syntax tree and script abstract syntax tree are respectively obtained based on the structural characteristics of the vue code, thereby achieving Match characters in source code written in Vue syntax and replace them with calling instructions.

在一些实施例中,前述步骤S103所述的将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,可以通过下述方式实现:In some embodiments, the aforementioned step S103 of replacing the first character in the target node with a calling instruction of the language switching program can be implemented in the following manner:

获取所述目标节点所包括的字符串并匹配所述第一字符;根据预设的标识符生成方法,确定所述第一字符的标识符;响应于第一文件中不包括所述第一字符的标识符,将第一字符的标识符以及所述第一字符写入所述第一文件;其中,所述第一文件用于存储字符的标识符以及在第一语言类型下的第二字符;根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Obtain the string included in the target node and match the first character; determine the identifier of the first character according to a preset identifier generation method; respond to the first file not including the first character The identifier of the first character and the first character are written into the first file; wherein the first file is used to store the identifier of the character and the second character in the first language type ; Generate a calling instruction based on the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.

其中,对于所确定的目标节点,先获取所述目标节点所包括的字符串文本,可以通过正则表达式匹配出第一语言类型的第一字符,具体的匹配规则可以根据第一语言类型和各个目标节点中的字符串文本中的第一字符特征进行设置,本申请对此不作限定。Wherein, for the determined target node, the string text included in the target node is first obtained, and the first character of the first language type can be matched through a regular expression. The specific matching rules can be based on the first language type and each The first character characteristic in the string text in the target node is set, which is not limited in this application.

所述标识符生成方法可以是MD5算法。MD5算法具有下述特点:任意长度的输入数据均生成固定长度128位的哈希值;生成的哈希值唯一,并且相同的输入数据生成的哈希值相同。基于MD5的特点,对于需要国际化的产品中存在的多个相同字符,可以复用同一个哈希值,并且生成的哈希值为固定长度,便于插入代码并不影响代码格式。The identifier generation method may be the MD5 algorithm. The MD5 algorithm has the following characteristics: input data of any length generates a fixed-length 128-bit hash value; the generated hash value is unique, and the same input data generates the same hash value. Based on the characteristics of MD5, the same hash value can be reused for multiple identical characters in products that require internationalization, and the generated hash value is of a fixed length, which facilitates code insertion without affecting the code format.

所述第一文件是指用于存储第一语言类型的字符、以及该字符的标识符的配置文件,其初始化为空白文件或者包含部分开发人员预先写入的第一语言类型的字符以及标识符。The first file refers to a configuration file used to store characters of the first language type and identifiers of the characters. It is initialized as a blank file or contains characters and identifiers of the first language type pre-written by some developers. .

在遍历待处理代码的第一抽象语法树的过程中,在确定的目标节点中匹配到第一字符时,根据预置方法生成该第一字符的标识符,检测所述第一文件中是否存在该第一字符的标识符,如果存在,则直接生成包含该第一字符的标识符的调用指令,并修改所述目标节点;如果不存在,则将目标节点中的第一字符以及该第一字符的标识符写入所述第一文件,并生成调用指令。In the process of traversing the first abstract syntax tree of the code to be processed, when the first character is matched in the determined target node, the identifier of the first character is generated according to the preset method, and whether it exists in the first file is detected. If the identifier of the first character exists, a calling instruction containing the identifier of the first character is directly generated and the target node is modified; if it does not exist, the first character in the target node and the first character are modified. Character identifiers are written to the first file and call instructions are generated.

在一个示例中,该实施例将目标节点中的第一字符以及该第一字符的标识符写入所述第一文件后,预配置的其他语言类型的语言文件中会分别更新写入所述第一标识符以及相应语言的翻译文本,该翻译文本可以通过调用相应的翻译API接口实现。或者,可以在所述第一抽象语法树中的全部目标节点处理完成后,依据标识符将对应文本分别写入其他语言类型的语言文件中。In one example, after this embodiment writes the first character in the target node and the identifier of the first character into the first file, the preconfigured language files of other language types will be updated and written into the first file respectively. The first identifier and the translation text in the corresponding language. The translation text can be implemented by calling the corresponding translation API interface. Alternatively, after all target nodes in the first abstract syntax tree are processed, the corresponding texts can be written into language files of other language types according to the identifiers.

在本公开实施例中,通过匹配目标节点中的第一字符进行字符替换的同时将该第一字符存储至第一文件,在实现代码国际化配置的过程中同步实现收集第一字符的国际化词条,提高了国际化词条收集的准确性和灵活性,减少了开发人员预配置工作量。In the embodiment of the present disclosure, character replacement is performed by matching the first character in the target node and the first character is stored in the first file. In the process of realizing code internationalization configuration, the internationalization of collecting the first character is simultaneously realized. Entries improve the accuracy and flexibility of international entry collection and reduce the preconfiguration workload of developers.

在一些实施例中前述步骤S103所述的将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,也可以通过以下步骤实现:In some embodiments, the aforementioned step S103 of replacing the first character in the target node with the calling instruction of the language switching program can also be implemented through the following steps:

获取所述目标节点所包括的字符串并匹配所述第一字符;响应于检测到第二文件中包括所述第一字符,根据所述第二文件获取所述第一字符的标识符;所述第二文件包括预存储字符的标识符以及在第一语言类型下的第三字符;根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Obtain the string included in the target node and match the first character; in response to detecting that the first character is included in the second file, obtain the identifier of the first character according to the second file; The second file includes the identifier of the pre-stored character and the third character under the first language type; generate a calling instruction according to the identifier of the first character, and modify the target node to replace the first character The calling instruction for the language switching program.

其中,所述第二文件是开发人员预配置的、用于存储字符及标识符的配置的,该语言文件所包括的字符至少囊括所述第一抽象语法树中的全部目标节点所包括的第一字符。Wherein, the second file is pre-configured by the developer and is used to store the configuration of characters and identifiers. The characters included in the language file include at least the third character included in all target nodes in the first abstract syntax tree. One character.

在本公开实施例中,通过预先配置字符和标识符的对应关系并写入语言文件,使得在对第一抽象语法树中的目标节点进行第一字符替换时可以直接调用第二文件信息,降低了对设备算力的要求,简化了代码处理流程。In the embodiment of the present disclosure, by preconfiguring the corresponding relationship between characters and identifiers and writing them into the language file, the second file information can be directly called when replacing the first character on the target node in the first abstract syntax tree, reducing the It reduces the requirements for equipment computing power and simplifies the code processing process.

在一些实施例中,响应于目标节点中匹配到的第一字符是包含变量的字符串,对于上述两个实施例中的第一文件和第二文件所写入的标识符以及对应的字符,包含变量的字符串对应写入所述第一文件和所述第二文件中的文本是将所述变量替换为占位符的第一语言类型的字符串;所生成的所述语言切换程序的调用指令还包括所述变量的名称与变量取值。In some embodiments, in response to the first character matched in the target node being a string containing a variable, for the identifiers and corresponding characters written in the first file and the second file in the above two embodiments, The string containing the variable corresponding to the text written in the first file and the second file is a string of the first language type in which the variable is replaced with a placeholder; the generated language switching program The calling instruction also includes the name and variable value of the variable.

例如,目标节点中所包括的第一字符为{‘user:username你好,欢迎登录’},则写入第一文件和第二文件中的字符为:(标识符S):‘%你好,欢迎登录’或者‘{}你好,欢迎登录’;若调用指令采用$t(),则将所述第一字符替换调用指令为{‘$t(S,user:username)’},基于该变量的实际取值会被替换为调用指令,从而user:username获取的是经过语言切换后的文本,从而将占位符替换为变量的实际取值,实现了包含变量的字符串的语言切换。For example, if the first character included in the target node is {'user:username Hello, welcome to log in'}, then the characters written in the first file and the second file are: (identifier S): '% Hello , welcome to log in' or '{}Hello, welcome to log in'; if the calling instruction uses $t(), replace the first character with the calling instruction as {'$t(S, user:username)'}, based on The actual value of the variable will be replaced by the calling instruction, so that user:username obtains the text after language switching, thus replacing the placeholder with the actual value of the variable, realizing language switching of the string containing the variable. .

在本公开实施例中,通过将包含变量的字符串存入语言文件时使用占位符替换,并在调用指令中传递变量取值作为参数,从而实现了源代码中包含变量的字符串的语言切换。In the embodiment of the present disclosure, by using placeholder replacement when storing the string containing variables in the language file, and passing the variable value as a parameter in the calling instruction, the language of the string containing variables in the source code is realized. switch.

在一些实施例中,上述实施例中所述的语言文件中存储的字符以及标识符可以以键值对的方式存储。可选的,class类或JSON对象类。Class(key value),其中,key可以表示字符串的唯一标识,value对应于不同的语言类型。In some embodiments, the characters and identifiers stored in the language files described in the above embodiments may be stored in the form of key-value pairs. Optional, class class or JSON object class. Class(key value), where key can represent the unique identifier of a string, and value corresponds to different language types.

为便于本领域技术人员更好的理解本申请所提供的方案,接下来结合一种示例性的基于vue框架开发的产品界面国际化场景,对本申请作进一步的示例性说明。In order to facilitate those skilled in the art to better understand the solution provided by this application, the following is a further exemplary explanation of this application in conjunction with an exemplary product interface internationalization scenario developed based on the Vue framework.

在本实施例中,假定开发者是基于中文设计并编写该产品界面的源代码文件,开发人员在完成基于中文的页面开发后,预先设置了待处理代码所在的源代码文件的存储位置信息及过滤信息、自动生成用于存储不同语言的字符及标识符的输出文件地址、i18n插件的路径信息以及调用方法等信息,为本实施例的实现完成初始配置。基于此,如图2所示,该实施例所提供的代码处理方法可以包括下述步骤:In this embodiment, it is assumed that the developer designs and writes the source code file of the product interface based on Chinese. After completing the Chinese-based page development, the developer pre-sets the storage location information and source code file of the code to be processed. Filtering information, automatically generating output file addresses for storing characters and identifiers in different languages, i18n plug-in path information, calling methods and other information complete the initial configuration for the implementation of this embodiment. Based on this, as shown in Figure 2, the code processing method provided in this embodiment may include the following steps:

S201,根据预设的存储位置信息以及过滤信息,从产品的开发源代码中确定第三代码文件;S201, determine the third code file from the product development source code according to the preset storage location information and filtering information;

S202,遍历所述第三代码文件,响应于检测到第三代码文件中的代码包含中文字符,则获取所述第三代码文件中的代码作为待处理代码;S202, traverse the third code file, and in response to detecting that the code in the third code file contains Chinese characters, obtain the code in the third code file as the code to be processed;

S203,响应于所述待处理代码为vue代码,获取vue代码中的模板代码和脚本代码,并通过vue语法树生成方法获取所述模板代码的vue模板抽象语法树;基于babel插件下的语法树生成方法获取所述脚本代码对应的脚本抽象语法树;S203, in response to the code to be processed being vue code, obtain the template code and script code in the vue code, and obtain the vue template abstract syntax tree of the template code through the vue syntax tree generation method; based on the syntax tree under the babel plug-in The generation method obtains the script abstract syntax tree corresponding to the script code;

S204,响应于所述待处理代码为JavaScript代码,通过babel插件下的语法树生成方法获取对应的JS抽象语法树;S204, in response to the code to be processed being JavaScript code, obtain the corresponding JS abstract syntax tree through the syntax tree generation method under the babel plug-in;

S205,遍历目标抽象语法树的各个节点,获取当前节点所包括的文本内容,响应于匹配到中文字符,根据预设的MD5算法生成所述中文字符的标识符,当检测到中文的文本存储文件中不包括该标识符时,将该中文以及该中文的标识符写入中文的文本存储文件,并生成包含该标识符的语言切换程序的调用指令,将所述中文字符替换为该调用指令,并将修改后的文本内容写入当前节点;所述目标抽象语法树包括脚本抽象语法树、vue模板抽象语法树、JS抽象语法树;S205: Traverse each node of the target abstract syntax tree, obtain the text content included in the current node, and in response to matching Chinese characters, generate identifiers of the Chinese characters according to the preset MD5 algorithm. When a Chinese text storage file is detected When the identifier is not included in , write the Chinese character and the Chinese identifier into the Chinese text storage file, and generate a calling instruction for the language switching program containing the identifier, and replace the Chinese characters with the calling instruction, And write the modified text content into the current node; the target abstract syntax tree includes script abstract syntax tree, vue template abstract syntax tree, and JS abstract syntax tree;

其中,在匹配到中文字符时,根据中文字符是否包含变量,分别执行不同的语言文件写入方式以及调用指令生成方式,具体参见前述实施例。Among them, when a Chinese character is matched, different language file writing methods and calling instruction generation methods are executed according to whether the Chinese character contains variables. For details, please refer to the foregoing embodiments.

S206,获取节点修改后得到的更新抽象语法树,所述更新抽象语法树与所述目标抽象语法树一一对应,并根据该更新抽象语法树生成与待处理代码对应的目标代码;S206, obtain the updated abstract syntax tree obtained after node modification, the updated abstract syntax tree corresponds to the target abstract syntax tree one-to-one, and generate the target code corresponding to the code to be processed based on the updated abstract syntax tree;

其中,对于同一vue代码的对应vue模板抽象语法树和脚本抽象语法树,将得到的更新vue模板抽象语法树、更新脚本抽象语法树拼接生成包含语言切换程序的调用指令的目标vue代码。Among them, for the corresponding vue template abstract syntax tree and script abstract syntax tree of the same vue code, the obtained updated vue template abstract syntax tree and updated script abstract syntax tree are spliced to generate a target vue code that contains the calling instruction of the language switching program.

S207,根据中文的语言文件和设置的语言类型,调用API接口逐条获取同一标识符对应的中文字符在不同语言类型下的翻译文本,将标识符和翻译文本写入对应语言的语言文件中;S207: According to the Chinese language file and the set language type, call the API interface to obtain the translated text of the Chinese characters corresponding to the same identifier in different language types one by one, and write the identifier and the translated text into the language file of the corresponding language;

S208,将所述待处理代码替换为所述目标代码,得到支持多语言的国际化产品源代码,并在检测到产品页面发生语言切换时,运行所述目标代码从目标语言的语言文件中按照标识符获取对应翻译文本。S208: Replace the to-be-processed code with the target code to obtain an internationalized product source code that supports multiple languages, and when it is detected that language switching occurs on the product page, run the target code from the language file of the target language according to The identifier obtains the corresponding translation text.

在本实施例中,开发者使用中文编写产品页面的开发源代码,通过本实施例先将产品页面显示相关的待处理代码文件转换为第一抽象语法树,遍历第一抽象语法书的节点匹配中文字符,采用MD5算法生成中文字符的唯一标识符,实现唯一标识符的复用,并根据唯一标识符以及中文字符获取不同语言的国际化词条,基于该唯一标识符生成语言切换程序的调用指令替换中文字符,得到第二抽象语法树,满足了源代码中包括的各种字符替换需求;根据所述第二抽象语法树转换回与待处理代码对应的目标代码,利用包含调用指令的目标代码替换待处理代码,基于目标代码支持多种语言,从而实现了产品页面的多种语言切换,减少了代码量和日常维护工作量,提高了处理效率。In this embodiment, the developer uses Chinese to write the development source code of the product page. Through this embodiment, the code file to be processed related to the product page display is first converted into the first abstract syntax tree, and the node matching of the first abstract syntax book is traversed. For Chinese characters, the MD5 algorithm is used to generate unique identifiers for Chinese characters, to realize the reuse of unique identifiers, and to obtain international entries in different languages based on the unique identifiers and Chinese characters, and to generate calls to the language switching program based on the unique identifiers. The instruction replaces Chinese characters to obtain a second abstract syntax tree, which meets various character replacement requirements included in the source code; according to the second abstract syntax tree, it is converted back to the target code corresponding to the code to be processed, and the target code containing the calling instruction is used The code replaces the code to be processed and supports multiple languages based on the target code, thus realizing multiple language switching of product pages, reducing the amount of code and daily maintenance workload, and improving processing efficiency.

与前述代码处理方法的实施例相对应,参见图3所示,本申请还提供了代码处理装置的实施例,所述装置包括:Corresponding to the embodiment of the aforementioned code processing method, as shown in Figure 3, this application also provides an embodiment of a code processing device, and the device includes:

第一语法树获取模块310,用于获取待处理代码的第一抽象语法树;其中,所述待处理代码中包括第一字符,所述第一字符为第一语言类型的字符;The first syntax tree acquisition module 310 is used to obtain the first abstract syntax tree of the code to be processed; wherein the code to be processed includes a first character, and the first character is a character of the first language type;

目标节点确定模块320,用于遍历所述第一抽象语法树的节点,从所述第一抽象语法树的节点中确定出内容包含所述第一字符的目标节点;The target node determination module 320 is configured to traverse the nodes of the first abstract syntax tree and determine the target node whose content contains the first character from the nodes of the first abstract syntax tree;

第二语法树获取模块330,用于将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,以生成第二抽象语法树;所述调用指令至少包括所述第一字符的标识符;The second syntax tree acquisition module 330 is used to replace the first character in the target node with a calling instruction of the language switching program to generate a second abstract syntax tree; the calling instruction at least includes the first character identifier;

目标代码生成模块340,用于根据所述第二抽象语法树,生成与所述待处理代码对应的目标代码,所述目标代码用于在运行过程中将所述第一字符由第一语言类型切换为目标语言类型。The target code generation module 340 is configured to generate target code corresponding to the code to be processed according to the second abstract syntax tree. The target code is used to convert the first character into a first language type during operation. Switch to the target language type.

在一些实施例中,所述待处理代码包括vue代码;所述第一语法树获取模块具体用于:In some embodiments, the code to be processed includes Vue code; the first syntax tree acquisition module is specifically used to:

获取所述vue代码中的模板代码和脚本代码;Get the template code and script code in the vue code;

分别获取所述模板代码对应的vue模板抽象语法树、以及所述脚本代码对应的脚本抽象语法树。Obtain respectively the vue template abstract syntax tree corresponding to the template code and the script abstract syntax tree corresponding to the script code.

在一些实施例中,所述第二抽象语法树获取模块具体用于:In some embodiments, the second abstract syntax tree acquisition module is specifically used to:

获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;

根据预设的标识符生成方法,确定所述第一字符的标识符;Determine the identifier of the first character according to a preset identifier generation method;

响应于第一文件中不包括所述第一字符的标识符,将第一字符的标识符以及所述第一字符写入所述第一文件;其中,所述第一文件用于存储字符的标识符以及在第一语言类型下的第二字符;In response to the first file not including the identifier of the first character, writing the identifier of the first character and the first character into the first file; wherein the first file is used to store the character The identifier and the second character in the first language type;

根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.

在一些实施例中,所述第二抽象语法树获取模块具体用于:In some embodiments, the second abstract syntax tree acquisition module is specifically used to:

获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;

响应于检测到第二文件中包括所述第一字符,根据所述第二文件获取所述第一字符的标识符;所述第二文件包括预存储字符的标识符以及在第一语言类型下的第三字符;In response to detecting that the first character is included in the second file, obtaining an identifier of the first character according to the second file; the second file includes an identifier of a pre-stored character and in the first language type the third character;

根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.

在一些实施例中,响应于匹配到的所述第一字符包括包含变量的字符串,则所述语言切换程序的调用指令还包括所述变量的名称与变量取值。In some embodiments, in response to the matched first character including a string containing a variable, the calling instruction of the language switching program further includes the name of the variable and the variable value.

上述装置中各个单元的功能和作用的实现过程具体详见上述方法中对应步骤的实现过程,在此不再赘述。For details on the implementation process of the functions and effects of each unit in the above device, please refer to the implementation process of the corresponding steps in the above method, and will not be described again here.

对于装置实施例而言,由于其基本对应于方法实施例,所以相关之处参见方法实施例的部分说明即可。以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本申请方案的目的。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。As for the device embodiment, since it basically corresponds to the method embodiment, please refer to the partial description of the method embodiment for relevant details. The device embodiments described above are only illustrative. The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they may be located in One location, or it can be distributed across multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this application. Persons of ordinary skill in the art can understand and implement the method without any creative effort.

本申请实施例还提供了一种电子设备,该电子设备的结构示意图如图4所示,该电子设备400包括至少一个处理器401、存储器402和总线403,至少一个处理器401均与存储器402电连接;存储器402被配置用于存储有至少一个计算机可执行指令,处理器401被配置用于执行该至少一个计算机可执行指令,从而执行如本申请中任意一个实施例或任意一种可选实施方式提供的任意一种代码处理方法的步骤。An embodiment of the present application also provides an electronic device. The structural diagram of the electronic device is shown in Figure 4. The electronic device 400 includes at least one processor 401, a memory 402 and a bus 403. The at least one processor 401 is connected to the memory 402. Electrically connected; the memory 402 is configured to store at least one computer-executable instruction, and the processor 401 is configured to execute the at least one computer-executable instruction, thereby executing any embodiment or any alternative in this application. The steps of any code processing method provided by the embodiment.

进一步,处理器401可以是FPGA(Field-Programmable Gate Array,现场可编程门阵列)或者其它具有逻辑处理能力的器件,如MCU(Microcontroller Unit,微控制单元)、CPU(Central Process Unit,中央处理器)。Further, the processor 401 may be an FPGA (Field-Programmable Gate Array) or other devices with logic processing capabilities, such as an MCU (Microcontroller Unit) or a CPU (Central Process Unit). ).

在本申请提供的技术方案中,通过将遍历待处理代码文件的抽象语法树的各个节点,将节点中所包括的第一语言类型的字符替换为语言切换调用指令,满足代码中的各种类型的字符替换需求,并基于修改后的抽象语法树生成包含语言切换调用指令的代码文件,从而实现了根据用户选定语言动态切换页面的语言,提高了处理效率。In the technical solution provided by this application, by traversing each node of the abstract syntax tree of the code file to be processed, and replacing the characters of the first language type included in the node with a language switching call instruction, various types of code in the code can be satisfied. The character replacement requirements are met, and a code file containing language switching call instructions is generated based on the modified abstract syntax tree, thereby realizing dynamic switching of the language of the page according to the language selected by the user, and improving processing efficiency.

本申请实施例还提供了另一种可读存储介质,存储有计算机程序,该计算机程序用于被处理器执行时实现本申请中任意一个实施例或任意一种可选实施方式提供的任意一种代码处理方法的步骤。The embodiment of the present application also provides another readable storage medium, which stores a computer program. The computer program is used to implement any one of the embodiments of the present application or any optional implementation mode when executed by the processor. Steps for each code processing method.

本申请实施例提供的可读存储介质包括但不限于任何类型的盘(包括软盘、硬盘、光盘、CD-ROM、和磁光盘)、ROM(Read-Only Memory,只读存储器)、RAM(Random AccessMemory,随即存储器)、EPROM(Erasable Programmable Read-Only Memory,可擦写可编程只读存储器)、EEPROM(Electrically Erasable Programmable Read-Only Memory,电可擦可编程只读存储器)、闪存、磁性卡片或光线卡片。也就是,可读存储介质包括由设备(例如,计算机)以能够读的形式存储或传输信息的任何介质。Readable storage media provided by embodiments of the present application include but are not limited to any type of disk (including floppy disk, hard disk, optical disk, CD-ROM, and magneto-optical disk), ROM (Read-Only Memory), RAM (Random AccessMemory, EPROM (Erasable Programmable Read-Only Memory, Erasable Programmable Read-Only Memory), EEPROM (Electrically Erasable Programmable Read-Only Memory), flash memory, magnetic card or Light card. That is, readable storage media includes any medium that stores or transmits information in a form that can be read by a device (eg, a computer).

在本申请提供的技术方案中,通过将遍历待处理代码文件的抽象语法树的各个节点,将节点中所包括的第一语言类型的字符替换为语言切换调用指令,满足代码中的各种类型的字符替换需求,并基于修改后的抽象语法树生成包含语言切换调用指令的代码文件,从而实现了根据用户选定语言动态切换页面的语言,提高了处理效率。In the technical solution provided by this application, by traversing each node of the abstract syntax tree of the code file to be processed, and replacing the characters of the first language type included in the node with a language switching call instruction, various types of code in the code can be satisfied. The character replacement requirements are met, and a code file containing language switching call instructions is generated based on the modified abstract syntax tree, thereby realizing dynamic switching of the language of the page according to the language selected by the user, and improving processing efficiency.

由此,主题的特定实施例已被描述。其他实施例在所附权利要求书的范围以内。在某些情况下,权利要求书中记载的动作可以以不同的顺序执行并且仍实现期望的结果。此外,附图中描绘的处理并非必需所示的特定顺序或顺次顺序,以实现期望的结果。在某些实现中,多任务和并行处理可能是有利的。Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve desirable results. Furthermore, the processes depicted in the figures do not necessarily require the specific order shown, or sequential order, to achieve desirable results. In some implementations, multitasking and parallel processing may be advantageous.

虽然本说明书包含许多具体实施细节,但是这些不应被解释为限制任何发明的范围或所要求保护的范围,而是主要用于描述特定发明的具体实施例的特征。本说明书内在多个实施例中描述的某些特征也可以在单个实施例中被组合实施。另一方面,在单个实施例中描述的各种特征也可以在多个实施例中分开实施或以任何合适的子组合来实施。此外,虽然特征可以如上所述在某些组合中起作用并且甚至最初如此要求保护,但是来自所要求保护的组合中的一个或多个特征在一些情况下可以从该组合中去除,并且所要求保护的组合可以指向子组合或子组合的变型。Although this specification contains many specific implementation details, these should not be construed to limit the scope of any invention or what is claimed, but rather serve primarily to describe features of specific embodiments of particular inventions. Certain features described in this specification as multiple embodiments can also be combined in a single embodiment. On the other hand, various features that are described in a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination. Furthermore, while features may function in certain combinations as described above and may even be originally claimed as such, one or more features from a claimed combination may in some cases be removed from that combination, and as claimed A protected combination can point to a subcombination or a variant of a subcombination.

以上所述仅为本申请的较佳实施例而已,并不用以限制本申请,凡在本申请的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本申请保护的范围之内。The above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the present application. within the scope of protection.

Claims (10)

Translated fromChinese
1.一种代码处理方法,其特征在于,所述方法包括:1. A code processing method, characterized in that the method includes:获取待处理代码的第一抽象语法树;其中,所述待处理代码中包括第一字符,所述第一字符为第一语言类型的字符;Obtain the first abstract syntax tree of the code to be processed; wherein the code to be processed includes a first character, and the first character is a character of the first language type;遍历所述第一抽象语法树的节点,从所述第一抽象语法树的节点中确定出内容包含所述第一字符的目标节点;Traverse the nodes of the first abstract syntax tree, and determine the target node whose content contains the first character from the nodes of the first abstract syntax tree;将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,以生成第二抽象语法树;所述调用指令至少包括所述第一字符的标识符;Replace the first character in the target node with a calling instruction of the language switching program to generate a second abstract syntax tree; the calling instruction at least includes an identifier of the first character;根据所述第二抽象语法树,生成与所述待处理代码对应的目标代码,所述目标代码用于在运行过程中将所述第一字符由第一语言类型切换为目标语言类型。According to the second abstract syntax tree, a target code corresponding to the code to be processed is generated, and the target code is used to switch the first character from the first language type to the target language type during operation.2.根据权利要求1所述的方法,其特征在于,所述待处理代码包括vue代码;所述第一抽象语法树包括vue模板抽象语法树和脚本抽象语法树;2. The method according to claim 1, characterized in that the code to be processed includes vue code; the first abstract syntax tree includes a vue template abstract syntax tree and a script abstract syntax tree;所述获取待处理代码的第一抽象语法树,包括:Obtaining the first abstract syntax tree of the code to be processed includes:获取所述vue代码中的模板代码和脚本代码;Get the template code and script code in the vue code;分别获取所述模板代码对应的vue模板抽象语法树、以及所述脚本代码对应的脚本抽象语法树。Obtain respectively the vue template abstract syntax tree corresponding to the template code and the script abstract syntax tree corresponding to the script code.3.根据权利要求1所述的方法,其特征在于,所述将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,包括:3. The method according to claim 1, characterized in that said replacing the first character in the target node with a calling instruction of a language switching program includes:获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;根据预设的标识符生成方法,确定所述第一字符的标识符;Determine the identifier of the first character according to a preset identifier generation method;响应于第一文件中不包括所述第一字符的标识符,将第一字符的标识符以及所述第一字符写入所述第一文件;其中,所述第一文件用于存储字符的标识符以及在第一语言类型下的第二字符;In response to the first file not including the identifier of the first character, writing the identifier of the first character and the first character into the first file; wherein the first file is used to store the character The identifier and the second character in the first language type;根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.4.根据权利要求1所述的方法,其特征在于,所述将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,包括:4. The method according to claim 1, characterized in that said replacing the first character in the target node with a calling instruction of a language switching program includes:获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;响应于检测到第二文件中包括所述第一字符,根据所述第二文件获取所述第一字符的标识符;所述第二文件包括预存储字符的标识符以及在第一语言类型下的第三字符;In response to detecting that the first character is included in the second file, obtaining an identifier of the first character according to the second file; the second file includes an identifier of a pre-stored character and in the first language type the third character;根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.5.根据权利要求3或4所述的方法,其特征在于,响应于匹配到的所述第一字符包括包含变量的字符串,则所述语言切换程序的调用指令还包括所述变量的名称与变量取值。5. The method according to claim 3 or 4, characterized in that, in response to the matched first character including a string containing a variable, the calling instruction of the language switching program further includes the name of the variable. and variable values.6.一种代码处理装置,其特征在于,所述装置包括:6. A code processing device, characterized in that the device includes:第一语法树获取模块,用于获取待处理代码的第一抽象语法树;其中,所述待处理代码中包括第一字符,所述第一字符为第一语言类型的字符;The first syntax tree acquisition module is used to acquire the first abstract syntax tree of the code to be processed; wherein the code to be processed includes a first character, and the first character is a character of the first language type;目标节点确定模块,用于遍历所述第一抽象语法树的节点,从所述第一抽象语法树的节点中确定出内容包含所述第一字符的目标节点;A target node determination module, configured to traverse the nodes of the first abstract syntax tree and determine the target node whose content contains the first character from the nodes of the first abstract syntax tree;第二语法树获取模块,用于将所述目标节点中的所述第一字符替换为语言切换程序的调用指令,以生成第二抽象语法树;所述调用指令至少包括所述第一字符的标识符;A second syntax tree acquisition module is used to replace the first character in the target node with a calling instruction of the language switching program to generate a second abstract syntax tree; the calling instruction at least includes the first character identifier;目标代码生成模块,用于根据所述第二抽象语法树,生成与所述待处理代码对应的目标代码,所述目标代码用于在运行过程中将所述第一字符由第一语言类型切换为目标语言类型。A target code generation module, configured to generate target code corresponding to the code to be processed according to the second abstract syntax tree, the target code being used to switch the first character from the first language type during operation is the target language type.7.根据权利要求6所述的装置,其特征在于,所述第二抽象语法树获取模块具体用于:7. The device according to claim 6, characterized in that the second abstract syntax tree acquisition module is specifically used to:获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;根据预设的标识符生成方法,确定所述第一字符的标识符;Determine the identifier of the first character according to a preset identifier generation method;响应于第一文件中不包括所述第一字符的标识符,将第一字符的标识符以及所述第一字符写入所述第一文件;其中,所述第一文件用于存储字符的标识符以及在第一语言类型下的第二字符;In response to the first file not including the identifier of the first character, writing the identifier of the first character and the first character into the first file; wherein the first file is used to store the character The identifier and the second character in the first language type;根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.8.根据权利要求6所述的装置,其特征在于,所述第二抽象语法树获取模块具体用于:8. The device according to claim 6, characterized in that the second abstract syntax tree acquisition module is specifically used to:获取所述目标节点所包括的字符串并匹配所述第一字符;Obtain the string included in the target node and match the first character;响应于检测到第二文件中包括所述第一字符,根据所述第二文件获取所述第一字符的标识符;所述第二文件包括预存储字符的标识符以及在第一语言类型下的第三字符;In response to detecting that the first character is included in the second file, obtaining an identifier of the first character according to the second file; the second file includes an identifier of a pre-stored character and in the first language type the third character;根据所述第一字符的标识符生成调用指令,并修改所述目标节点,将所述第一字符替换为所述语言切换程序的调用指令。Generate a calling instruction according to the identifier of the first character, modify the target node, and replace the first character with the calling instruction of the language switching program.9.一种电子设备,其特征在于,包括:处理器、存储器;9. An electronic device, characterized by including: a processor and a memory;所述存储器,用于存储计算机程序;The memory is used to store computer programs;所述处理器,用于通过调用所述计算机程序,执行如权利要求1-5中任一项所述的代码处理方法。The processor is configured to execute the code processing method according to any one of claims 1-5 by calling the computer program.10.一种可读存储介质,其上存储有计算机程序,其特征在于,所述程序被处理器执行时实现如权利要求1-5中任一项所述的代码处理方法。10. A readable storage medium with a computer program stored thereon, characterized in that when the program is executed by a processor, the code processing method according to any one of claims 1-5 is implemented.
CN202311182822.1A2023-09-132023-09-13Code processing method, device, equipment and readable storage mediumPendingCN117234507A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202311182822.1ACN117234507A (en)2023-09-132023-09-13Code processing method, device, equipment and readable storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202311182822.1ACN117234507A (en)2023-09-132023-09-13Code processing method, device, equipment and readable storage medium

Publications (1)

Publication NumberPublication Date
CN117234507Atrue CN117234507A (en)2023-12-15

Family

ID=89092391

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202311182822.1APendingCN117234507A (en)2023-09-132023-09-13Code processing method, device, equipment and readable storage medium

Country Status (1)

CountryLink
CN (1)CN117234507A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN119829061A (en)*2024-11-262025-04-15金蝶软件(中国)有限公司Prompt replacement method, device, apparatus, storage medium and program product
CN120258007A (en)*2025-02-262025-07-04北京轻网科技股份有限公司 A Web multi-language translation method and device based on AST analysis

Cited By (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN119829061A (en)*2024-11-262025-04-15金蝶软件(中国)有限公司Prompt replacement method, device, apparatus, storage medium and program product
CN120258007A (en)*2025-02-262025-07-04北京轻网科技股份有限公司 A Web multi-language translation method and device based on AST analysis

Similar Documents

PublicationPublication DateTitle
CN113139390B (en) A language conversion method and device for code string
CN111831384B (en)Language switching method, device, equipment and storage medium
CN112015430B (en)JavaScript code translation method, device, computer equipment and storage medium
CN117234507A (en)Code processing method, device, equipment and readable storage medium
CN110502520B (en)Method, system and equipment for data warehousing and computer readable storage medium
WO2021017735A1 (en)Smart contract formal verification method, electronic apparatus and storage medium
CN100550020C (en)A kind of method and apparatus that is used to solve the Chinese software issue of supporting multilanguage
CN111736840A (en)Compiling method and running method of applet, storage medium and electronic equipment
CN113076167A (en)Code processing method and related equipment
CN101667118A (en)Method and device for multi-language version development and replacement
CN110347416B (en)Script updating method and device
CN111079408A (en)Language identification method, device, equipment and storage medium
CN113835714B (en) Application language conversion method, device, computer equipment and storage medium
US10545743B2 (en)Enhanced programming language source code conversion with implicit temporary object emulation
CN117193781B (en) A method and device for constructing an abstract syntax tree for SIMSCRIPT language
CN104536769A (en)International file achieving method
CN116521621A (en)Data processing method and device, electronic equipment and storage medium
CN112486623A (en)Development method, system and electronic equipment for automatically supporting multiple languages based on interface
CN110377371B (en)Style sheet system management method based on Web tag
CN115687399A (en) A syntax analysis method and device for SQL statements
CN111443979B (en)Document processing method, device, computer equipment and storage medium
JP2005332146A (en) Dynamic content creation program generation device, program for generating dynamic content creation program, and dynamic content creation program generation method
CN113961238A (en)Object conversion method and device, electronic equipment and storage medium
CN103440231A (en)Equipment and method for comparing texts
CN117289949A (en)Code conversion method, device, computer equipment and storage medium

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination

[8]ページ先頭

©2009-2025 Movatter.jp