Information prompting method and device

By monitoring input events and using regular rules to extract internationalized resource keys, the problem of difficult-to-know key meanings in internationalized codes is solved, and the readability and maintenance efficiency of internationalized codes are improved.

CN113361286BActive Publication Date: 2024-10-18BEIJING WODONG TIANJUN INFORMATION TECH CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202010152204.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-06
Publication Date
2024-10-18
Estimated Expiration
2040-03-06

AI Technical Summary

Technical Problem

In international software projects, the Chinese text in the code is accessed through the international resource key, making it difficult for developers or maintenance personnel to intuitively know the meaning of the key, which reduces the readability of the code and the efficiency of development and maintenance.

Method used

By listening to input events, the text selected by the user is obtained, using regular rules to extract the international resource key, and retrieving the corresponding translated text in the code editor cache or file system, and displaying it to the user, thereby improving the readability and maintenance efficiency of the code.

Benefits of technology

It improves the readability and development and maintenance efficiency of internationalized code. Through the hover prompt function, developers can quickly understand the meaning of internationalized resources, which improves development and maintenance efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113361286B_ABST
    Figure CN113361286B_ABST
Patent Text Reader

Abstract

The present invention discloses an information prompt method and device, and relates to the field of computer technology. The method comprises: after monitoring a predetermined input event, obtaining the text selected by the user through the input event; extracting the key of the internationalized resource from the text according to a regular rule; searching according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; and displaying the translation text corresponding to the key of the internationalized resource. Through the above steps, the translation text can be prompted for the internationalized code in the project, which not only improves the readability of the internationalized code, but also improves the efficiency of code development and maintenance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an information prompting method and device. Background Art

[0002] In the process of developing internationalized software projects, it is necessary to select and switch the system display text language through internationalization methods. Since all Chinese texts in the code are accessed in the form of internationalized resource keys, and the internationalized resource keys are usually unrelated to the corresponding translated text content, code developers or maintenance personnel cannot intuitively know the meaning of the key, resulting in reduced readability of the source code. In the prior art, in order to obtain the translated text content corresponding to the internationalized resource key, developers or maintenance personnel are often required to manually query in the resource file.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: the internationalized code has the problem of low readability, and the existing method of manually querying and obtaining the translated text content corresponding to the internationalized resource Key reduces the efficiency of code development and maintenance. Summary of the invention

[0004] In view of this, the present invention provides an information prompt method and device, which can prompt the translated text for the internationalized code in the project, which not only improves the readability of the internationalized code, but also improves the efficiency of code development and maintenance.

[0005] To achieve the above objective, according to one aspect of the present invention, an information prompting method is provided.

[0006] The information prompt method of the present invention includes: after monitoring a predetermined input event, obtaining the text selected by the user through the input event; extracting the key of the internationalized resource from the text according to a regular rule; searching according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; and displaying the translation text corresponding to the key of the internationalized resource.

[0007] Optionally, the method further comprises: before the step of extracting the key of the internationalized resource from the text according to the regular rule, confirming that the file type to which the text selected by the user through the input event belongs is a file type that needs to be prompted.

[0008] Optionally, searching according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource includes: searching the code editor cache according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; and when the translation text corresponding to the key of the internationalized resource cannot be retrieved from the code editor cache, searching the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource.

[0009] Optionally, the method further comprises: after retrieving the translation text corresponding to the key of the internationalized resource file from the file system, updating the translation text into the code editor cache.

[0010] Optionally, searching the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource includes: searching a pre-configured file search path according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource.

[0011] Optionally, the method further comprises: configuring at least one of the regular rule, the file type that needs to be prompted, the file search path, and the language of the translated text that needs to be prompted.

[0012] Optionally, the predetermined input event is a mouse hovering event, and the text selected by the user through the input event is the text at the mouse hovering location.

[0013] To achieve the above objective, according to another aspect of the present invention, an information prompting device is provided.

[0014] The information prompt device of the present invention comprises: an acquisition module, which is used to acquire the text selected by the user through the input event after monitoring a predetermined input event; an extraction module, which is used to extract the key of the internationalized resource from the text according to a regular rule; a retrieval module, which is used to search according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; and a display module, which is used to display the translation text corresponding to the key of the internationalized resource.

[0015] To achieve the above objective, according to another aspect of the present invention, an electronic device is provided.

[0016] The electronic device of the present invention comprises: one or more processors; and a storage device for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the information prompt method of the present invention.

