Method and device for displaying text in a page, storage medium, and electronic device

By judging the language in computer products and loading dictionary files in real time, the problems of slow page loading speed and difficulty in development and maintenance are solved, and the effect of rapid display and simplified maintenance is achieved.

CN112988300BActive Publication Date: 2025-08-22BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110277251.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-15
Publication Date
2025-08-22
Estimated Expiration
2041-03-15

AI Technical Summary

Technical Problem

In the prior art, computer products have slow page loading speed with multilingual support, and developers have a lot of maintenance work, especially when language switching requires loading redundant content and executing translation functions.

Method used

By obtaining page loading instructions, judging that the languages ​​are the same or different, directly display the parameter name or call the translation function to obtain the text to be loaded, and use the key values ​​to load and translate the structured dictionary files in real time to reduce unnecessary dictionary file loading and translation function execution.

Benefits of technology

It improves the display speed of text in the page in the same language environment, reduces the development and maintenance workload, and improves the page loading speed and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112988300B_ABST
    Figure CN112988300B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for displaying text in a page, a storage medium, and an electronic device, and belongs to the field of computers. The method comprises: obtaining a loading instruction for a page to be displayed, wherein the page to be displayed includes at least one text loading area, the loading instruction includes a name in a first language and a parameter name corresponding to each text loading area, and the parameter name is the text to be loaded in the first language; if the first language is the same as the language of the parameter name, the corresponding parameter name is displayed in each text loading area; if the first language is different from the language of the parameter name, based on the parameter name, a preset translation function is called to obtain the text to be loaded corresponding to the first language name in each text loading area, and the obtained text to be loaded is displayed in each text loading area. The present invention solves the technical problem of slow page display speed in the related art and improves the display speed of text in the page.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a method and device for displaying text in a page, a storage medium, and an electronic device. Background Art

[0002] In related technologies, when the same computer product is launched in multiple countries around the world, in order to facilitate use by users in different countries, the user-end operation page of the computer product needs to support the languages ​​of multiple countries, so that users can switch languages ​​by clicking the language list on the page according to their needs.

[0003] Related technology uses the following scheme to switch the language of a page: a dictionary file is pre-loaded before the page is generated (the dictionary file contains multiple key-value pairs, for example: key1:confirm; key1:confirm). When the user chooses to switch to the target language, each text display area on the page can call the translation function trans(key). When the translation function is called, it reads the text of the target language of the area from the dictionary file according to the translation function input parameter key corresponding to the area, and displays the obtained text on the page. For example: the parameter corresponding to a certain text display area is key1. When the target language is Chinese, the text obtained after trans(key1) is executed is "confirm". When the target language is English, the text obtained after trans(key1) is executed is "confirm". Since the input parameter key of the translation function is a characteristic character and cannot be displayed in the page in advance, no matter which language the user chooses, when the page is generated, the translation function needs to use the key to query the text to be displayed from the dictionary file and then load it into the page. This process takes a long time, the page loading speed is slow, and the user experience is poor. In addition, developers create a dictionary file for each business line's page. As products evolve, some content in this dictionary file is no longer used by the product, but this redundant content still needs to be loaded each time the dictionary file is loaded. Because the key is a characteristic character in the code file, updating a term on a page requires resetting the translation function and manually maintaining the dictionary key, which is a heavy workload for developers.

[0004] Currently, no effective solutions have been found for the above-mentioned problems existing in the related technologies. Summary of the Invention

[0005] Embodiments of the present invention provide a method and device for displaying text in a page, a storage medium, and an electronic device.

[0006] According to one aspect of an embodiment of the present application, a method for displaying text in a page is provided, comprising: obtaining a loading instruction for a page to be displayed, wherein the page to be displayed includes at least one text loading area, the loading instruction includes a name in a first language and a parameter name corresponding to each of the text loading areas, the parameter name being the text to be loaded in the first language; if the first language is the same as the language of the parameter name, displaying the corresponding parameter name in each of the text loading areas; if the first language is different from the language of the parameter name, calling a preset translation function based on the parameter name to obtain the text to be loaded corresponding to each of the text loading areas and the first language name, and displaying the obtained text to be loaded in each of the text loading areas.

