CN113760821A - File conversion method and device - Google Patents
File conversion method and device Download PDFInfo
- Publication number
- CN113760821A CN113760821A CN202010574894.0A CN202010574894A CN113760821A CN 113760821 A CN113760821 A CN 113760821A CN 202010574894 A CN202010574894 A CN 202010574894A CN 113760821 A CN113760821 A CN 113760821A
- Authority
- CN
- China
- Prior art keywords
- field
- file
- original
- translation
- determining
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000006243 chemical reaction Methods 0.000 title claims abstract description 112
- 238000000034 method Methods 0.000 title claims abstract description 42
- 238000013519 translation Methods 0.000 claims abstract description 98
- 238000000926 separation method Methods 0.000 claims description 18
- 238000004590 computer program Methods 0.000 claims description 9
- 238000010586 diagram Methods 0.000 description 12
- 230000008569 process Effects 0.000 description 9
- 238000004891 communication Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 6
- 238000012545 processing Methods 0.000 description 5
- 230000003287 optical effect Effects 0.000 description 4
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 238000012360 testing method Methods 0.000 description 3
- 230000008901 benefit Effects 0.000 description 2
- 239000000835 fiber Substances 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 238000010276 construction Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000018109 developmental process Effects 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000001914 filtration Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000013507 mapping Methods 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 238000007639 printing Methods 0.000 description 1
- 230000011218 segmentation Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/11—File system administration, e.g. details of archiving or snapshots
- G06F16/116—Details of conversion of file system types or formats
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/12—Use of codes for handling textual entities
- G06F40/151—Transformation
- G06F40/157—Transformation using dictionaries or tables
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/40—Processing or translation of natural language
- G06F40/42—Data-driven translation
- G06F40/47—Machine-assisted translation, e.g. using translation memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/451—Execution arrangements for user interfaces
- G06F9/454—Multi-language systems; Localisation; Internationalisation
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Artificial Intelligence (AREA)
- Human Computer Interaction (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Machine Translation (AREA)
Abstract
The invention discloses a file conversion method and device, and relates to the technical field of computers. One embodiment of the method comprises: determining at least one text file; according to a configuration file, determining a target text file with the same type as the file to be converted from the at least one text file, and searching an identifier representing a comment and/or a characteristic field for displaying plaintext information from the target text file; wherein the configuration file comprises: a file type to be converted and one or both of the following: the identifier representing the annotation and the characteristic field for presenting plaintext information; determining an original field indicated by the searched identifier and/or the characteristic field, and determining a translation field corresponding to the original field; replacing an original field in the target text file with the translated field to convert the target text file. The file conversion efficiency is improved by the file conversion method.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for file conversion.
Background
With the development of computer technology, Application scenarios of websites and applications (apps) are increasing, and different interfaces and resources need to be provided for different Application scenarios, for example, a chinese interface needs to be provided in an in-app Application scenario of an app, and interfaces in other languages (such as english) need to be provided in an out-app Application scenario. Therefore, for different application scenarios, corresponding conversion needs to be performed on files corresponding to the website and the application.
At present, a file is usually converted in a manual manner, specifically, the file needs to be retrieved in a file system in a manual manner, the file needs to be converted is searched, each line in the file is checked one by one to search fields needing to be converted, and the searched fields are converted into target fields corresponding to an application scene one by one to enable the converted file to adapt to a current application scene.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
the efficiency of converting files in a manual mode is low, and when fields are converted in a manual mode, the error rate is high, and errors in interface layout after file conversion can be caused.
Disclosure of Invention
In view of this, embodiments of the present invention provide a file conversion method and device, which can improve file conversion efficiency and avoid field conversion errors in a file, thereby avoiding interface layout errors caused by file conversion.
To achieve the above object, according to an aspect of an embodiment of the present invention, a method of file conversion is provided.
The file conversion method of the embodiment of the invention comprises the following steps:
determining at least one text file;
according to a configuration file, determining a target text file with the same type as the file to be converted from the at least one text file, and searching an identifier representing a comment and/or a characteristic field for displaying plaintext information from the target text file; wherein the configuration file comprises: a file type to be converted and one or both of the following: the identifier representing the annotation and the characteristic field for presenting plaintext information;
determining an original field indicated by the searched identifier and/or the characteristic field, and determining a translation field corresponding to the original field;
replacing an original field in the target text file with the translated field to convert the target text file.
Optionally, the determining a translation field corresponding to the original field includes:
and determining a translation field corresponding to the original field by using a local translation corresponding table, wherein the translation corresponding table correspondingly records translation fields corresponding to a plurality of fields respectively.
Optionally, when there are a plurality of original fields, the determining a translation field corresponding to the original field includes:
determining original fields different from each other from the searched original fields;
generating a conversion dictionary for the mutually different original fields; the conversion dictionary includes: the different original fields and the different original fields respectively correspond to translation fields and default values; and determining a translation field corresponding to the original field according to the conversion dictionary.
Optionally, the method further comprises:
and storing the conversion dictionary to call the conversion dictionary according to a storage path.
Optionally, the determining a translation field corresponding to the original field includes:
and determining a translation field corresponding to the original field by using an online translation plug-in.
Optionally, the configuration file further includes: the identifier corresponds to a separator and a separation strategy; the determining the original field indicated by the located identifier includes:
and determining the line data corresponding to the identifier and/or the characteristic field, and separating the line data according to the separator and a separation strategy to obtain the original field.
Optionally, the translation field includes: an internationalized field; the configuration file further comprises: a replacement prefix and a replacement suffix; replacing an original field in the target text file with the translated field, comprising:
replacing an original field in the target text file with the replacement prefix, the internationalized field, and the replacement suffix.
Optionally, the replacing the field to be converted in the text file with the internationalized field includes:
marking the position of the original field in the target text file, and adding a conversion identifier corresponding to the translation field at the position;
and replacing the original field with the translation field according to the conversion identifier.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided an apparatus for file conversion.
The file conversion device of the embodiment of the invention comprises: the system comprises a file determining module, a first determining module, a second determining module and a replacing module; wherein,
the file determining module is used for determining at least one text file;
the first determining module is used for determining a target text file with the same type as the file to be converted from the at least one text file according to the configuration file, and searching an identifier representing a comment and/or a characteristic field for displaying plaintext information from the target text file; wherein the configuration file comprises: a file type to be converted and one or both of the following: the identifier representing the annotation and the characteristic field for presenting plaintext information;
the second determining module is configured to determine an original field indicated by the found identifier and/or the feature field, and determine a translation field corresponding to the original field;
the replacing module is used for replacing the original field in the target text by the translation field so as to convert the target text file.
Optionally, the second determining module is configured to determine the translation field corresponding to the original field by using a local translation correspondence table or an online translation plug-in.
Optionally, the second determining module is configured to determine different original fields from the plurality of original fields, and generate a conversion dictionary for the different original fields; the conversion dictionary includes: the different original fields and the different original fields respectively correspond to translation fields and default values; and determining a translation field corresponding to the original field according to the conversion dictionary.
To achieve the above object, according to still another aspect of the embodiments of the present invention, there is provided an electronic device for file conversion.
An electronic device for file conversion according to an embodiment of the present invention includes: one or more processors; a storage device, configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement a method for file conversion according to an embodiment of the present invention.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a computer-readable storage medium.
A computer-readable storage medium of an embodiment of the present invention stores thereon a computer program that, when executed by a processor, implements a method of file conversion of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: the method comprises the steps of configuring a file type to be converted, an identifier for identifying a comment and a characteristic field for displaying plaintext information in advance through a configuration file, after the text file is obtained, calling the configuration file to determine a target text file with the same file type as the file type to be converted, searching the identifier for representing the comment and the characteristic field for displaying the plaintext information from the target text file to determine an original field to be converted, then determining a translation field corresponding to the original field, and replacing the original field with the translation field, so that automatic conversion of the target text file is realized, the file conversion efficiency is improved, errors are avoided when the field is replaced, and interface layout errors caused by file conversion are avoided.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of a method of file conversion according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of the main steps of another method of file conversion according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the main modules of an apparatus for document conversion according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that the embodiments of the present invention and the technical features of the embodiments may be combined with each other without conflict.
Fig. 1 is a schematic diagram of main steps of a file conversion method according to an embodiment of the present invention.
As shown in fig. 1, a method for file conversion according to an embodiment of the present invention mainly includes the following steps:
step S101: at least one text file is determined.
Step S102: according to a configuration file, determining a target text file with the same type as the file to be converted from the at least one text file, and searching an identifier representing a comment and/or a characteristic field for displaying plaintext information from the target text file; wherein the configuration file comprises: a file type to be converted and one or both of the following: the identifier representing the annotation and the characteristic field for presenting the plaintext information.
In the embodiment of the present invention, the file type to be converted may be configured in the configuration file in advance through the name attribute, for example, by writing different file extensions in the configuration file, for example, the file type corresponding to each file extension shown in table 1 below is used as the file type to be converted, so as to configure the file type to be converted.
TABLE 1
Also, identifiers representing annotations, such as "/" or "/" etc., may also be configured in the configuration file. In addition, a feature field for displaying the plaintext information may also be configured in the configuration file, for example, when the file type to be converted corresponds to an html file, the feature field for displaying the plaintext information may be a print, a printf, a println in JAVA, or a printjs in javascript, and the like. It should be noted that displaying the plaintext information may mean displaying the plaintext information on the client, and may mean printing the plaintext information to the log file.
When the target text file with the same type as the file to be converted is determined according to the configuration file, at least one text file can be determined according to the specified file directory, namely the subdirectory and the file corresponding to the file directory are traversed to determine the at least one text file, and then the target text file is determined from the at least one text file according to the type of the file to be converted in the configuration file. For example, when the file type with conversion in the configuration file is each file type as shown in table 1, a target text file with a file extension of cs, xaml, form, java, html, or js is determined from at least one text file.
Then, for each target text file: each line in the target text file is traversed to find therefrom identifiers representing annotations and/or characteristic fields for presenting plaintext information, such as "/", print, printf, and println, etc.
Step S103: and determining the original field indicated by the searched identifier and/or the characteristic field, and determining the translation field corresponding to the original field.
In embodiments of the present invention, the original field indicated by the identifier and/or the feature field may be determined by a regular expression. For example, in addition to configuring the file type to be converted through the name attribute in the configuration file, the regular expression may also be configured through the mark attribute in the configuration file, and the matching condition may also be configured through the condition attribute. After the identifier and/or the characteristic field are found, the original field to be converted can be determined from the content corresponding to the identifier and/or the characteristic field according to the regular expression and the matching condition. For example, when the identifier representing the annotation is "/" or "/", the content corresponding to the identifier is a pair of "/", or content between a pair of "/"; when the feature field for displaying the plaintext information is print, printf, println, or printjs, the print, printf, println, or printjs is generally followed by parentheses, and for example, in an html document, the form of the feature field is generally print (), printf (), println (), or printjs (), and the content corresponding to the feature field is the content in the parentheses following the print, printf, println, or printjs.
In the configuration file, the file type, the regular expression and the matching condition can be configured at least through the following program languages:
<data name=”.xaml”>
<remark><![CDATA[<\!—[\d\D]*></remark>
<codition>[\u4e00-\u9fbb]</condition>
for convenience of description, the original field to be converted is determined from the content corresponding to the identifier. In this example, assuming that the extension of the text file 1 determined from the file directory is. xaml, the type of the text file 1 belongs to the file types included in the configuration file, and therefore, this text file 1 can be used as the target text file to be converted. And traversing and searching the text file 1, finding the identifier representing the annotation, and further determining whether the content corresponding to the identifier representing the annotation is matched with the regular expression according to the regular expression. For example, when the identifier indicating the comment is "/", the content corresponding to the identifier indicating the comment is the content between a pair of "/". Then, according to the regular expression in the configuration table, determining whether the content corresponding to the identifier representing the comment is matched with the regular expression, if so, indicating that the content corresponding to the identifier representing the comment does not have the original field to be converted, otherwise, indicating that the content corresponding to the identifier representing the comment has the original field to be converted, further determining the original field from the content corresponding to the identifier representing the comment according to the condition attribute, for example, when the condition attribute is configured to include a regular expression of chinese, taking the chinese included in the content corresponding to the identifier representing the comment as the original field. For example, in a certain line in the text file 1, the content corresponding to the identifier indicating the annotation is "< label name ═ test" > input account number ≧ label > ", the original field to be converted is" input account number ".
In addition, the configuration file may further include a separator and a separation policy, and when the original field is determined, the line data corresponding to the identifier and/or the feature field may be determined first, and then the line data is separated according to the separator and the separation policy, so as to obtain the original field to be converted.
For example, in addition to the mark attribute and the condition attribute, the configuration file is further provided with a separator (symbol) and a separation policy (deep), the separator is a mark that line data in the text file needs to be separated, the separation policy indicates a policy for separating line data of the text file, if a field indicating the separation policy is 1, it indicates that only a word appearing first in the line data needs to be separated, and if the separation policy is 0, it indicates that each appearing word in the line data needs to be separated. In addition, other additional conditions (additional) can be set in the configuration file in a self-defined way, such as the commonly used filtering conditions: in (), not is null, and, or the like as additional conditions. The configuration of the delimiters, delimitation policies and additional conditions described above can be implemented at least by the following programming languages:
according to the above embodiment, when the configuration file includes both the remark attribute and the condition attribute, the separator (symbol), the separation policy (deep), and the additional condition, the configuration file may be implemented by at least the following programming languages:
when the configuration file simultaneously includes a remark attribute, a condition attribute, a separator, a separation policy and an additional condition, line data matched with a regular expression corresponding to the condition attribute may be determined, that is, content matched with the condition attribute is determined from content corresponding to an identifier representing a comment, then the determined content is separated according to the separator and the separation policy corresponding to the identifier, then the separated fields are matched with the additional condition (such as one or more filter conditions), and the successfully matched fields are used as original fields to be converted. It can be understood that the process of determining the original field from the content corresponding to the characteristic field for displaying the plaintext information according to the separator and the separation policy is the same as the process of determining the original field from the content corresponding to the identifier representing the annotation, and is not described herein again.
After the original field is determined, a translation field corresponding to the original field may be determined using a local translation correspondence table or an online translation plug-in. When the translation field corresponding to the original field is determined by using the local translation correspondence table, the translation correspondence table may be stored in the configuration file, or may be separately stored from the configuration file. And the translation corresponding table is correspondingly recorded with one or more translation fields corresponding to the fields respectively.
When the configuration file includes the delimiter and the separation policy, the determined original field is generally in a word segmentation form, and the translation corresponding table may be preferably used to determine the translation field corresponding to the original field. The translation corresponding table records translation fields corresponding to a plurality of fields respectively, and when a plurality of original fields are determined from the target text file, original fields different from each other can be determined from the original fields; generating a conversion dictionary for the mutually different original fields; the conversion dictionary includes: the mutually different original fields and the mutually different original fields respectively correspond to translation fields and default values.
For example, after matching text files according to a configuration file, all original fields in a target text file which need to be replaced may be acquired, where the original fields may include the same field, for example, when the target text file includes a plurality of "input accounts", translation fields corresponding to the plurality of "input accounts" are the same, so that when a conversion dictionary is generated, only one of the plurality of "input accounts" needs to be selected to generate the conversion dictionary, that is, each original field in the conversion dictionary is an original field which is different from each other, so as to reduce the data amount in the conversion dictionary, and improve the efficiency of replacing the original field with the translation field. In generating the conversion dictionary, the conversion dictionary may be generated from the translation correspondence table. For example, after the original field is determined, a field identical to the original field may be searched for from the translation correspondence table, and a translation field corresponding to the field recorded in the translation correspondence table may be searched for, so as to generate a conversion dictionary corresponding to the original field according to the translation correspondence table.
For example, when the original field is a chinese field and the translated field is an internationalized field, the translation correspondence table includes internationalized fields and default values corresponding to a plurality of chinese fields, respectively. After a plurality of original fields are determined from a target text file, an original field set dic is generated according to the different original fields in the original fields, then the dic is traversed to search the internationalized field and the default value corresponding to each original field from the translation corresponding table, and then a conversion dictionary is generated according to the original fields and the corresponding relation between the internationalized field and the default value. The default value corresponding to the original field may be a self-defined content, which may be the same as or different from the translated field. The default value is used for presenting customized content on the interface when the translation fails or the display fails.
In addition, when the original field is a chinese field and the translated field is an internationalized field, after the original field set dic is generated, the dic may also be traversed to encode each chinese field therein, generate a unique identifier unickey corresponding to each chinese field, and generate an I18N (internationalization) field corresponding to each chinese field, that is, in addition to determining the internationalized field corresponding to the chinese field from the translation correspondence table, the internationalized field corresponding to the chinese field may also be generated by encoding. Then, based on the Chinese field and its corresponding internationalized field, a corresponding I18N dictionary, i.e., a conversion dictionary, is generated. The conversion dictionary can be in the form of map, the key in the map is the original field, and the value can be multiple, for example, the value includes the unique identification unicey, default value, chinese value, english value, etc. corresponding to the original field. The form of the conversion dictionary can be shown in table 2 below.
TABLE 2
Wherein, Unikey represents the unique identifier corresponding to the original field, Defstr represents the default value, ZHCNStr represents the Chinese value, and EnUsStr represents the English value. In one embodiment of the present invention, when the original field in the dic is "enter account", the 1I8n dictionary is I18nDic [ com _100001, ("com _100001," "enter account," "" ",") ] after I18N conversion.
In addition, when the configuration file only includes the file type to be converted, an identifier representing a comment, and a feature field for presenting plaintext information, the determined original field may be in a sentence form, in which case, it is preferable to determine a translation field corresponding to the original field using an online translation plug-in. For example, when the original field indicated by the characteristic field for displaying the plaintext information is determined, and the original field indicated by the characteristic field is possibly in a sentence form, the translation plug-in can be directly adopted to directly translate the whole original field. It can be understood that, when the translation plug-in is used to determine the translation field corresponding to the original field, since there may be a plurality of identical original fields in the target text file, a corresponding conversion dictionary may also be generated, so as to facilitate replacement of the plurality of identical original fields.
In another embodiment of the present invention, the original field and the translated field may also be fields with the same language but different contents, for example, the original field is "zhang XX" and the translated field is "li YY".
After the conversion dictionary is generated, the conversion dictionary can be stored, so that when the original field in the current target text file is replaced or the original field in the new target text file is replaced, the conversion dictionary can be called according to the storage path of the conversion dictionary, the replacement efficiency of the original field is improved, and the file conversion efficiency is improved.
Step S104: replacing an original field in the target text file with the translated field to convert the target text file.
When the original fields are replaced according to the conversion dictionary, because the same original fields in the conversion dictionary only appear once, when the original fields are determined from the target text file, the positions of the original fields in the target text file can be marked, and conversion marks corresponding to the translation fields are added at the positions; when replacing, the original field to be converted can be quickly positioned according to the conversion identifier, so that the original field can be replaced by the translation field. For example, the same original fields in the target text file are marked with the same conversion identifications, and if the conversion identifications of "1" are added to a plurality of "input account numbers" in the target text file, when the original fields of the "input account numbers" are converted, the "input account numbers" in the target text file can be quickly located through the "1", so that the "input fields" in the target text file can be replaced according to the international fields corresponding to the "input account numbers" in the conversion dictionary, and the field replacement efficiency is improved.
In one embodiment of the present invention, the configuration file may further include a replacement prefix and a replacement suffix, and when the original field in the target text file is replaced with the internationalized field, the original field in the target text file may be replaced with the replacement prefix, the internationalized field, and the replacement suffix.
For example, the configuration file may configure a replacement prefix and a replacement suffix respectively using a prefix field and a suffix field, and may also configure additional conditions corresponding to the replacement process, for example, still taking the filter condition as an additional condition. The additional conditions of the replacement phase and the original field determination process may be the same or different. When the configuration file is configured with an additional condition of a replacement process, when the original field meets the additional condition, the original field is replaced by adopting a mode of replacing a prefix, an internationalized field and a suffix. In addition, a reference path corresponding to the replacement module can be configured in the configuration file, and the reference is inserted into the line of the target text file through the line attribute configuration. The above configuration can be realized by at least the following program languages:
when the configuration file is configured as above, when the original field in the target text file is replaced according to the conversion dictionary, the data Ld of each line of the target text file can be traversed to determine the original field to be replaced, and when the original field is matched with the additional condition of the replacement process, the original field is replaced according to the replacement prefix, the internationalized field and the replacement suffix in the configuration file, that is, the replacement result of the original field is prefix data + universal key + suffix data in the conversion dictionary, wherein the universal key is the unique identifier corresponding to the original field in the conversion dictionary. For example, when the line data in the target text file is < label name ═ test "> input account number </label >, the line data is replaced according to the conversion dictionary [ com _100001, (" com _100001, "" input account number, "" ") ], and then the replacement result is < label name ═ test" content ═ x: staticii 18N: xxx.com _100001} "/>. It will be appreciated that when multiple original fields exist in the target text file, batch replacement may be performed according to the conversion dictionary. Therefore, the internationalized conversion of the target text file is realized.
According to the above embodiment, as shown in fig. 2, a file conversion method provided by an embodiment of the present invention may include the following steps:
step S201: determining at least one text file, and determining a target text file with the same type as the file to be converted from the at least one text file according to the type of the file to be converted included in the configuration file.
Step S202: and searching the identifier representing the annotation and the characteristic field for displaying the plaintext information from the target text file according to the identifier representing the annotation and the characteristic field for displaying the plaintext information which are included in the configuration file.
Here, an identifier "/" or "/" indicating an annotation, and a feature field for showing plaintext information is print, printf, println, or printjs.
Step S203: and determining the identifier in the target text file and the line data corresponding to the characteristic field for displaying the plaintext information, and separating the line data according to the separator and the separation strategy in the configuration file to obtain a plurality of original fields.
Step S204: and marking the position of the original field in the target text file, and adding a conversion identifier corresponding to the translation field at the position.
Step S205: determining internationalized fields respectively corresponding to different original fields in the plurality of original fields, and generating a conversion dictionary according to the internationalized fields respectively corresponding to the different original fields and a default value.
Step S206: and replacing each original field in the target text file with an internationalized field according to the conversion dictionary and the conversion identifier in the target text file so as to convert the target text file into the internationalized file.
According to the file conversion method, the file type to be converted, the identifier for identifying the comment and the characteristic field for displaying the plaintext information are configured in advance through the configuration file, after the text file is obtained, the configuration file is called to determine the target text file with the same type as the file to be converted, the identifier for representing the comment and the characteristic field for displaying the plaintext information are searched from the target text file to determine the original field to be converted, then the translation field corresponding to the original field is determined, and the original field is replaced by the translation field, so that automatic conversion of the target text file is achieved, file conversion efficiency is improved, errors in field replacement are avoided, and interface layout errors caused by file conversion are avoided.
Fig. 3 is a schematic diagram of main modules of an apparatus for file conversion according to an embodiment of the present invention.
As shown in fig. 3, an apparatus 300 for file conversion according to an embodiment of the present invention includes: a file determination module 301, a first determination module 302, a second determination module 303, and a replacement module 304; wherein,
the file determining module 301 is configured to determine at least one text file;
the first determining module 302 is configured to determine, according to a configuration file, a target text file of the same type as the file to be converted from the at least one text file, and search for an identifier representing a comment and/or a feature field for displaying plaintext information from the target text file; wherein the configuration file comprises: a file type to be converted and one or both of the following: the identifier representing the annotation and the characteristic field for presenting plaintext information;
the second determining module 303 is configured to determine an original field indicated by the found identifier and/or the found characteristic field, and determine a translation field corresponding to the original field;
the replacing module 304 is configured to replace an original field in the target text with the translated field to convert the target text file.
In an embodiment of the present invention, the second determining module 303 is configured to determine a translation field corresponding to the original field by using a local translation mapping table or an online translation plug-in.
In an embodiment of the present invention, the second determining module 303 is configured to determine different original fields from a plurality of the original fields, and generate a conversion dictionary for the different original fields; the conversion dictionary includes: the different original fields and the different original fields respectively correspond to translation fields and default values; and determining a translation field corresponding to the original field according to the conversion dictionary.
In an embodiment of the present invention, the second determining module 303 is configured to store the conversion dictionary, so as to call the conversion dictionary according to a storage path.
In an embodiment of the present invention, the configuration file further includes: a separator and a separation policy; the second determining module 303 is configured to determine line data corresponding to the identifier and/or the feature field, and separate the line data according to the separator and a separation policy to obtain the original field.
In one embodiment of the invention, the translation field includes: an internationalized field; the configuration file further comprises: a replacement prefix and a replacement suffix; the replacing module 304 is configured to replace the original field in the target text file with the replacement prefix, the internationalized field, and the replacement suffix.
In an embodiment of the present invention, the replacing module 304 is configured to mark a position of the original field in the target text file, and add a conversion identifier corresponding to the translation field at the position; and replacing the original field with the translation field according to the conversion identifier.
According to the file conversion device provided by the embodiment of the invention, the file type to be converted, the identifier for identifying the annotation and the characteristic field for displaying the plaintext information are configured in advance through the configuration file, after the text file is obtained, the configuration file is called to determine the target text file with the same type as the file to be converted, the identifier for representing the annotation and the characteristic field for displaying the plaintext information are searched from the target text file to determine the original field to be converted, then the translation field corresponding to the original field is determined, and the original field is replaced by the translation field, so that the automatic conversion of the target text file is realized, the file conversion efficiency is improved, errors are avoided when the field is replaced, and the interface layout errors caused by file conversion are avoided.
Fig. 4 illustrates an exemplary system architecture 400 of a method of file conversion or an apparatus of file conversion to which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have various communication client applications installed thereon, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 401, 402, and 403. The background management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (e.g., target push information and product information) to the terminal device.
It should be noted that, the method for converting a file provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, a device for converting a file is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a file determination module, a first determination module, a second determination module, and a replacement module. Where the names of these modules do not in some cases constitute a limitation of the module itself, for example, the file determination module may also be described as a "module that determines at least one text file".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: determining at least one text file; according to a configuration file, determining a target text file with the same type as the file to be converted from the at least one text file, and searching an identifier representing a comment and/or a characteristic field for displaying plaintext information from the target text file; wherein the configuration file comprises: the file type to be converted, the identifier representing the annotation and the characteristic field for displaying plaintext information; determining an original field indicated by the searched identifier and/or the characteristic field, and determining a translation field corresponding to the original field; replacing an original field in the target text file with the translated field to convert the target text file.
According to the technical scheme of the embodiment of the invention, the file type to be converted, the identifier for identifying the comment and the characteristic field for displaying the plaintext information are configured in advance through the configuration file, after the text file is obtained, the configuration file is called to determine the target text file with the same type as the file type to be converted, the identifier for representing the comment and the characteristic field for displaying the plaintext information are searched from the target text file to determine the original field to be converted, then the translation field corresponding to the original field is determined, and the original field is replaced by the translation field, so that the automatic conversion of the target text file is realized, the file conversion efficiency is improved, errors are avoided when the field is replaced, and the interface layout errors caused by file conversion are avoided.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (13)
1. A method of file conversion, comprising:
determining at least one text file;
according to a configuration file, determining a target text file with the same type as the file to be converted from the at least one text file, and searching an identifier representing a comment and/or a characteristic field for displaying plaintext information from the target text file; wherein the configuration file comprises: a file type to be converted and one or both of the following: the identifier representing the annotation and the characteristic field for presenting plaintext information;
determining an original field indicated by the searched identifier and/or the characteristic field, and determining a translation field corresponding to the original field;
replacing an original field in the target text file with the translated field to convert the target text file.
2. The method of claim 1, wherein the determining the translation field corresponding to the original field comprises:
and determining a translation field corresponding to the original field by using a local translation corresponding table, wherein the translation corresponding table correspondingly records translation fields corresponding to a plurality of fields respectively.
3. The method according to claim 1, wherein when there are a plurality of original fields found in the text file, the determining a translation field corresponding to the original field comprises:
determining original fields different from each other from the searched original fields;
generating a conversion dictionary for the mutually different original fields; the conversion dictionary includes: the different original fields and the different original fields respectively correspond to translation fields and default values;
and determining a translation field corresponding to the original field according to the conversion dictionary.
4. The method of claim 3, further comprising:
and storing the conversion dictionary to call the conversion dictionary according to a storage path.
5. The method of claim 1, wherein the determining the translation field corresponding to the original field comprises:
and determining a translation field corresponding to the original field by using an online translation plug-in.
6. The method of claim 1, wherein the configuration file further comprises: a separator and a separation policy; the determining the original field indicated by the located identifier includes:
and determining the line data corresponding to the identifier and/or the characteristic field, and separating the line data according to the separator and a separation strategy to obtain the original field.
7. The method of claim 1, wherein the translation field comprises: an internationalized field; the configuration file further comprises: a replacement prefix and a replacement suffix; replacing an original field in the target text file with the translated field, comprising:
replacing an original field in the target text file with the replacement prefix, the internationalized field, and the replacement suffix.
8. The method of claim 1, wherein replacing the field to be converted in the text file with the internationalized field comprises:
marking the position of the original field in the target text file, and adding a conversion identifier corresponding to the translation field at the position;
and replacing the original field with the translation field according to the conversion identifier.
9. An apparatus for file conversion, comprising: the system comprises a file determining module, a first determining module, a second determining module and a replacing module; wherein,
the file determining module is used for determining at least one text file;
the first determining module is used for determining a target text file with the same type as the file to be converted from the at least one text file according to the configuration file, and searching an identifier representing a comment and/or a characteristic field for displaying plaintext information from the target text file; wherein the configuration file comprises: a file type to be converted and one or both of the following: the identifier representing the annotation and the characteristic field for presenting plaintext information;
the second determining module is configured to determine an original field indicated by the found identifier and/or the feature field, and determine a translation field corresponding to the original field;
the replacing module is used for replacing the original field in the target text by the translation field so as to convert the target text file.
10. The apparatus of claim 9,
the second determining module is configured to determine a translation field corresponding to the original field by using a local translation correspondence table or an online translation plug-in, where translation fields corresponding to a plurality of fields are recorded in the translation correspondence table.
11. The apparatus of claim 9,
the second determining module is configured to determine different original fields from the plurality of original fields, and generate a conversion dictionary for the different original fields; the conversion dictionary includes: the different original fields and the different original fields respectively correspond to translation fields and default values; and determining a translation field corresponding to the original field according to the conversion dictionary.
12. An electronic device for file conversion, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-8.
13. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010574894.0A CN113760821B (en) | 2020-06-22 | 2020-06-22 | File conversion method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010574894.0A CN113760821B (en) | 2020-06-22 | 2020-06-22 | File conversion method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113760821A true CN113760821A (en) | 2021-12-07 |
CN113760821B CN113760821B (en) | 2024-07-16 |
Family
ID=78785504
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010574894.0A Active CN113760821B (en) | 2020-06-22 | 2020-06-22 | File conversion method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113760821B (en) |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6385569B1 (en) * | 1999-03-11 | 2002-05-07 | Sharp Kabushiki Kaisha | Translator, translating method and recording medium having translating program recorded thereon |
CN104536769A (en) * | 2015-01-16 | 2015-04-22 | 浪潮电子信息产业股份有限公司 | International file achieving method |
CN109918166A (en) * | 2019-03-12 | 2019-06-21 | 天津字节跳动科技有限公司 | Applet process method, apparatus and electronic equipment |
CN110263130A (en) * | 2019-06-27 | 2019-09-20 | 深圳前海微众银行股份有限公司 | Page info processing method, device and storage medium |
CN110413574A (en) * | 2019-07-30 | 2019-11-05 | 深圳市携众通科技有限公司 | A kind of method of automatic code generating internationalized resources |
CN110879801A (en) * | 2019-11-21 | 2020-03-13 | 中国银行股份有限公司 | Data reading method and device |
-
2020
- 2020-06-22 CN CN202010574894.0A patent/CN113760821B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6385569B1 (en) * | 1999-03-11 | 2002-05-07 | Sharp Kabushiki Kaisha | Translator, translating method and recording medium having translating program recorded thereon |
CN104536769A (en) * | 2015-01-16 | 2015-04-22 | 浪潮电子信息产业股份有限公司 | International file achieving method |
CN109918166A (en) * | 2019-03-12 | 2019-06-21 | 天津字节跳动科技有限公司 | Applet process method, apparatus and electronic equipment |
CN110263130A (en) * | 2019-06-27 | 2019-09-20 | 深圳前海微众银行股份有限公司 | Page info processing method, device and storage medium |
CN110413574A (en) * | 2019-07-30 | 2019-11-05 | 深圳市携众通科技有限公司 | A kind of method of automatic code generating internationalized resources |
CN110879801A (en) * | 2019-11-21 | 2020-03-13 | 中国银行股份有限公司 | Data reading method and device |
Non-Patent Citations (3)
Title |
---|
CHEN, WEI-TE等: "Anafora: A Web-based General Purpose Annotation Tool", 《 PROCEEDINGS OF THE CONFERENCE. ASSOCIATION FOR COMPUTATIONAL LINGUISTICS》, vol. 2013, 1 June 2013 (2013-06-01) * |
关向峰;: ""对等论"翻译标准在商标翻译中的局限性", 中国电力教育, no. 05, 10 February 2011 (2011-02-10) * |
陈章进: "数据库开发中的字段翻译和TAB顺序工具", 计算机工程, no. 08, 20 August 2000 (2000-08-20) * |
Also Published As
Publication number | Publication date |
---|---|
CN113760821B (en) | 2024-07-16 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11461111B2 (en) | Method for running applets, and electronic device | |
CN110471848B (en) | Method and device for dynamically returning message | |
CN111447257B (en) | Message conversion method and device | |
CN113139390A (en) | Language conversion method and device applied to code character strings | |
CN110555030A (en) | SQL statement processing method and device | |
CN113382083B (en) | Webpage screenshot method and device | |
CN110858202A (en) | Method and device for generating where clause in database query statement | |
CN110705271A (en) | System and method for providing natural language processing service | |
CN107526742B (en) | Method and apparatus for processing multilingual text | |
CN108885544B (en) | Front-end page internationalized processing method, application server and computer-readable storage medium | |
CN113626223A (en) | Interface calling method and device | |
US11994980B2 (en) | Method, device and computer program product for application testing | |
US11687735B2 (en) | Method, apparatus, device and storage medium for outputting information | |
CN113360106B (en) | Webpage printing method and device | |
CN113760821B (en) | File conversion method and device | |
CN111178025A (en) | Editing method and device of nuclear power plant operation guide rules, computer equipment and storage medium | |
CN112784596A (en) | Method and device for identifying sensitive words | |
CN112487765B (en) | Method and device for generating notification text | |
CN111753675B (en) | Picture type junk mail identification method and device | |
CN113361286A (en) | Information prompting method and device | |
CN113779018A (en) | Data processing method and device | |
CN110796137A (en) | Method and device for identifying image | |
CN113704242A (en) | Data processing method and device | |
CN112835609A (en) | Method and device for modifying dependent package download address | |
CN110858240A (en) | Front-end module loading method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant |