A method, device, and medium for multilingual rendering in Grafana
By configuring data key-value pair information and a UQL language plugin for Grafana, real-time language switching and accurate translation of Grafana charts were achieved, solving the problems of high maintenance costs and low translation accuracy in existing technologies and improving the user experience.
Patent Information
- Application Number
- CN202511570205.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-30
- Publication Date
- 2026-11-10
- Estimated Expiration
- 2045-10-30
AI Technical Summary
Grafana's current technology cannot dynamically switch the language of chart content. Users need to restart the service and modify the configuration file, resulting in high maintenance costs and low translation accuracy.
By configuring data key-value pair information for custom variables, including variable name, locale identifier, translated text, and query variable identifier, the system dynamically parses user request URLs to achieve real-time language rendering, utilizes the UQL language plugin to construct query paths, and replaces page text.
It enables real-time language switching and page display of chart content, reducing maintenance workload, improving translation accuracy and efficiency, and reducing the probability of errors.
Smart Images

Figure CN121433791B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a method, apparatus and medium for multilingual rendering in Grafana. Background Technology
[0002] Grafana is an open-source platform widely used for monitoring data visualization, supporting various data sources and chart types. Currently, Grafana typically defaults to English for its interface language, which is inconvenient for users in other language environments. Grafana's multilingual support primarily relies on modifying configuration files and restarting the service to load the target language pack, thereby changing the language of all UI text, including system menus and prompts.
[0003] The above only applies to multilingual support for system menus, etc. For user-defined chart titles, legend names, tooltips, etc., dynamic language display is not possible. Grafana service must be restarted after each language configuration change, and the language cannot be dynamically switched on the page based on the user's selection, which does not conform to user habits. Summary of the Invention
[0004] To address the aforementioned technical problems, this invention provides a method, device, and medium for multilingual rendering in Grafana, which can reduce maintenance costs and also enables real-time language switching and page display of charts, making it convenient for users.
[0005] According to a first aspect of the present invention, a method for multilingual rendering in Grafana is provided, comprising the following steps: For each pre-defined custom variable, corresponding data key-value pair information is configured; the custom variable refers to a variable with language environment conversion requirements; the data key-value pair information includes the variable name of the custom variable itself, several preset language environment identifiers, the text identifier associated with the variable name under each preset language environment identifier, the translation text corresponding to the preset language environment identifier itself, and the query variable identifier corresponding to the variable name.
[0006] When a user request URL is received, the query variable identifier and the corresponding variable value are obtained from the user request URL; the user request URL is a string generated based on the language environment switching command sent by the user on the current Grafana page; the variable value corresponding to the query variable identifier refers to the target language environment identifier requested by the user.
[0007] Based on the query variable identifier, the data key-value pair information corresponding to the user's requested URL is found and parsed to obtain the translated text corresponding to the target language environment identifier.
[0008] Locate the position of the custom variable on the current Grafana page, and replace the original text at the corresponding position of the custom variable with the translated text corresponding to the target locale identifier to complete the language rendering.
[0009] According to a second aspect of the invention, a non-transitory computer-readable storage medium is provided, the storage medium storing at least one instruction or at least one program segment, the at least one instruction or the at least one program segment being loaded and executed by a processor to implement the above-described method for multilingual rendering in Grafana.
[0010] According to a third aspect of the present invention, an electronic device is provided, including a processor and the aforementioned non-transitory computer-readable storage medium.
[0011] The present invention has at least the following beneficial effects: This invention provides a method for multilingual rendering in Grafana. First, for each pre-defined custom variable, corresponding data key-value pair information is configured. This data key-value pair information includes the variable name of the custom variable itself, several preset locale identifiers, a text identifier associated with the variable name under each preset locale identifier, the translated text corresponding to the preset locale identifier itself, and a query variable identifier corresponding to the variable name. Then, when a user request URL is received, the query variable identifier and the target locale identifier requested by the user are obtained from the user request URL. Based on the query variable identifier, the data key-value pair information corresponding to the user request URL is found and parsed to obtain the target locale identifier. The system identifies the target language environment identifier and its corresponding translated text. Finally, it locates the corresponding position of the custom variable on the current Grafana page and replaces the original text at that position with the translated text corresponding to the target language environment identifier to complete the language rendering. Through the above, this invention sets data key-value pairs for each custom variable. Compared to traditional multilingual template methods, this solution only requires modification of the corresponding data key-value pairs when the chart content changes, eliminating the need to modify multiple language versions of the template separately. This significantly reduces maintenance workload and the probability of errors. Furthermore, based on user-sent language environment switching commands, it can dynamically generate user request URLs, enabling real-time language switching and page display of the chart, making it convenient for users. Attached Figure Description
[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 A flowchart illustrating a method for multilingual rendering in Grafana, provided as an embodiment of the present invention. Detailed Implementation
[0014] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0015] Based on the technical deficiencies in the existing technology, this invention provides Embodiment 1, which provides a method for multilingual rendering in Grafana. When using Grafana, if it is necessary to display the content of the current page in other languages, the current page needs to be captured in the form of a snapshot, and then a translation plugin is introduced to translate it. The translated content is then replaced in the corresponding original display position to achieve rendering and display in other languages. This method only requires the introduction of a snapshot plugin and a translation plugin to achieve multilingual rendering, and the backend operation is simple. However, this method still has certain drawbacks, such as the translation not being accurate enough, especially for many application scenarios in Grafana chart panels that require the use of professional terminology. The accuracy of this rendering method needs to be improved.
[0016] Based on this, the present invention also provides a second embodiment, which provides a method for multilingual rendering in Grafana. On the Grafana server, a code template is configured for each preset language. For example, 18 languages require 18 code templates, which contain the corresponding translation content in each preset language environment. When a user needs to display the content of the current page in another language, they select the corresponding language environment identifier, find the code template corresponding to the language environment identifier, and execute it to achieve language switching of the current page. This method sets a code template containing professional translation terms for each language, which can solve the problem of multilingual rendering and solve the problem of low translation accuracy. It is suitable for application scenarios in Grafana chart panels that require the use of professional terms. However, when the terms corresponding to one language need to be added or changed, all code templates need to be updated, which is inefficient and prone to missing code templates.
[0017] Therefore, this application also provides Embodiment 3, which provides a method for multilingual rendering in Grafana, such as... Figure 1 As shown, the method includes the following steps: S100, based on each pre-defined custom variable, corresponding data key-value pair information is configured; the custom variable refers to a variable with language environment conversion requirements; the data key-value pair information includes the variable name of the custom variable itself, several preset language environment identifiers, the text identifier associated with the variable name under each preset language environment identifier, the translation text corresponding to the preset language environment identifier itself, and the query variable identifier corresponding to the variable name.
[0018] Specifically, the custom variables include, but are not limited to, at least one of the following: chart title, axis labels, and legend description.
[0019] For example, when the custom variable is the chart title, the code example for the corresponding key-value pair information is as follows: { "name": "i18n_chart_title", "uql_query_data": "i18n": { "en": {"chart_title": "Sales Data Statistics"}, "zh": {"chart_title": "Sales Data Statistics"} }, "uql":"parse | i18n.${lang}.chart_title" } The `name` field corresponds to the variable name of the custom variable itself, and is used as the identifier of the custom variable to be translated. Under `uql_query_data`, `i18n` represents the root node of the data, `en` represents the English locale identifier, `zh` represents the Chinese locale identifier, `chart_title` represents the text identifier associated with the variable name, and the corresponding value is the translated text in the corresponding locale. The `uql` field defines the UQL language query statement for parsing the data key-value pairs, and `lang` represents the query variable identifier, which is used to specify the requested locale.
[0020] As described above, by configuring data key-value pair information for custom variables, professional translation terms can be pre-set, resulting in more professional translation terms and more accurate translation results when switching language environments. Furthermore, the same data key-value pair information can be used to set translation content for several languages, solving the problem of needing to configure a separate code template for each language. This simplifies backend development and improves the efficiency and cost of backend updates and maintenance.
[0021] S200, when a user request URL is received, the query variable identifier and the variable value corresponding to the query variable identifier are obtained from the user request URL; the user request URL is a string generated based on the language environment switching command sent by the user on the current Grafana page; the variable value corresponding to the query variable identifier refers to the target language environment identifier requested by the user.
[0022] Furthermore, the step of generating a string based on the language environment switching command sent by the user on the current Grafana page includes the following steps: S201, based on the language environment switching command sent by the user on the current Grafana page, obtain the variable name of each custom variable on the current page; this can be understood as: the user sends a language environment switching command by clicking the language switching option configured on the current page.
[0023] S202, for each custom variable's corresponding data key-value pair information, obtain the query variable identifier corresponding to the variable name of each custom variable itself. For example, when the custom variable is a chart title, obtain the data key-value pair information corresponding to the chart title; when the custom variable is an axis label, obtain the data key-value pair information corresponding to the axis label. That is, the data key-value pair information corresponding to the custom variable is determined by the value of the name field in the code example above.
[0024] S203, generate the variable value corresponding to each query variable identifier according to the language environment switching instruction, and generate the corresponding string based on each query variable identifier and the variable value corresponding to each query variable identifier; this can be understood as: the user request URL includes query variable identifiers and the variable values corresponding to each query variable identifier. For example, when obtaining the user request URL, if lang=en, it means that the translation content in the English language environment needs to be displayed, and if lang=zh, it means that the translation content in the Chinese language environment needs to be displayed.
[0025] As described above, by sending a language environment switching command by the user, the language of the current page can be switched and displayed only. This achieves the purpose of dynamically obtaining language parameters and generating the string of the user's requested URL. The language can be dynamically switched at any time according to the user's needs, which is convenient for users and helps to improve the user's understanding of the chart information.
[0026] S300, based on the query variable identifier, finds the data key-value pair information corresponding to the user's requested URL and parses the data key-value pair information to obtain the translated text corresponding to the target language environment identifier.
[0027] Specifically, the data key-value pair information is data key-value pair information in JSON format.
[0028] Further, the translated text corresponding to the target language environment identifier is obtained through the following steps: S301, dynamically construct the UQL query path based on the query variable identifier and the target language environment identifier.
[0029] S302, based on the UQL query path, uses a plugin that supports the UQL language to parse the JSON format key-value pairs corresponding to the query variable identifiers, obtaining the translated text corresponding to the target language environment identifier. The plugin that supports the UQL language can be the Infinity plugin.
[0030] For example, when parsing JSON-formatted key-value pairs, a plugin supporting UQL is used. Based on the obtained variable value corresponding to `lang`, a query statement in the UQL field is executed to parse several key-value pairs in `uql_query_data`. For instance, when `lang=en`, the plugin executes the query statement, obtains the corresponding value `i18n.en.chart_title`, and thus parses the content corresponding to the `i18n_chart_title` variable as `Sales DataStatistics` in the English language environment.
[0031] As described above, different query paths can be constructed for different query variable identifiers, realizing the dynamic construction of query paths. If different custom variables exist on the current page, the corresponding translation text of the target language environment identifier can be found in the corresponding data key-value pair information through different query paths, making the chart display more complete and accurate. Moreover, by setting the query path of UQL language, it is easy to flexibly adjust the parsing logic according to different needs, which has high flexibility and scalability and can easily adapt to changes in different business and multilingual requirements.
[0032] S400 locates the position of the custom variable in the current Grafana page and replaces the original text at the corresponding position of the custom variable with the translated text corresponding to the target locale identifier to complete the language rendering.
[0033] As described above, data key-value pairs are set for each custom variable. Compared with the traditional multilingual template approach, this solution only requires modification of the corresponding data key-value pairs when the chart content changes, without the need to modify multiple language versions of the template separately. This greatly reduces maintenance workload and the probability of errors. Furthermore, based on the user's language environment switching commands sent at any time, the solution can dynamically generate user request URLs, enabling real-time language switching and page display of the chart, making it convenient for users.
[0034] In a further embodiment, the method further includes the following steps: S10, when performing language rendering on the current page of Grafana, determine whether the current display space of the translated text corresponding to the target language environment identifier is greater than the preset maximum display space of the original text at the corresponding position of the custom variable.
[0035] If S20 is not greater than, then the translated text corresponding to the target language environment identifier will be displayed at the corresponding position of the custom variable.
[0036] S30, if it is greater than, call the preset storage database, and filter the synonyms corresponding to the translated text in the preset storage database in descending order of importance, until the synonyms not greater than the corresponding preset maximum display space are obtained, and replace the translated text corresponding to the target language environment identifier for display.
[0037] Specifically, the preset storage database is configured with at least one translated text under each preset language environment identifier corresponding to each custom variable; this can be understood as: multiple translated texts are synonyms.
[0038] As described above, by comparing the display space of the translated text corresponding to the target language environment identifier with the preset maximum display space at the corresponding position, the translated text can be displayed reasonably in different situations without the need to reformat the chart, reducing development complexity and maintaining a high degree of consistency with the original chart, making it convenient for users.
[0039] Furthermore, the method also includes the following steps: S40, if the preset storage database is called and no synonymous text larger than the corresponding preset maximum display space is obtained, the font size of the translated text corresponding to the target language environment identifier is successively reduced.
[0040] S50: If the text can be fully displayed before or after being reduced to the preset font size, then the translated text with the reduced font size corresponding to the target language environment identifier will be displayed at the corresponding position of the custom variable.
[0041] S60: If the translated text corresponding to the target language environment identifier cannot be fully displayed even when the font size is reduced to the preset size, then the original display space of the current page will be automatically adjusted, and the translated text corresponding to the target language environment identifier in a reduced font size will be displayed. For example, in a Chinese environment, the CPU is the central processing unit, and its display space is much larger than that of the CPU.
[0042] As mentioned above, in cases where no synonyms for the translated text are available, the font size of the translated text is reduced. In order to maintain the viewing effect for users, the minimum font size needs to be limited. For cases where the translated text cannot be fully displayed even after being reduced to the minimum font size, the original display space is adjusted. For example, the rows or columns of charts are automatically adjusted before display, making the information layout of the current page more complete and reasonable.
[0043] Embodiments of the present invention also provide a non-transitory computer-readable storage medium that can be disposed in an electronic device to store at least one instruction or at least one program related to implementing a method in the method embodiments, wherein the at least one instruction or the at least one program is loaded and executed by the processor to implement the method for multilingual rendering of Grafana provided in the above embodiments.
[0044] Embodiments of the present invention also provide an electronic device, including a processor and the aforementioned non-transitory computer-readable storage medium.
[0045] While specific embodiments of the invention have been described in detail by way of example, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of the invention. It should also be understood that various modifications can be made to the embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.
Claims
1. A method for multilingual rendering in Grafana, characterized in that, The method includes the following steps: For each pre-defined custom variable, corresponding data key-value pair information is configured; the custom variable refers to a variable with language environment conversion requirements; the data key-value pair information includes the variable name of the custom variable itself, several preset language environment identifiers, the text identifier associated with the variable name under each preset language environment identifier, the translation text corresponding to the preset language environment identifier itself, and the query variable identifier corresponding to the variable name. When a user request URL is received, the query variable identifier and the corresponding variable value are obtained from the user request URL; the user request URL is a string generated based on the language environment switching command sent by the user on the current Grafana page; The variable value corresponding to the query variable identifier refers to the target language environment identifier requested by the user; Based on the query variable identifier, the data key-value pair information corresponding to the user's requested URL is found and parsed to obtain the translated text corresponding to the target language environment identifier; Locate the position of the custom variable in the current Grafana page, and replace the original text at the corresponding position of the custom variable with the translated text corresponding to the target locale identifier to complete the language rendering; The method further includes the following steps: when performing language rendering on the current Grafana page, determine whether the current display space of the translated text corresponding to the target locale identifier is greater than the preset maximum display space of the original text at the corresponding position of the custom variable; if it is not greater, display the translated text corresponding to the target locale identifier at the corresponding position of the custom variable; if it is greater, call the preset storage database, and sequentially filter the synonyms corresponding to the translated text in the preset storage database according to the order of importance from high to low, until a synonym is obtained that is not greater than the corresponding preset maximum display space, to replace the translated text corresponding to the target locale identifier and display it; the preset storage database is configured with at least one translated text under each preset locale identifier corresponding to each custom variable.
2. The method for multilingual rendering in Grafana according to claim 1, characterized in that, The custom variables include at least one of the following: chart title, axis labels, and legend description.
3. The method for multilingual rendering in Grafana according to claim 1, characterized in that, The process of generating a string based on the language environment switching command sent by the user on the current Grafana page includes the following steps: Based on the language environment switching command sent by the user on the current page of Grafana, obtain the variable name of each custom variable on the current page; For each custom variable, retrieve the query variable identifier corresponding to the variable name of each custom variable itself; The variable value corresponding to each query variable identifier is generated according to the language environment switching instruction, and the corresponding string is generated based on each query variable identifier and the variable value corresponding to each query variable identifier.
4. The method for multilingual rendering in Grafana according to claim 1, characterized in that, The data key-value pair information is in JSON format. The following steps are used to obtain the translated text corresponding to the target language environment identifier: The UQL query path is dynamically constructed based on the query variable identifier and the target language environment identifier; Based on the UQL query path, a plugin that supports the UQL language is used to parse the JSON format key-value pairs of data corresponding to the query variable identifiers to obtain the translated text corresponding to the target language environment identifiers.
5. The method for multilingual rendering in Grafana according to claim 1, characterized in that, The method further includes the following steps: If the preset storage database is called and no synonymous text larger than the corresponding preset maximum display space is obtained, the font size of the translated text corresponding to the target language environment identifier will be reduced one by one. If the text can be fully displayed before or after being reduced to the preset font size, then the translated text with the reduced font size corresponding to the target language environment identifier will be displayed at the corresponding position of the custom variable. If the translated text corresponding to the target language environment identifier cannot be fully displayed even when the font size is reduced to the preset size, the original display space of the current page will be automatically adjusted, and then the translated text corresponding to the target language environment identifier with a reduced font size will be displayed.
6. A non-transitory computer-readable storage medium, wherein the storage medium stores at least one instruction or at least one program segment, characterized in that, The at least one instruction or the at least one program segment is loaded and executed by the processor to implement the method for multilingual rendering in Grafana as described in any one of claims 1-5.
7. An electronic device, characterized in that, Includes a processor and the non-transitory computer-readable storage medium as described in claim 6.
Citation Information
Patent Citations
Site text translation method and device, equipment and medium
CN120430321A