[0007] Furthermore, based on the parameter name, a preset translation function is called to obtain the text to be loaded corresponding to each of the text loading areas and the first language name, including: passing the parameter name corresponding to each of the text loading areas into the translation function as an input parameter; searching for the text to be loaded corresponding to each of the parameter names in a preset dictionary file; wherein the dictionary file adopts a key-value pair data structure, each of the parameter names is a key, and the text to be loaded is a Value.

[0008] Furthermore, after each text loading area displays the corresponding parameter name, the method further includes: detecting a language selection instruction in the page, wherein the language selection instruction is used to instruct to display text content in a second language in the page; calling a translation function according to the language selection instruction, and querying the Value value of the Key in a dictionary file through the translation function, wherein the Value value is the text content in the second language; and displaying the Value value in the text loading area of ​​the page.

[0009] Furthermore, querying the Value of the Key in the dictionary file through the translation function includes: loading the dictionary file from the server to the local browser in real time, wherein the page runs in the local browser; and querying the Value of the Key in the dictionary file through the translation function in the local browser.

[0010] Furthermore, loading the dictionary file from the server to the local browser in real time includes: searching for the dictionary file identifier of the dictionary file in the code file of the page, and generating the uniform resource locator URL address of the dictionary file based on the dictionary file identifier; searching for the dictionary file in the server based on the URL address; and loading the dictionary file to the local browser.

[0011] Furthermore, before each text loading area displays its corresponding parameter name, the method also includes: extracting a key from the code file of the page, and extracting part-of-speech information of the key from the code file of the page, wherein the parameter name includes the key; sending the key and the part-of-speech information to a server, wherein the server is used to create a dictionary file in a second language based on the key and the part-of-speech information.

[0012] Furthermore, extracting the part-of-speech information of the Key in the code file of the page includes one of the following: searching for the annotation information of the Key in the code file of the page, and obtaining the part-of-speech information of the entry from the annotation information; searching for the key-value pair parameters of the Key in the code file of the page, and obtaining the part-of-speech information of the entry from the key-value pair parameters.

[0013] Furthermore, after extracting the Key from the code file of the page and extracting the part-of-speech information of the Key from the code file of the page, the method also includes: generating a dictionary file identifier based on the reading timestamp of the Key and the part-of-speech information; writing the dictionary file identifier into the code file of the page, and sending the dictionary file identifier to the server, wherein the server is used to create a dictionary file of the second language based on the Key and the part-of-speech information.

[0014] According to another aspect of an embodiment of the present application, a device for displaying text in a page is also provided, including: an acquisition module, used to obtain a loading instruction of a page to be displayed, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name of a first language and a parameter name corresponding to each of the text loading areas, and the parameter name is the text to be loaded in the first language; a first display module, used to display the corresponding parameter name in each of the text loading areas if the first language is the same as the language of the parameter name; and a second display module, used to call a preset translation function based on the parameter name to obtain the text to be loaded corresponding to each of the text loading areas and the first language name if the first language is different from the language of the parameter name, and display the obtained text to be loaded in each of the text loading areas.

[0015] Furthermore, the second display module includes: a parameter passing unit, used to pass the parameter names corresponding to each of the text loading areas into the translation function as input parameters; a search unit, used to search for the text to be loaded corresponding to each of the parameter names in a preset dictionary file; wherein, the dictionary file adopts a key-value pair data structure, each of the parameter names is a key, and the text to be loaded is a Value.

[0016] Furthermore, the device also includes: a detection module, which is used to detect a language selection instruction in the page after the first display module displays the corresponding parameter name in each text loading area, wherein the language selection instruction is used to indicate that text content in the second language is displayed in the page; a query module, which is used to call a translation function according to the language selection instruction, and query the Value value of the Key in the dictionary file through the translation function, wherein the Value value is the text content in the second language; and a third display module, which is used to display the Value value in the text loading area of ​​the page.

[0017] Furthermore, the query module includes: a loading unit for loading the dictionary file from the server to the local browser in real time, wherein the page runs in the local browser; a query unit for querying the Value of the Key in the dictionary file through the translation function in the local browser.