[0017] To achieve the above objective, according to yet another aspect of the present invention, a computer readable medium is provided.

[0018] The computer readable medium of the present invention stores a computer program, and when the program is executed by a processor, the information prompting method of the present invention is implemented.

[0019] An embodiment of the above invention has the following advantages or beneficial effects: after listening to a predetermined input event, the text selected by the user through the input event is obtained, the key of the internationalized resource is extracted from the text according to a regular rule, and the translation text corresponding to the key of the internationalized resource is retrieved to obtain the translation text corresponding to the key of the internationalized resource, and the translation text corresponding to the key of the internationalized resource is displayed. These steps can prompt the translation text for the internationalized code in the project, which not only improves the readability of the internationalized code, but also improves the efficiency of code development and maintenance.

[0020] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0022] Figure 1 is a schematic diagram of the main flow of the information prompt method according to the first embodiment of the present invention;

[0023] Figure 2 is a schematic diagram of the main flow of the information prompt method according to the second embodiment of the present invention;

[0024] Figure 3 is a schematic diagram of main modules of an information prompting device according to a third embodiment of the present invention;

[0025] Figure 4 is a schematic diagram of main modules of an information prompting device according to a fourth embodiment of the present invention;

[0026] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0027] Figure 6 It is a schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present invention. DETAILED DESCRIPTION

[0028] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0029] It should be pointed out that the embodiments of the present invention and the features in the embodiments may be combined with each other if there is no conflict.

[0030] Before describing the embodiments of the present invention in detail, some technical terms involved in the embodiments of the present invention are first described.

[0031] Keys of internationalized resources: In an internationalized resource file, the same key name corresponds to the translated texts of different languages ​​for the same translation target.

[0032] VS Code: Microsoft officially announced the Visual Studio Code project at the Build Developer Conference on April 30, 2015: a cross-platform source code editor that runs on Mac OS X, Windows, and Linux and is designed for writing modern Web and cloud applications.

[0033] i18n: It comes from the first and last characters i and n of the English word internationalization, and 18 is the number of characters in the middle, which is the abbreviation of "internationalization".

[0034] Vue: is a progressive front-end framework for building user interfaces.

[0035] Figure 1 FIG. 1 is a schematic diagram of the main flow of the information prompt method according to the first embodiment of the present invention. Figure 1 As shown, the information prompting method of the embodiment of the present invention includes:

[0036] Step S101: after monitoring a predetermined input event, obtaining the text selected by the user through the input event.

[0037] Exemplarily, the predetermined input event is a mouse hover event, and the text selected by the user through the input event is the text at the mouse hovering position. In addition, without affecting the implementation of the present invention, the predetermined input event may also be other input events. For example, a mouse click event, and accordingly, the text selected by the user through the input event is the text at the mouse click position.

[0038] Step S102: extracting the key of the internationalized resource from the text according to regular rules.

[0039] In this step, it is possible to check whether the text selected by the user through the input event (such as the text at the mouse hovering position) is a reference to an internationalized resource according to the regular rule. If so, the key of the internationalized resource can be further extracted through the regular rule; if not, the key of the internationalized resource cannot be extracted from it. For example, through `$t.('example.test')`.match( / (\$t.\()(['"])([A-Za-z0-9_\.]+)(['"])\) / ), the matching result (also called "extraction result" or "extracted key of the internationalized resource") can be obtained as "example.test". Among them, "$t.('example.test')" is the text at the mouse hovering position, and " / (\$t.\()(['"])([A-Za-z0-9_\.]+)(['"])\) / " is a pre-configured regular rule.

[0040] Step S103: searching according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource.

[0041] In an optional example, step S103 includes: searching the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource. Further, in this optional example, in order to improve the search efficiency, the file search path can be configured in advance, and the file search path can be searched according to the key of the internationalized resource.

[0042] In another optional example, considering that the cost of frequently reading and retrieving the file system is very high, an improvement can be made by setting a code editor cache. Specifically, in this optional example, step S103 includes: searching the code editor cache according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; if the translation text corresponding to the key of the internationalized resource cannot be retrieved from the code editor cache, searching the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource.

[0043] Step S104: display the translated text corresponding to the key of the internationalized resource.

[0044] Exemplarily, in this step, if the output language is pre-configured, the translated text under the output language is displayed; if the output language is not pre-configured, the translated text under all output languages ​​is displayed. For example, assuming that the output languages ​​configured by the user are English and Indonesian, the translated text under English and the translated text under Indonesian corresponding to the key of the internationalized resource are displayed; assuming that the user does not configure the output language, the translated texts of all languages ​​corresponding to the key of the internationalized resource are displayed.

[0045] In a specific implementation, the translation text corresponding to the key of the internationalized resource can be used as the return value of the custom prompt function, and the returned information can be further modified, such as defining the returned text format, etc. In addition, in a specific implementation, the returned translation text can be displayed to the user by means of a floating prompt box, etc.

[0046] In an embodiment of the present invention, after listening to a predetermined input event, the text selected by the user through the input event is obtained, the key of the internationalized resource is extracted from the text according to a regular rule, and the key of the internationalized resource is searched to obtain the translation text corresponding to the key of the internationalized resource, and the translation text corresponding to the key of the internationalized resource is displayed. These steps can provide a prompt for the translation text for the internationalized code in the project, which not only improves the readability of the internationalized code, but also improves the efficiency of code development and maintenance.

[0047] Figure 2 FIG. 2 is a schematic diagram of the main flow of the information prompt method according to the second embodiment of the present invention. Figure 2 As shown, the information prompting method of the embodiment of the present invention includes:

[0048] Step S201: After a predetermined input event is monitored, the text selected by the user through the input event and the file type to which the text belongs are obtained.

[0049] In an optional example, the predetermined input event is a mouse hover event, and the text selected by the user through the input event is the text at the mouse hovering position. In this optional example, in addition to obtaining the text at the mouse hovering position, information such as the file type to which the text belongs is also obtained.

[0050] Furthermore, taking the code editor VS Code as an example, the text at the mouse hovering point and the file type to which the text belongs can be obtained through the following optional implementation method: the hover prompt callback function provided by VS Code will return document and position as parameters to the user. The user can obtain the current file name and the text content in the current file from the document parameter, and obtain the position information of the mouse hovering point from the position parameter. Then, the code text at the current mouse hovering point can be obtained through the document.getWordRangeAtPosition(position) method; the file type to which the code text belongs is determined by the current file name.

[0051] Step S202: Determine whether the file type to which the text belongs is a file type that needs to be prompted.

[0052] In this step, the file type to which the text belongs obtained in step S201 can be compared with the pre-configured file type that needs to be prompted. If the file type to which the text belongs belongs to the file type that needs to be prompted, step S203 can be performed next; if the file type to which the text belongs does not belong to the file type that needs to be prompted, step S209 can be performed next.

[0053] Step S203: extracting the key of the internationalized resource from the text according to regular rules.

[0054] In this step, it is possible to check whether the text selected by the user through the input event (such as the text at the mouse hovering position) is a reference to an internationalized resource according to the regular rule. If so, the key of the internationalized resource can be further extracted through the regular rule; if not, the key of the internationalized resource cannot be extracted from it. For example, through `$t.('example.test')`.match( / (\$t.\()(['"])([A-Za-z0-9_\.]+)(['"])\) / ), the matching result (also called "extraction result" or "extracted key of the internationalized resource") can be obtained as "example.test". Among them, "$t.('example.test')" is the text at the mouse hovering position, and " / (\$t.\()(['"])([A-Za-z0-9_\.]+)(['"])\) / " is a pre-configured regular rule.

[0055] Step S204: Determine whether the key of the internationalized resource is extracted.

[0056] In the case where the key of the internationalized resource is extracted according to the regular rule, step S205 may be performed next; in the case where the key of the internationalized resource is not extracted according to the regular rule, step S209 may be performed next.

[0057] Step S205: Search the code editor cache according to the key of the internationalized resource.

[0058] In the embodiment of the present invention, considering that the cost of frequently reading and searching the file system is very high, an improvement can be made by setting an editor cache. Specifically, space can be applied in the cache of the code editor to store the retrieved internationalized resource content.

[0059] In specific implementation, in order to ensure the consistency of the retrieval method from the code editor cache and the file system, the internationalized resources stored in the code editor cache must be stored in the storage format of the internationalized resources in the file system. For example, if the internationalized resources in the file system are stored in the form of Key:Value object key-value pairs, then the internationalized resources in the code editor cache are also stored in the form of Key:Value object key-value pairs; if the internationalized resources in the file system are stored in the form of Key=Value assignment, then the internationalized resources in the code editor cache are also stored in the form of Key=Value assignment.

[0060] When the translation text corresponding to the key of the internationalized resource is obtained from the code editor cache, step S208 is executed; when the translation text corresponding to the key of the internationalized resource is not obtained from the code editor cache, step S206 is executed.

[0061] Step S206: Search the file system according to the key of the internationalized resource.

[0062] In order to further improve the search efficiency, a file search path may be configured in advance, and in this step, the file search path may be searched according to the key of the internationalized resource.

[0063] In the development of internationalized projects, different internationalized plug-ins are used in different language environments, and there are differences in the writing of internationalized resources, which leads to different storage methods of internationalized resources in the file system. For example, in the file system, the internationalized resources may be stored in the form of Key:Value object key-value pairs, or in the form of Key=Value assignment. Different storage methods need to be used for retrieval.

[0064] Exemplarily, when the internationalized resources in the file system are stored in the form of Key:Value object key-value pairs, step S206 may specifically include: searching a pre-configured file search path to match the corresponding internationalized resource file, and then directly introducing the internationalized resource file as an object into the custom prompt function, and converting the string into an object through the eval method to obtain the translation text corresponding to the key (Key) of the internationalized resource.

[0065] Exemplarily, when the internationalized resources in the file system are stored in the form of Key=Value assignment, step S206 may specifically include: searching the pre-configured file search path to match the corresponding internationalized resource file, accessing the content in the resource file and parsing it, storing the parsed translation text corresponding to the key of the internationalized resource in an object, then introducing the object into the custom prompt function, and converting the string into the form of an object through the eval method to obtain the translation text corresponding to the key (Key) of the internationalized resource. In specific implementation, when parsing the content, the content of each line can be distinguished according to "\n" (line break), when "#" (comment symbol) is matched in a line of text, the line is used as a comment line, the parsing of the line is skipped, and then the next line of content is parsed. During the parsing process, the current line key value (Value) can be obtained by splitting the string with an equal sign. If there is a cross-line value, the line key value needs to be spliced ​​after the previous line key value. After the parsing is completed, the value can be stored in the object and exported.

[0066] When the translation text corresponding to the key of the internationalized resource is obtained from the file system, step S207 and step S208 may be executed next; when the translation text corresponding to the key of the internationalized resource is not obtained from the file system, step S209 may be executed next.

[0067] Step S207: Update the translated text corresponding to the key of the internationalized resource into the code editor cache.

[0068] After retrieving the translation text corresponding to the key of the internationalized resource through the file system, the translation text can be updated to the code editor cache, so that the next time you need to search based on the same internationalized resource key, you can directly get the corresponding translation text from the cache, thereby improving retrieval efficiency.

[0069] Step S208: Display the translated text corresponding to the key of the internationalized resource.

[0070] Exemplarily, in this step, if the output language is pre-configured, the translated text under the output language is displayed; if the output language is not pre-configured, the translated text under all output languages ​​is displayed. For example, assuming that the output languages ​​configured by the user are English and Indonesian, the translated text under English and the translated text under Indonesian corresponding to the key of the internationalized resource are displayed; assuming that the user does not configure the output language, the translated texts of all languages ​​corresponding to the key of the internationalized resource are displayed.

[0071] In a specific implementation, the translation text corresponding to the key of the internationalized resource can be used as the return value of the custom prompt function, and the returned information can be further modified, such as defining the returned text format, etc. In addition, in a specific implementation, the returned translation text can be displayed to the user by means of a floating prompt box, etc.

[0072] Furthermore, the method of the embodiment of the present invention further includes the following steps: configuring at least one of the regular rule, the file type that needs to be prompted, the file search path, and the language of the translation text that needs to be prompted.

[0073] In specific implementation, when configuring the file search path for internationalized resources, the user can configure a folder or a specific file. When the configured file search path points to a folder, all files in the folder (such as .js and .property files) will be searched during the search; when the configured file search path points to a specific file in a folder, only the specific file in the folder will be searched during the search.

[0074] In specific implementation, when configuring regular rules, users need to configure different regular rules, taking into account that different front-end frameworks or different internationalization methods will lead to different reference methods of internationalized resources in the code. For example, when using i18n in Vue for internationalized project development, the code uses the internationalization method $t.() to reference internationalized resources in the page. At this time, users can configure regular rules that meet the $t.() structure, such as configuring the regular rule " / (\$t.\()(['"])([A-Za-z0-9_\.])+(['"])\) / " to determine whether the text selected by the user through the input event is the reference to the internationalized resource; for example, when using the vt instruction in the html tag to reference internationalized resources, users can configure the following regular rule " / (vt=")([A-Za-z0-9_\.])+" / " to determine whether the text selected by the user through the input event is the reference to the internationalized resource.

[0075] Step S209, end.

[0076] In the embodiment of the present invention, the above steps realize the hover prompt function of internationalized resources, so that the user can see the translation text corresponding to the key of the internationalized resource displayed in the form of a floating prompt box by hovering the mouse during code development or maintenance, which not only improves the readability of the internationalized code, but also helps to improve the development and maintenance efficiency of internationalized projects. In addition, by realizing the configurable function, the developer can flexibly configure the translation text prompt function to realize personalized prompts for internationalized resources of different code editors, different development frameworks, and different internationalization methods.

[0077] Figure 3 Schematic diagram of the main modules of the information prompting device according to the third embodiment of the present invention. Figure 3 As shown, the information prompting device 300 of the embodiment of the present invention includes: an acquisition module 301 , an extraction module 302 , a retrieval module 303 , and a display module 304 .

[0078] The acquisition module 301 is used to acquire the text selected by the user through the input event after monitoring the predetermined input event.

[0079] Exemplarily, the predetermined input event is a mouse hover event, and the text selected by the user through the input event is the text at the mouse hovering position. In addition, without affecting the implementation of the present invention, the predetermined input event may also be other input events. For example, a mouse click event, and accordingly, the text selected by the user through the input event is the text at the mouse click position.

[0080] The extraction module 302 is used to extract the key of the internationalized resource from the text according to regular rules.

[0081] Specifically, the extraction module 302 can verify whether the text selected by the user through the input event (such as the text at the mouse hovering position) is a reference to an internationalized resource according to a pre-configured regular rule. If so, the extraction module 302 can further extract the key of the internationalized resource through the regular rule; if not, the key of the internationalized resource cannot be extracted from it. For example, through `$t.('example.test')`.match( / (\$t.\()(['"])([A-Za-z0-9_\.]+)(['"])\) / ), the matching result (also referred to as "extraction result" or "extracted key of the internationalized resource") can be obtained as "example.test". Among them, "$t.('example.test')" is the text at the mouse hovering position, and " / (\$t.\()(['"])([A-Za-z0-9_\.]+)(['"])\) / " is a pre-configured regular rule.

[0082] The search module 303 is used to search according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource.

[0083] In an optional example, the retrieval module 303 searches the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource. Further, in this optional example, in order to improve the retrieval efficiency, the file retrieval path can be configured in advance, and then the retrieval module 303 can search the file retrieval path according to the key of the internationalized resource.

[0084] In another optional example, considering that the cost of frequently reading and retrieving the file system is very high, an improvement can be made by setting a code editor cache. Specifically, in this optional example, the retrieval module 303 searches the code editor cache according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; when the translation text corresponding to the key of the internationalized resource cannot be retrieved from the code editor cache, the retrieval module 303 searches the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource.

[0085] The display module 304 is used to display the translation text corresponding to the key of the internationalized resource.

[0086] Exemplarily, if the output language is pre-configured, the display module 304 displays the translated text in the output language; if the output language is not pre-configured, the display module 304 displays the translated text in all output languages. For example, assuming that the output languages ​​configured by the user are English and Indonesian, the display module 304 displays the translated text in English and the translated text in Indonesian corresponding to the key of the internationalized resource; assuming that the user does not configure the output language, the display module 304 displays the translated text in all languages ​​corresponding to the key of the internationalized resource.

[0087] In a specific implementation, the translation text corresponding to the key of the internationalized resource can be used as the return value of the custom prompt function, and the returned information can be further modified, such as defining the returned text format, etc. In addition, in a specific implementation, the returned translation text can be displayed to the user by means of a floating prompt box, etc.

[0088] In an embodiment of the present invention, after monitoring a predetermined input event, an acquisition module acquires the text selected by the user through the input event, an extraction module extracts the key of the internationalized resource from the text according to a regular rule, a retrieval module performs retrieval according to the key of the internationalized resource, and a display module displays the translated text corresponding to the key of the internationalized resource. This can provide a prompt for the translated text for the internationalized code in the project, thereby improving not only the readability of the internationalized code but also the efficiency of code development and maintenance.

[0089] Figure 4 Schematic diagram of the main modules of the information prompting device according to the fourth embodiment of the present invention. Figure 4 As shown, the information prompting device 400 of the embodiment of the present invention includes: an acquisition module 401, a judgment module 402, an extraction module 403, a retrieval module 404, an update module 405, and a display module 406.

[0090] The acquisition module 401 is used to acquire the text selected by the user through the input event and the file type to which the text belongs after monitoring a predetermined input event.

[0091] In an optional example, the predetermined input event is a mouse hover event, and the text selected by the user through the input event is the text at the mouse hovering position. In this optional example, in addition to obtaining the text at the mouse hovering position, information such as the file type to which the text belongs is also obtained.

[0092] Furthermore, taking the code editor VS Code as an example, the text at the mouse hovering point and the file type to which the text belongs can be obtained through the following optional implementation method: the hover prompt callback function provided by VS Code will return document and position as parameters to the user. The user can obtain the current file name and the text content in the current file from the document parameter, and obtain the position information of the mouse hovering point from the position parameter. Then, the code text at the current mouse hovering point can be obtained through the document.getWordRangeAtPosition(position) method; the file type to which the code text belongs is determined by the current file name.

[0093] The judgment module 402 is used to judge whether the file type to which the text belongs is a file type that needs to be prompted.

[0094] Specifically, the judgment module 402 can compare the file type to which the text obtained by the acquisition module 401 belongs with the pre-configured file type that needs to be prompted. If the judgment module 402 determines that the file type to which the text belongs belongs to a file type that needs to be prompted, the extraction module 403 can be called; if the judgment module 402 determines that the file type to which the text belongs does not belong to a file type that needs to be prompted, the process can be ended.

[0095] The extraction module 403 is used to extract the key of the internationalized resource from the text according to regular rules.

[0096] Specifically, the extraction module 403 can verify whether the text selected by the user through the input event (such as the text at the mouse hovering position) is a reference to an internationalized resource according to the regular rule. If so, the extraction module 403 can further extract the key of the internationalized resource through the regular rule; if not, the extraction module 403 cannot extract the key of the internationalized resource from it. For example, through `$t.('example.test')`.match( / (\$t.\()(['"])([A-Za-z0-9_\.]+)(['"])\) / ), the matching result (also referred to as "extraction result" or "extracted key of the internationalized resource") can be obtained as "example.test". Among them, "$t.('example.test')" is the text at the mouse hovering position, and " / (\$t.\()(['"])([A-Za-z0-9_\.]+)(['"])\) / " is a pre-configured regular rule.

[0097] The retrieval module 404 is used to search the code editor cache according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; when the translation text corresponding to the key of the internationalized resource cannot be retrieved from the code editor cache, the retrieval module 404 searches the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource. Furthermore, in order to improve the retrieval efficiency, the file retrieval path can be configured in advance. Furthermore, when searching the file system, the retrieval module 404 can search the file retrieval path according to the key of the internationalized resource.

[0098] The updating module 405 is used to update the translated text into the code editor cache after the retrieval module 404 retrieves the translated text corresponding to the key of the internationalized resource file from the file system.

[0099] In the embodiment of the present invention, by setting the updating module 405, the corresponding translation text can be directly obtained from the cache when searching according to the key of the same internationalized resource next time, thereby improving the search efficiency.

[0100] The display module 406 is used to display the translation text corresponding to the key of the internationalized resource.

[0101] Exemplarily, if the output language is pre-configured, the display module 406 displays the translated text in the output language; if the output language is not pre-configured, the display module 304 displays the translated text in all output languages. For example, assuming that the output languages ​​configured by the user are English and Indonesian, the display module 406 displays the translated text in English and the translated text in Indonesian corresponding to the key of the internationalized resource; assuming that the user does not configure the output language, the display module 406 displays the translated text in all languages ​​corresponding to the key of the internationalized resource.

[0102] In a specific implementation, the translation text corresponding to the key of the internationalized resource can be used as the return value of the custom prompt function, and the returned information can be further modified, such as defining the returned text format, etc. In addition, in a specific implementation, the returned translation text can be displayed to the user by means of a floating prompt box, etc.

[0103] Furthermore, the information prompting device of the embodiment of the present invention may also include: a configuration module for configuring at least one of the regular rule, the file type to be prompted, the file search path, and the language of the translated text to be prompted.

[0104] In the embodiment of the present invention, the above module realizes the hover prompt function of internationalized resources, so that the user can see the translation text corresponding to the key of the internationalized resource displayed in the form of a floating prompt box by hovering the mouse during code development or maintenance, which not only improves the readability of the internationalized code, but also helps to improve the development and maintenance efficiency of internationalized projects. In addition, by realizing the configurable function, the developer can flexibly configure the translation text prompt function to realize personalized prompts for internationalized resources of different code editors, different development frameworks, and different internationalization methods.

[0105] Figure 5 An exemplary system architecture 500 to which the information prompting method or information prompting device according to the embodiment of the present invention can be applied is shown.

[0106] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0107] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as code editor client applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0108] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0109] The server 505 may be a server that provides various services, such as a background management server that provides support for the code editor application or website browsed by the user using the terminal devices 501, 502, and 503. The background management server may analyze and process the received data such as the file system search request, and feed back the processing result (such as the retrieved translation text) to the terminal device.

[0110] It should be noted that the information prompting method provided in the embodiment of the present invention is generally executed by a terminal device, and accordingly, the information prompting device is generally arranged in the terminal device.

[0111] It should be understood that Figure 5 The number of terminal devices, networks and servers in the example is only for illustration. Any number of terminal devices, networks and servers may be provided as required. Figure 5 In addition to the system architecture shown, the exemplary system architecture of the information prompting method or the information prompting device according to the embodiment of the present invention may also be composed of terminal devices only.

[0112] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6 The computer system shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0113] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0114] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0115] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.

[0116] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0117] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0118] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes an acquisition module, an extraction module, a retrieval module, and a display module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the extraction module may also be described as a "module for extracting keys of internationalized resources".

[0119] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device executes the following process: after listening to a predetermined input event, obtain the text selected by the user through the input event; extract the key of the internationalized resource from the text according to the regular rule; search according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; and display the translation text corresponding to the key of the internationalized resource.

[0120] According to the technical solution of the embodiment of the present invention, it is possible to provide a prompt for translation text for the internationalized code in the project, which not only improves the readability of the internationalized code, but also improves the efficiency of code development and maintenance.

[0121] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. An information prompting method, characterized in that: Applied to a code editor, the method includes: After monitoring a predetermined input event, obtaining the text selected by the user through the input event; Extracting the key of the internationalized resource from the text according to a regular rule; Retrieving according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource, including: searching the code editor cache according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; when the translation text corresponding to the key of the internationalized resource cannot be retrieved from the code editor cache, searching the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; wherein different retrieval methods are used for retrieval of internationalized resources in different storage methods; The translated text corresponding to the key of the internationalized resource is displayed.

2. The method according to claim 1, characterized in that The method further comprises: Before the step of extracting the key of the internationalized resource from the text according to the regular rule, it is confirmed that the file type to which the text selected by the user through the input event belongs is a file type that needs to be prompted.

3. The method according to claim 1, characterized in that The method further comprises: After retrieving the translated text corresponding to the key of the internationalized resource file from the file system, the translated text is updated to the code editor cache.

4. The method according to claim 1, characterized in that: The method further comprises: At least one of the regular rule, the file type that needs to be prompted, the file search path, and the language of the translation text that needs to be prompted is configured.

5. The method according to claim 4, characterized in that The predetermined input event is a mouse hovering event, and the text selected by the user through the input event is the text at the mouse hovering position.

6. An information prompting device, characterized in that: Applied to a code editor, the device comprises: An acquisition module, used for acquiring the text selected by the user through the input event after monitoring a predetermined input event; An extraction module, used for extracting the key of the internationalized resource from the text according to a regular rule; A retrieval module, used for searching according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource, including: searching the code editor cache according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; when the translation text corresponding to the key of the internationalized resource cannot be retrieved from the code editor cache, searching the file system according to the key of the internationalized resource to obtain the translation text corresponding to the key of the internationalized resource; wherein different retrieval methods are used for retrieval of internationalized resources in different storage methods; The display module is used to display the translation text corresponding to the key of the internationalized resource.

7. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.

8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Extensible help system based on Web and realizing method thereof

    CN101655796A

  • Software system internationalization methods and apparatus

    CN102279847A

  • Internationalized code conversion method based on editor

    CN106648819A

  • Code internationalization method and device for automatically generating key values

    CN106775914A

  • Information presentation method and device

    CN107168635A