[0018] Furthermore, the loading unit includes: a generating subunit, used to search for the dictionary file identifier of the dictionary file in the code file of the page, and generate the URL address of the dictionary file based on the dictionary file identifier; a searching subunit, used to search for the dictionary file in the server based on the URL address; and a loading subunit, used to load the dictionary file into the local browser.

[0019] Furthermore, the device also includes: an extraction module, used to extract the Key from the code file of the page and extract the part-of-speech information of the Key from the code file of the page before the first display module displays the corresponding parameter name in each text loading area, wherein the parameter name includes the Key; a first sending module, used to send the Key and the part-of-speech information to a server, wherein the server is used to create a dictionary file of the second language based on the Key and the part-of-speech information.

[0020] Furthermore, the extraction module includes one of the following: a first extraction unit, used to search for the annotation information of the Key in the code file of the page, and obtain the part-of-speech information of the entry from the annotation information; a second extraction unit, used to search for the key-value pair parameters of the Key in the code file of the page, and obtain the part-of-speech information of the entry from the key-value pair parameters.

[0021] Furthermore, the device also includes: a generation module, which is used to generate a dictionary file identifier based on the reading timestamp of the Key and the part-of-speech information after the extraction module extracts the Key from the code file of the page and extracts the part-of-speech information of the Key from the code file of the page; a second sending module, which is used to write the dictionary file identifier into the code file of the page and send the dictionary file identifier to the server, wherein the server is used to create a dictionary file of the second language based on the Key and the part-of-speech information.

[0022] According to another aspect of an embodiment of the present application, a storage medium is further provided, which includes a stored program, and the above steps are executed when the program is run.

[0023] According to another aspect of an embodiment of the present application, an electronic device is also provided, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; wherein: the memory is used to store computer programs; the processor is used to execute the steps in the above method by running the program stored in the memory.

[0024] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the steps in the above method.

[0025] Through the present invention, a loading instruction of a page to be displayed is obtained, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name of a first language and a parameter name corresponding to each text loading area, the parameter name is the text to be loaded in the first language, if the first language is the same as the language of the parameter name, then the corresponding parameter name is displayed in each text loading area, if the first language is different from the language of the parameter name, then based on the parameter name, a preset translation function is called to obtain the text to be loaded corresponding to the first language name in each text loading area, and the obtained text to be loaded is displayed in each text loading area, by displaying the corresponding parameter name if the first language is the same as the language of the parameter name when displaying the page, without loading a dictionary file and executing a translation function, thereby improving the display speed of text in the page in the first language, solving the technical problem of slow page display speed in the related art, and improving the display speed of text in the page. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0027] Figure 1This is a hardware structure block diagram of a server according to an embodiment of the present invention;

[0028] Figure 2 is a flow chart of a method for displaying text in a page according to an embodiment of the present invention;

[0029] Figure 3 It is a principle flow chart of an embodiment of the present invention;

[0030] Figure 4 This is an interface diagram of the background management system of an embodiment of the present invention;

[0031] Figure 5 This is a structural block diagram of a device for displaying text in a page according to an embodiment of the present invention;

[0032] Figure 6 It is a structural block diagram of an electronic device implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0033] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of this application. It should be noted that, in the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other.

[0034] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0035] Example 1

[0036] The method embodiment provided in the first embodiment of the present application can be executed on a server (such as a network server, cloud server, etc.), a computer, a mobile phone, a tablet or a similar computing device. Taking running on a server as an example, Figure 1 This is a hardware structure diagram of a server according to an embodiment of the present invention. Figure 1 As shown, the server may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data. Optionally, the server may also include a transmission device 106 and an input / output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.

[0037] The memory 104 can be used to store server programs, for example, software programs and modules of application software, such as a server program corresponding to a method for displaying text in a page in an embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the server program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0038] The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned network may include a wireless network provided by the server's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In one embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0039] In this embodiment, a method for displaying text in a page is provided. Figure 2 is a flow chart of a method for displaying text in a page according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0040] Step S202: Obtaining a loading instruction for a page to be displayed, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name in a first language and a parameter name corresponding to each text loading area, wherein the parameter name is the text to be loaded in the first language;

[0041] Optionally, the page to be displayed may further include a picture or video loading area. Correspondingly, the loading instruction is further used to request to obtain the picture or video content corresponding to the picture or video loading area.

[0042] Optionally, the name of the first language is input or selected by the user through an interactive interface, or the first language can be obtained by parsing language environment information. The language environment information of this embodiment can be obtained from the configuration language of the browser where the page is located, the configuration language of the operating system of the terminal where the page is located, the location information of the terminal (such as country, region, etc.), the account attribute information of the login account of the page (such as user name, registration address, account nationality, etc.), etc., such as determining the configuration language of the browser or operating system as the first language, and determining the official language of the location and nationality as the first language.

[0043] Step S204: If the first language is the same as the language of the parameter name, the corresponding parameter name is displayed in each text loading area;

[0044] Step S206: If the first language is different from the language of the parameter name, a preset translation function is called based on the parameter name to obtain the text to be loaded corresponding to the first language name in each text loading area, and the obtained text to be loaded is displayed in each text loading area.

[0045] The translation function in this embodiment is a key-value query function used to query the corresponding value based on the key. When the query conditions change, the value corresponding to the key may also change. The key of the translation function is edited by the entry in the first language and is the basic component of the text content. In this embodiment, the parameter name is Key, and the text to be loaded is Value. Optionally, the first language can be Chinese, English, Korean, etc.

[0046] Through the above steps, a loading instruction of a page to be displayed is obtained, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name of a first language and a parameter name corresponding to each text loading area, the parameter name is the text to be loaded in the first language, if the first language is the same as the language of the parameter name, then the corresponding parameter name is displayed in each text loading area, if the first language is different from the language of the parameter name, then based on the parameter name, a preset translation function is called to obtain the text to be loaded corresponding to the first language name in each text loading area, and the obtained text to be loaded is displayed in each text loading area. By displaying the page, if the first language is the same as the language of the parameter name, then the corresponding parameter name is displayed, there is no need to load a dictionary file and execute a translation function, thereby improving the display speed of text in the page in the first language, solving the technical problem of slow page display speed in the related art, and improving the display speed of text in the page.

[0047] In an application scenario, in response to a display instruction of a text page, the language environment information of the text page is obtained. If the universal language of the language environment information is the first language, the keyword Key of the translation function is displayed in the text page. By directly displaying the Key in the code file in a specific language environment when displaying the text page, there is no need to load the dictionary file and execute the translation function.

[0048] In one implementation of this embodiment, based on the parameter name, a preset translation function is called to obtain the text to be loaded corresponding to each text loading area and the first language name, including: passing the parameter name corresponding to each text loading area into the translation function as an input parameter; searching for the text to be loaded corresponding to each parameter name in a preset dictionary file; wherein the dictionary file adopts a key-value pair data structure, each parameter name is a key, and the text to be loaded is a value.

[0049] In some implementation scenarios of this embodiment, the language can also be switched on the page. After the keyword Key of the translation function is displayed on the page, the following is also included:

[0050] S11, detecting a language selection instruction in a web page, wherein the language selection instruction is used to instruct to display text content in a second language in the web page;

[0051] S12, calling a translation function according to the language selection instruction, and querying the Value value of the Key in the dictionary file through the translation function, wherein the Value value is the text content in the second language;

[0052] In an example based on this embodiment, querying the Value value of the Key in the dictionary file through the translation function includes: loading the dictionary file from the server to the local browser in real time, wherein the page runs in the local browser; querying the Value value of the Key in the dictionary file through the translation function in the local browser.

[0053] By loading the dictionary file in real time based on the language selection instruction, and loading the dictionary file into the local browser of the page with the language selection instruction as the trigger condition, the loading speed and display speed of the page in the first language environment can be improved, that is, the first loading speed of the page can be improved, while reducing the local cache amount of the local browser and improving the running speed of the local browser.

[0054] Optionally, loading the dictionary file from the server to the local browser in real time includes: searching for the dictionary file identifier of the dictionary file in the code file of the page, and generating a uniform resource locator (URL) address of the dictionary file based on the dictionary file identifier; searching for the dictionary file in the server based on the URL address; and loading the dictionary file to the local browser.

[0055] In one example, the URL address includes two segments, namely the dictionary file identifier and the language type, where the dictionary file identifier can be the time when the dictionary file was created, the last update time, etc., such as 20201123-English, 20201120-Korean; in another example, the URL address includes three segments, in addition to the dictionary file identifier and language type, it also includes version information, such as test version, online version, official version, etc., for example, beta / 20201123 / English, online / 20201120 / Korean, etc.

[0056] In other instances, the dictionary file can also be loaded from the server to the local client when the page is first loaded, or during the idle period of interaction between the local client and the server, thereby improving the response speed of the language selection instruction and the switching speed of the page in multiple language environments.

[0057] S13, displaying the Value in the text loading area of ​​the page.

[0058] In this embodiment, the Key and Value values ​​of the translation function are the same text content in the page, which is edited and displayed in the first language and the second language respectively. For example, if the text content is "System Configuration", the first language and the second language are Chinese and English respectively, then the Key and Value values ​​are "System Configuration" and "System Configuration" respectively.

[0059] In an implementation manner of this embodiment, before displaying the parameter names corresponding to each text loading area, it further includes:

[0060] S21, extract the Key from the code file of the page, and extract the词性 information of the Key from the code file of the page, where the parameter name includes the Key;

[0061] In an example based on this implementation manner, the method for extracting the词性 information of the Key from the code file of the page may include, but is not limited to: searching for the annotation information of the Key in the code file of the page, and obtaining the词性 information of the entry from the annotation information; searching for the key-value pair parameters of the Key in the code file of the page, and obtaining the词性 information of the entry from the key-value pair parameters.

[0062] In addition to annotating the词性 of the Key in the code file by way of annotation, the词性 can also be annotated by way of parameters. For example, $trans('确定', 'n') is confirmation, and $trans('确定', 'v') is confirm.

[0063] In another example, if the词性 information of the Key is not obtained, a default词性 can also be set to implement the automatic translation of the content in the first language corresponding to the Key in the server and the automatic creation of a dictionary file.

[0064] S22, send the Key and the词性 information to the server, where the server is used to create a dictionary file in the second language according to the Key and the词性 information.

[0065] In an implementation manner of this embodiment, after extracting the Key from the code file of the page and extracting the词性 information of the Key from the code file of the page, it further includes: generating a dictionary file identifier based on the read timestamp of the Key and the词性 information; writing the dictionary file identifier into the code file of the page, and sending the dictionary file identifier to the server, where the server is used to create a dictionary file in the second language according to the Key and the词性 information.

[0066] Since the page content needs to be updated when it is updated, such as updating "China's Future" to "The Future of the World" on 20201123, it is necessary to replace "China" with "The World" in the form of Key in the code file of the page. Each time the page is updated, the latest Key and its part-of-speech information are read, and the dictionary file identifier of the latest version of the dictionary file is created based on the read timestamp of the read operation (to be loaded later). The old version of the dictionary file is replaced based on the dictionary file identifier, and the latest dictionary file can be created in real time, and redundant old version files can be deleted. In addition to generating a dictionary file identifier by reading the timestamp, in other examples, a dictionary file identifier can also be generated based on the creation timestamp of the Key and its part-of-speech information, or the last latest edit time of the code file of the page.

[0067] After generating the dictionary file identifier, on the one hand, the dictionary file identifier is written into the code file of the page so that it can be used as a keyword to retrieve the dictionary file in the server later. On the other hand, the dictionary file identifier is sent to the server. After the server translates it into text content in the second language based on the key and part-of-speech information, it is stored in the path where the dictionary file identifier is located.

[0068] Figure 3 This is a flow chart of the principles of an embodiment of the present invention, including front-end code (code files for user display pages on the client), a database (used to implement translation between multiple languages), and a content delivery network (CDN) (used to implement communication between the server and the client). The back-end server includes the database and CDN. When each module passes parameters, the first language is Chinese as an example. The execution steps include:

[0069] Front-end engineers use the translation function $trans() when they need to display multiple languages ​​on the page. The parameter is the Chinese key. If a word has multiple parts of speech, the part of speech can be indicated in code parameters such as comments. n is a noun, v is a verb, and a is an adjective.

[0070] You can use the interface to obtain the part-of-speech list of the entry from the database and select one from the list. If the front-end engineer does not provide a part-of-speech explanation for these entries, a default part-of-speech can be automatically configured for them.

[0071] After the front-end code is completed, the build tool extracts the Chinese key and the key's part of speech from the front-end code and sends this data to the back-end server (database + CDN);

[0072] The build tool generates a dictionary file name based on the timestamp, writes the dictionary file name into the built front-end code, and sends the dictionary file name to the back-end server;

[0073] The database creates a second language dictionary file based on the received Chinese key, the key's part of speech, and the dictionary file name, and uploads the dictionary file to the CDN server. After the page is loaded in the browser, the front-end code can retrieve the dictionary file based on the dictionary file name, language type (second language), version (test version, online version), etc.

[0074] If the current language type is Chinese, the translation function will directly output the Chinese key; if the current language type is a foreign language, the translation function will query the dictionary file based on the Chinese key and output the translated content;

[0075] In other implementation scenarios, the server also sets up a backend management system for configuring databases, dictionary files, etc. through human-computer interaction instructions, and realizing operations such as retrieval, creation, editing, deletion, and online of entries and dictionary files. New entries support a combination of online translation and manual translation. Figure 4 This is an interface diagram of the background management system of an embodiment of the present invention.

[0076] The solution of this embodiment uses the default first language such as Chinese as the key of the translation function. If it is the language environment of the first language, the key is directly displayed. If it is another language environment, the dictionary is checked. Since most users are Chinese users, the speed of page display can be improved, and the speed of page display in the first language environment is improved. When the page is constructed, all the keys that need to be translated in the page are extracted, and a dictionary file is created based on these keys. The dictionary file is created based on the entries actually used in the page. The dictionary file is small and loads quickly, which reduces the size of the dictionary file and speeds up the page loading speed. By calling the function to automatically add new keys to the dictionary data, there is no need to manually maintain the keys in the code file.

[0077] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0078] Example 2

[0079] In this embodiment, a device for displaying text in a page is also provided to implement the above-mentioned embodiments and preferred embodiments. Details that have been described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0080] Figure 5 is a structural block diagram of a device for displaying text in a page according to an embodiment of the present invention. Figure 5 As shown, the device includes: an acquisition module 50, a first display module 52, and a second display module 54, wherein:

[0081] an acquisition module 50 configured to acquire a loading instruction for a page to be displayed, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name in a first language and a parameter name corresponding to each text loading area, wherein the parameter name is the text to be loaded in the first language;

[0082] A first display module 52 is configured to display the corresponding parameter name in each text loading area if the first language is the same as the language of the parameter name;

[0083] The second display module 54 is used to call a preset translation function based on the parameter name to obtain the text to be loaded corresponding to each text loading area and the first language name if the first language is different from the language of the parameter name, and display the obtained text to be loaded in each text loading area.

[0084] Optionally, the second display module includes: a parameter passing unit, used to pass the parameter names corresponding to each of the text loading areas into the translation function as input parameters; a search unit, used to search for the text to be loaded corresponding to each of the parameter names in a preset dictionary file; wherein the dictionary file adopts a key-value pair data structure, each of the parameter names is a key, and the text to be loaded is a Value.

[0085] Optionally, the device further includes: a detection module, configured to detect a language selection instruction in the page after the first display module displays the corresponding parameter name in each text loading area, wherein the language selection instruction is used to indicate that text content in a second language is displayed in the page; a query module, configured to call a translation function according to the language selection instruction, and query the Value value of the Key in a dictionary file through the translation function, wherein the Value value is text content in the second language; and a third display module, configured to display the Value value in the text loading area of ​​the page.

[0086] Optionally, the query module includes: a loading unit, used to load the dictionary file from the server to the local browser in real time, wherein the page runs in the local browser; a query unit, used to query the Value of the Key in the dictionary file through the translation function in the local browser.

[0087] Optionally, the loading unit includes: a generating subunit, used to search for the dictionary file identifier of the dictionary file in the code file of the page, and generate the URL address of the dictionary file based on the dictionary file identifier; a searching subunit, used to search for the dictionary file in the server based on the URL address; and a loading subunit, used to load the dictionary file into the local browser.

[0088] Optionally, the device also includes: an extraction module, used to extract the Key from the code file of the page and extract the part-of-speech information of the Key from the code file of the page before the first display module displays the corresponding parameter name in each text loading area, wherein the parameter name includes the Key; a first sending module, used to send the Key and the part-of-speech information to a server, wherein the server is used to create a dictionary file of the second language based on the Key and the part-of-speech information.

[0089] Optionally, the extraction module includes one of the following: a first extraction unit, used to search for annotation information of the Key in the code file of the page, and obtain the part-of-speech information of the entry from the annotation information; a second extraction unit, used to search for key-value pair parameters of the Key in the code file of the page, and obtain the part-of-speech information of the entry from the key-value pair parameters.

[0090] Optionally, the device further includes: a generation module, configured to generate a dictionary file identifier based on a reading timestamp of the Key and the part-of-speech information after the extraction module extracts the Key from the code file of the page and extracts the part-of-speech information of the Key from the code file of the page; a second sending module, configured to write the dictionary file identifier into the code file of the page and send the dictionary file identifier to the server, wherein the server is configured to create a dictionary file of the second language based on the Key and the part-of-speech information.

[0091] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0092] Example 3

[0093] An embodiment of the present invention further provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.

[0094] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:

[0095] S1, obtaining a loading instruction for a page to be displayed, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name in a first language and a parameter name corresponding to each text loading area, wherein the parameter name is the text to be loaded in the first language;

[0096] S2, if the first language is the same as the language of the parameter name, displaying the corresponding parameter name in each text loading area;

[0097] S3: If the first language is different from the language of the parameter name, based on the parameter name, a preset translation function is called to obtain the text to be loaded corresponding to each text loading area and the first language name, and the obtained text to be loaded is displayed in each text loading area.

[0098] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.

[0099] An embodiment of the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0100] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0101] Optionally, in this embodiment, the processor may be configured to execute the following steps through a computer program:

[0102] S1, obtaining a loading instruction for a page to be displayed, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name in a first language and a parameter name corresponding to each text loading area, wherein the parameter name is the text to be loaded in the first language;

[0103] S2, if the first language is the same as the language of the parameter name, displaying the corresponding parameter name in each text loading area;

[0104] S3: If the first language is different from the language of the parameter name, based on the parameter name, a preset translation function is called to obtain the text to be loaded corresponding to each text loading area and the first language name, and the obtained text to be loaded is displayed in each text loading area.

[0105] Optionally, specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0106] Figure 6 is a structural diagram of an electronic device according to an embodiment of the present invention, such as Figure 6 As shown, it includes a processor 61, a communication interface 62, a memory 63 and a communication bus 64, wherein the processor 61, the communication interface 62, and the memory 63 communicate with each other through the communication bus 64, the memory 63 is used to store computer programs; the processor 61 is used to execute the programs stored in the memory 63.

[0107] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0108] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0109] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0110] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0111] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0112] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0113] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for displaying text in a page, characterized in that: include: Obtaining a loading instruction for a page to be displayed, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name in a first language and a parameter name corresponding to each of the text loading areas, wherein the parameter name is the text to be loaded in the first language; If the first language is the same as the language of the parameter name, the corresponding parameter name is displayed in each text loading area; If the first language is different from the language of the parameter name, calling a preset translation function based on the parameter name to obtain the text to be loaded corresponding to the first language name in each text loading area, and displaying the obtained text to be loaded in each text loading area; After the parameter names corresponding to the respective text loading areas are displayed, the method further includes: detecting a language selection instruction in the page, wherein the language selection instruction is used to instruct the display of text content in a second language in the page; calling a translation function according to the language selection instruction, and querying the Value of the Key in a dictionary file through the translation function, wherein the Value is the text content in the second language; and displaying the Value in the text loading area of ​​the page; wherein querying the Value of the Key in the dictionary file through the translation function includes: loading the dictionary file from a server to a local browser in real time, wherein the page is run in the local browser; querying the Value of the Key in the dictionary file through the translation function in the local browser; wherein loading the dictionary file from the server to the local browser in real time includes: searching for a dictionary file identifier of the dictionary file in the code file of the page, and generating a uniform resource locator URL address of the dictionary file based on the dictionary file identifier; searching for the dictionary file in the server based on the URL address; and loading the dictionary file to the local browser.

2. The method according to claim 1, wherein The step of calling a preset translation function based on the parameter name to obtain the text to be loaded corresponding to each of the text loading areas and the first language name includes: Passing the parameter names corresponding to the respective text loading areas into the translation function as input parameters; Search for the text to be loaded corresponding to each parameter name in a preset dictionary file; wherein the dictionary file adopts a key-value pair data structure, each parameter name is a key, and the text to be loaded is a Value.

3. The method according to claim 1, wherein Before each text loading area displays the corresponding parameter name, the method further includes: Extracting a key from the code file of the page, and extracting part-of-speech information of the key from the code file of the page, wherein the parameter name includes the key; The Key and the part-of-speech information are sent to a server, wherein the server is configured to create a dictionary file in a second language according to the Key and the part-of-speech information.

4. The method according to claim 3, wherein: Extracting the part-of-speech information of the Key from the code file of the page includes one of the following: Searching for annotation information of the Key in the code file of the page, and obtaining part-of-speech information of the entry from the annotation information; Search the key-value pair parameter of the Key in the code file of the page, and obtain the part-of-speech information of the entry from the key-value pair parameter.

5. The method according to claim 3, wherein: After extracting the key from the code file of the page and extracting the part-of-speech information of the key from the code file of the page, the method further includes: Generate a dictionary file identifier based on the Key and the reading timestamp of the part-of-speech information; The dictionary file identifier is written into the code file of the page, and the dictionary file identifier is sent to the server, wherein the server is used to create a dictionary file of the second language according to the Key and the part-of-speech information.

6. A device for displaying text in a page, wherein: include: an acquisition module, configured to acquire a loading instruction for a page to be displayed, wherein the page to be displayed includes at least one text loading area, and the loading instruction includes a name in a first language and a parameter name corresponding to each of the text loading areas, wherein the parameter name is the text to be loaded in the first language; a first display module, configured to display the corresponding parameter name in each text loading area if the first language is the same as the language of the parameter name; a second display module configured to, if the first language is different from the language of the parameter name, call a preset translation function based on the parameter name to obtain the text to be loaded corresponding to the first language name in each text loading area, and display the obtained text to be loaded in each text loading area; The device further includes: a detection module configured to detect a language selection instruction in the page after the first display module displays the corresponding parameter name in each text loading area, wherein the language selection instruction is used to instruct the display of text content in the second language in the page; a query module configured to call a translation function according to the language selection instruction, and query a Value value of a Key in a dictionary file through the translation function, wherein the Value value is text content in the second language; and a third display module configured to display the Value value in the text loading area of ​​the page; The query module includes: a loading unit for loading a dictionary file from a server to a local browser in real time, wherein the page runs in the local browser; a query unit for querying the Value of the Key in the dictionary file through the translation function in the local browser; Among them, the loading unit includes: a generating subunit, used to search for the dictionary file identifier of the dictionary file in the code file of the page, and generate the URL address of the dictionary file based on the dictionary file identifier; a searching subunit, used to search for the dictionary file in the server based on the URL address; and a loading subunit, used to load the dictionary file into the local browser.

7. A storage medium, wherein: The storage medium includes a stored program, wherein the program executes the method steps of any one of claims 1 to 5 when running.

8. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, communication interface, and memory communicate with each other via a communication bus; wherein: Memory for storing computer programs; A processor, configured to execute the method steps according to any one of claims 1 to 5 by running a program stored in a memory.

9. A computer product comprising a computer program / instructions, wherein: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Information processing method and electronic device

    CN104021127A

  • Method and device for conducting webpage data translation and browser client side

    CN104462074A

  • Display page processing method, device and equipment and storage medium

    CN111857903A