Code localization conversion method and related equipment

By using an automated code localization conversion method, configuration files and matching rules are used to accurately locate and process localized strings in the code, solving the problems of low efficiency and high error rate in traditional methods, and achieving efficient and accurate localization processing and real-time monitoring.

CN120848950APending Publication Date: 2025-10-28SHENZHEN LANYOU TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510893492.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2025-10-28

AI Technical Summary

Technical Problem

Traditional code localization processes rely on manual operations, resulting in low efficiency, high error rates, maintenance difficulties, and lack of verification, which seriously affects software development efficiency and product quality.

Method used

By obtaining the configuration file, the system automatically traverses the code file using the scanning path, matching rules, and ignore patterns to accurately locate the target string. It then uses a replacement template to perform automated localization calls and generates a report of unlocalized strings for real-time monitoring.

Benefits of technology

It improves the efficiency of code localization extraction, avoids human omissions and operational errors, ensures localization coverage, realizes automated real-time monitoring and synchronization, and reduces maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120848950A_ABST
    Figure CN120848950A_ABST
Patent Text Reader

Abstract

The invention discloses a code localization conversion method and related equipment. The method comprises the steps that a configuration file is acquired; wherein the configuration file comprises a scanning path, a matching rule, an ignoring mode and a replacement template; based on the scanning path, loading to obtain a source code to be converted; extracting a capture group and a matching mode thereof from the source code based on the matching rule and the neglect mode; wherein codes, except for the capture group, in the source code are marked as non-localized so as to generate a non-localized character string report; and based on the matching mode, carrying out localization calling on the capture group according to the replacement template, and outputting a localization code. According to the method, code localization conversion can be efficiently and accurately realized. The method can be widely applied to the technical field of data processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a code localization conversion method and related equipment. Background Technology

[0002] In the process of global software development, code localization is a core step in achieving multi-language support. Traditional localization processes typically rely on developers manually performing the following operations:

[0003] 1. Manual Traversal and Extraction: Developers need to scan the source code line by line and manually identify strings that need to be localized (such as user interface text). In large projects, the code is massive and complex, making this process time-consuming and labor-intensive, and prone to missing critical strings due to human error.

[0004] 2. Manual Replacement and Integration: Developers need to replace the original string with a localized function call (such as `gettext()`). Due to the lack of precise string boundary recognition rules, two types of errors often occur:

[0005] Incorrectly replacing non-localized content (such as logs or technical identifiers) can cause functional abnormalities.

[0006] The omission of strings that need to be localized resulted in insufficient translation coverage.

[0007] 3. High maintenance costs: When the project is iterated, new strings need to be manually extracted repeatedly, which is difficult to synchronize with localized resource files in real time; at the same time, code refactoring may cause old localized resource references to become invalid, forming "zombie resources" and significantly increasing the maintenance burden.

[0008] 4. Lack of verification mechanism: There is a lack of automated tools to detect non-localized strings. Reliance on manual review or test case coverage makes it difficult to guarantee the integrity of localization, which can easily lead to quality risks in internationalized versions.

[0009] In summary, existing technologies suffer from four major drawbacks: low efficiency, high error rate, difficult maintenance, and lack of verification, which severely restrict software development efficiency and product quality. Summary of the Invention

[0010] The main objective of this application is to provide a code localization conversion method, apparatus, electronic device, and storage medium, which aims to solve at least one problem of the prior art.

[0011] To achieve the above objectives, one aspect of this application proposes a code localization conversion method, the method comprising:

[0012] Obtain the configuration file; the configuration file includes the scan path, matching rules, ignore mode, and replacement template;

[0013] Based on the scan path, the source code to be converted is loaded;

[0014] Based on matching rules and ignore patterns, capture groups and their matching patterns are extracted from the source code; code other than capture groups in the source code is marked as unlocalized to generate an unlocalized string report.

[0015] Based on the matching pattern, the capture group is called locally according to the replacement template, and the local code is output.

[0016] In some embodiments, the method further includes the following steps:

[0017] In response to configuration operations on the target object, a configuration file is generated.

[0018] In some embodiments, the matching rules include multiple regular expressions, and the matching patterns include language features and matching positions. Based on the matching rules and ignore patterns, the capture groups and their matching patterns are extracted from the source code, including the following steps:

[0019] The first regular expression is used to scan the source code line by line to identify comments and obtain the comment lines in the source code.

[0020] Based on the semantics and structure of the source code, ignore code blocks in the source code are obtained by traversing the ignore pattern;

[0021] Obtain the file extension of the source code, and determine the programming language type of the source code as a language feature based on the file extension mapping;

[0022] The capture groups are extracted from the source code (excluding comment lines and ignored code blocks) using a second regular expression, and the matching positions of the capture groups are recorded.

[0023] In some embodiments, the source code is scanned line by line using a first regular expression to identify comments and obtain comment lines in the source code, including the following steps:

[0024] The source code is scanned line by line using the first regular expression to check if each line contains the target comment tag;

[0025] When a line of code contains a target comment marker, the line of code is determined to be a comment line.

[0026] In some embodiments, traversing the semantics and structure of the source code based on the ignore pattern to obtain the ignored code blocks in the source code includes the following steps:

[0027] Iterate through each line of the source code line by line, and use the currently iterated line of code as the target line;

[0028] Match the target line based on the ignore pattern. If the target line contains the ignore pattern, obtain the nesting depth of the target line.

[0029] Take the target line as the first target line, continue scanning the subsequent lines of the first target line and decrease the nesting depth line by line until the nesting depth is zero, and take the scanned line of code as the second target line;

[0030] All lines of code from the first target line to the second target line are designated as the ignored code block;

[0031] Take the line following the second target line as the target line, return to execute the step of matching the target line based on the ignore pattern, until all lines of code in the source code have been traversed.

[0032] In some embodiments, capturing groups are extracted from the source code (excluding comment lines and ignored code blocks) using a second regular expression, and the matching positions of the capturing groups are recorded, including the following steps:

[0033] The second regular expression is used to match strings in the source code except for comment lines and ignored code blocks. Based on the successful matches, the strings and their context information are extracted to obtain capture groups, and the matching positions of the strings and their contexts are recorded.

[0034] In some embodiments, the replacement template includes a custom template and a default template; based on the matching pattern, the capture group is localized according to the replacement template, and localized code is output, including the following steps:

[0035] Based on the matching pattern corresponding to the capture group, the target template is obtained by matching from the custom template;

[0036] The capture group is localized based on the target template, and localized code is output.

[0037] If no target template is found from the custom template, the capture group is localized based on the default template, and the localized code is output.

[0038] To achieve the above objectives, another aspect of the embodiments of this application proposes a code localization conversion apparatus, the apparatus comprising:

[0039] The data acquisition module is used to acquire configuration files; the configuration files include scan paths, matching rules, ignore modes, and replacement templates.

[0040] The code loading module is used to load the source code to be converted based on the scan path;

[0041] The capture module is used to extract capture groups and their matching patterns from the source code based on matching rules and ignore patterns.

[0042] The localization module is used to make localized calls to the capture group based on the matching pattern and the replacement template, and output localized code.

[0043] In some embodiments, the apparatus further includes:

[0044] The configuration module is used to generate configuration files in response to configuration operations on the target object.

[0045] To achieve the above objectives, another aspect of the embodiments of this application proposes an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the aforementioned method.

[0046] To achieve the above objectives, another aspect of the embodiments of this application proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned method.

[0047] To achieve the above objectives, another aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the aforementioned method.

[0048] The embodiments of this application include at least the following beneficial effects: This application provides a code localization conversion method, apparatus, electronic device, storage medium, and program product. This solution obtains a configuration file; wherein the configuration file includes a scan path, matching rules, ignore modes, and replacement templates; based on the scan path, the source code to be converted is loaded; based on the matching rules and ignore modes, capture groups and their matching modes are extracted from the source code; wherein code in the source code other than the capture groups is marked as unlocalized to generate an unlocalized string report; based on the matching modes, the capture groups are called locally according to the replacement templates to output localized code. This application automatically traverses code files through scan paths and matching rules to accurately locate target strings, and automatically filters non-localized content (such as logs and debugging information) using the configured ignore modes to avoid human omissions and improve extraction efficiency; simultaneously, it automatically generates standard localized calls using replacement templates to eliminate human error; newly added code can be rescanned with one click through the configuration file and automatically synchronized to localized resource files; it can also reverse-detect unmatched strings based on matching rules and output an unlocalized string report to achieve real-time monitoring of localization coverage and ensure no omissions. Attached Figure Description

[0049] Figure 1 This is a schematic diagram of an implementation environment for the code localization conversion method provided in this application embodiment;

[0050] Figure 2This is a flowchart illustrating a code localization conversion method provided in an embodiment of this application;

[0051] Figure 3 This is a schematic diagram illustrating the system architecture principle and flow of the code localization conversion method provided in the embodiments of this application;

[0052] Figure 4 This is a schematic diagram of the business process of the code localization conversion method provided in the embodiments of this application;

[0053] Figure 5 This is a schematic diagram of the structure of a code localization conversion device provided in an embodiment of this application;

[0054] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Detailed Implementation

[0055] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit it. In the following description, when referring to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with those of this application; they are merely examples of apparatuses and methods consistent with some aspects of the embodiments of this application as detailed in the appended claims.

[0056] It is understood that the terms “first,” “second,” etc., used in this application may be used herein to describe various concepts, but unless otherwise stated, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of the embodiments of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the words “if,” “when,” or “in response to a determination” as used herein may be interpreted as “when…” or “when…” or “in response to a determination.”

[0057] As used in this application, the terms "at least one", "multiple", "each", "any", etc., "at least one" includes one, two or more, "multiple" includes two or more, "each" refers to each of the corresponding multiples, and "any" refers to any one of the multiples.

[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0059] Before providing a detailed description of the embodiments of this application, some of the nouns and terms involved in the embodiments of this application will be explained first. The nouns and terms involved in the embodiments of this application are subject to the following interpretations.

[0060] i18n (internationalization): refers to the process of decoupling a product from specific languages ​​and regions during the software design phase, so that it can adapt to different language environments (such as interface text, date formats, currency symbols, etc.) without modifying the internal code.

[0061] Multi-pattern matching engine: One of the core components of the system, based on regular expression caching, compilation pattern caching, and multi-level matching strategies, it supports multi-level matching from simple strings to complex syntax. By pre-compiling and caching regular expressions, it avoids the overhead of repeated compilation, and can efficiently identify strings in the code that need to be localized, covering diverse localization scenarios.

[0062] Context-aware algorithms: Intelligent processing algorithms that combine code semantics and contextual environment. By recognizing code comments, ignoring code blocks that do not require localization (such as logs and debugging code), and automatically adjusting processing strategies based on file type, it ensures that only valid strings are localized, avoiding accidental operations. For example, it determines whether to ignore specific code segments by analyzing code block depth (number of nested curly braces).

[0063] In related technologies, traditional localization processes usually rely on developers to manually complete related operations, which has four major drawbacks: low efficiency, high error rate, difficult maintenance, and lack of verification, which seriously restrict software development efficiency and product quality.

[0064] In view of this, this application provides a code localization conversion method. This method obtains a configuration file, which includes a scan path, matching rules, an ignore mode, and a replacement template. Based on the scan path, the source code to be converted is loaded. Based on the matching rules and the ignore mode, capture groups and their matching modes are extracted from the source code. Code in the source code other than the capture groups is marked as unlocalized to generate an unlocalized string report. Based on the matching mode, the capture groups are localized according to the replacement template, outputting localized code. This application automatically traverses code files using the scan path and matching rules to accurately locate target strings. Furthermore, it automatically filters non-localized content (such as logs and debugging information) using the configured ignore mode, avoiding manual omissions and improving extraction efficiency. Simultaneously, it automatically generates standard localized calls using the replacement template, eliminating human error. Newly added code can be rescanned with a single click through the configuration file and automatically synchronized to localized resource files. It can also reverse-detect unmatched strings based on the matching rules and output an unlocalized string report to achieve real-time monitoring of localization coverage and ensure no omissions.

[0065] It is understood that the code localization conversion method provided in this application can be applied to any computer device with data processing and computing capabilities, and this computer device can be various terminals or servers. When the computer device in the embodiment is a server, the server is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Optionally, the terminal can be a smartphone, tablet, laptop, or desktop computer, but it is not limited to these.

[0066] like Figure 1 The diagram shown is a schematic representation of an implementation environment provided in an embodiment of this application. (Refer to...) Figure 1 The implementation environment includes at least one terminal 102 and a server 101. The terminal 102 and the server 101 can be connected via a network, either wirelessly or via a wired connection, to complete data transmission and exchange.

[0067] Server 101 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0068] Additionally, server 101 can also be a node server in a blockchain network. Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms.

[0069] Terminal 102 can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited to these. Terminal 102 and server 101 can be directly or indirectly connected via wired or wireless communication, and this embodiment of the application does not impose any limitations.

[0070] For example, based on Figure 1 The implementation environment shown in this application embodiment provides a code localization conversion method. The following description uses the application of this code localization conversion method in server 101 as an example. It can be understood that this code localization conversion method can also be applied in terminal 102.

[0071] Reference Figure 2 , Figure 2 This is an optional flowchart of the code localization conversion method provided in the embodiments of this application. The execution subject of the code localization conversion method can be any of the aforementioned computer devices (including servers or terminals). Figure 2 The method may include, but is not limited to, steps S100 to S400.

[0072] Step S100: Obtain the configuration file;

[0073] The configuration file includes the scan path, matching rules, ignore mode, and replacement template;

[0074] It should be noted that in some embodiments, the method may further include the following step: generating a configuration file in response to a configuration operation of the target object.

[0075] For example, in some specific implementations, a user-defined JSON configuration file can first be dynamically loaded, including the scan path, matching rules, ignore patterns, and replacement templates.

[0076] Step S200: Based on the scan path, load the source code to be converted;

[0077] For example, in some specific implementations, the location of the source code to be converted is determined based on the scanning path, and then the source code to be converted is loaded from the corresponding storage / database.

[0078] Step S300: Based on the matching rules and ignore patterns, extract the capture groups and their matching patterns from the source code;

[0079] In this context, code outside of the capture group in the source code is marked as unlocalized to generate an unlocalized string report;

[0080] For example, in some implementations, processing logs are logged, including untranslated strings and their locations, by marking code in the source code other than the capture group as unlocalized to output an unlocalized string report.

[0081] It should be noted that the matching rules include various regular expressions, and the matching patterns include language features and matching positions. In some embodiments, step S300 may include the following steps:

[0082] S301. Scan the source code line by line using the first regular expression to identify comments and obtain the comment lines in the source code;

[0083] In some embodiments, step S301 may include the following steps: scanning the source code line by line using a first regular expression to check whether each line contains a target comment marker; when a line of code contains a target comment marker, determining that the line of code is a comment line.

[0084] For example, in some specific implementations, annotation recognition can be achieved as follows:

[0085] Algorithm logic: Scan the code line by line, checking if each line begins with a comment marker (such as / / , / *) or ends with a comment marker (such as * / ). For non-Swift files (such as Objective-C .m or .h files), additionally check lines that begin with @ but do not contain a string (such as property declarations). Use regular expressions to match comment patterns to ensure that comment content is not mistaken for localized strings.

[0086] Data processing flow:

[0087] 1. Read the lines of code and remove leading and trailing whitespace.

[0088] 2. Use regular expressions (such as ^\s* / / , ^\s* / \*, ^\s*\* / ) to check if it is a comment.

[0089] 3. If it is a comment, skip the line and do not extract the string.

[0090] Rule Basis: Comments typically do not contain user-visible interface text, therefore localization is unnecessary. The system uses explicit syntax markers ( / / , / *, etc.) to ensure accuracy.

[0091] S302. Based on the ignore pattern, traverse the semantics and structure of the source code to obtain the ignored code blocks in the source code;

[0092] In some embodiments, step S302 may include the following steps: traversing each line of the source code line by line, taking the currently traversed line of code as the target line; matching the target line based on the ignore pattern, and when the target line contains the ignore pattern, obtaining the nesting depth of the target line; taking the target line as the first target line, continuing to scan the subsequent lines of the first target line and decreasing the nesting depth line by line until the nesting depth reaches zero, taking the scanned line of code as the second target line; determining all lines of code from the first target line to the second target line as ignored code blocks; taking the next line of the second target line as the target line, returning to execute the step of matching the target line based on the ignore pattern, until all lines of code in the source code have been traversed.

[0093] For example, in some specific implementations, ignoring code blocks can be achieved as follows:

[0094] Algorithm logic: By analyzing the semantics and structure of code blocks, code segments that do not require localization (such as log output and debugging code) are ignored. The system uses regular expressions to match specific keywords (such as NSLog, print, logEvent) or patterns (such as trackToCode), and combines this with the code block depth (the nesting level of curly braces {}) to determine the scope of the exclusion.

[0095] Data processing flow:

[0096] 1. Check if the current line contains an ignored pattern (such as NSLog, print).

[0097] 2. If the ignore pattern is matched, calculate the nesting depth of the curly braces in the current line (depth += line.count("{") - line.count("}")).

[0098] 3. Continue scanning subsequent lines, decreasing the nesting depth line by line, until the depth reaches zero, indicating the end of the code block.

[0099] 4. Ignore strings within the entire code block; do not extract or replace them.

[0100] Rule Basis: Logs or debug code are typically used for internal developer diagnostics and do not require translation. The system uses keyword matching and in-depth code block analysis to ensure precise exclusion scope and avoid mishandling.

[0101] S303. Obtain the file extension of the source code, and determine the programming language type of the source code as a language feature based on the file extension mapping;

[0102] For example, in some specific implementations, language feature detection can be achieved as follows:

[0103] Algorithm logic: Based on file extensions (such as .swift, .m, .h) and code syntax characteristics, the algorithm automatically identifies the programming language to facilitate loading the corresponding matching rules and replacement templates in subsequent localization processing steps. For example, Swift code uses the ly_localizedStringKey macro, while Objective-C code uses NSLocalizedString.

[0104] Data processing flow:

[0105] 1. Read the file extension to determine the programming language (e.g., .swift for Swift, .m or .h for Objective-C).

[0106] 2. Load predefined regular expression patterns based on the language type (such as Swift's setTitle call pattern or Objective-C's @ string prefix).

[0107] 3. Adjust and replace the template to ensure that the generated localized calls conform to the syntax of the target language.

[0108] Rule basis: Different programming languages ​​have different string syntax and localization calling methods. The system improves compatibility by adaptively adjusting the strategy based on file extensions and syntax features.

[0109] S304. Extract capture groups from the source code (excluding comment lines and ignored code blocks) using the second regular expression, and record the matching positions of the capture groups.

[0110] In some embodiments, step S303 may include the following steps: matching strings in the source code other than comment lines and ignored code blocks using a second regular expression, extracting the string and its context information based on the successful matching results to obtain a capture group, and recording the matching position of the string and its context.

[0111] For example, in some specific implementations, taking Chinese characters as the strings to be processed in the source code, the capture group extraction can be achieved as follows:

[0112] 1. Compile all custom pattern regular expressions and cache them to improve performance.

[0113] 2. Scan the code line by line, using both general and custom patterns for parallel matching to extract strings containing Chinese characters.

[0114] 3. If the custom pattern matches successfully, extract the specified capture group (such as the group specified by capture_group_index) and record the string and its context information (such as line number and matching position).

[0115] Step S400: Based on the matching pattern, perform localized calls on the capture group according to the replacement template and output localized code;

[0116] It should be noted that the replacement template includes a custom template and a default template. In some embodiments, step S400 may include the following steps: matching the target template from the custom template based on the matching pattern corresponding to the capture group; making a localized call to the capture group according to the target template and outputting localized code; when no target template is matched from the custom template, making a localized call to the capture group according to the default template and outputting localized code.

[0117] For example, in some specific implementations, localized calls can be achieved as follows:

[0118] Logic: During the string replacement phase, the system prioritizes applying the matching custom replacement template based on the extracted string and its context. If no matching custom rule is found, the default localized call (such as ly_localizedStringKey or NSLocalizedString) is used.

[0119] Execution process:

[0120] 1. For each extracted string, check if its line matches any custom pattern.

[0121] 2. If a match is found, obtain the corresponding replacement template and dynamically inject the localized key ({key}) and capture group content (e.g., \\1, \\2).

[0122] 3. Use the sub method of regular expressions to replace the original line of code with a new localized call.

[0123] To explain in detail the principles of the technical solution of this application, the overall process of this application will be described below with reference to some specific embodiments. It is easy to understand that the following is an explanation of the technical principles of this application and should not be regarded as a limitation of this application.

[0124] First, it's important to note that in mobile application development, multilingual localization is one of the core requirements for achieving internationalized applications. With the continuous expansion of the global market, supporting multiple languages ​​has become a crucial indicator of an application's competitiveness. However, traditional localization processes suffer from the following problems, limiting development efficiency and quality:

[0125] 1. Manual extraction is inefficient: Developers need to manually traverse the code to identify and extract strings that need to be localized. This is not only time-consuming, but also prone to missing key content due to human error in large projects.

[0126] 2. High error rate in replacement: When manually replacing localized strings, non-localized content (such as log information or debug strings) may be mistakenly replaced with localized calls, or some strings that need to be localized may be omitted, resulting in incomplete translation or abnormal functionality.

[0127] 3. Maintenance difficulties: As the project iterates, newly added strings are difficult to quickly synchronize to localized files, and old localized resources may also become invalid due to code adjustments, increasing maintenance costs.

[0128] 4. Lack of verification: Traditional processes lack automated tools to verify whether there are unlocalized strings in the code, making it difficult for developers and testers to fully check localization coverage.

[0129] Existing solutions, such as Xcode's built-in genstrings tool, while alleviating the burden of manual extraction to some extent, have significant limitations:

[0130] Limited syntax support: It can only recognize the standard NSLocalizedString syntax and cannot handle developer-defined localized macros or non-standard calls.

[0131] Poor compatibility with custom components: It cannot effectively handle strings embedded in custom UI components or frameworks, limiting its applicability in complex projects.

[0132] Lack of intelligent ignore mechanism: It cannot distinguish between strings that need to be localized and content that does not need to be localized (such as logs, URLs or constants), resulting in incorrect replacement or redundant processing.

[0133] No version control capability: It does not support version management of local files, making it difficult to track the history of string changes or roll back erroneous operations.

[0134] The aforementioned problems demonstrate that traditional methods and existing tools are insufficient to meet the demands of modern international application development for efficiency, accuracy, and flexibility. Therefore, a more intelligent and automated localization processing system is urgently needed to solve these technical challenges.

[0135] In view of this, this application provides a code localization conversion method, which can be achieved through methods such as... Figure 3 The system architecture shown is implemented as follows. This system architecture is divided into the following core components, each of which collaborates with each other to complete the localization processing task:

[0136] 1. Configuration Manager: Responsible for loading and parsing JSON-formatted configuration files, defining scan paths, matching rules, replacement templates, and ignore modes. It supports cross-platform path parsing, automatically adapting to file path formats on different operating systems (such as macOS and Windows), and provides default configurations for new users, lowering the learning curve.

[0137] 2. Multi-pattern matching engine: Based on regular expression caching and multi-level matching strategies, it efficiently identifies localized strings in code. It supports pre-compiled regular expressions and compilation pattern caching to reduce redundant calculation overhead.

[0138] 3. Context-aware processor: Through semantic analysis, it identifies comments in the code, ignores code blocks that do not need to be localized, and adjusts the processing strategy according to the file type (such as .swift, .m) to ensure that only valid strings are processed.

[0139] 4. Custom rule engine: Provides a flexible rule configuration interface, allowing developers to define matching patterns, replacement templates and capture groups, and supports dynamic replacement logic for complex strings.

[0140] 5. Report Generator: Generates detailed reports with unlocalized strings and records processing logs for easy review and supplementation by developers.

[0141] In some specific application scenarios, the technical solution of this application achieves an efficient and accurate localization process through an innovative multi-pattern matching engine and context-aware replacement algorithm. Its main process logic includes:

[0142] 1. Automatic scanning of localized strings in source code: Through static analysis technology, the system can comprehensively scan the code library and identify strings that need to be localized without manual intervention.

[0143] 2. Intelligent replacement with standardized localized calls: Based on predefined rules, the identified strings are replaced with standardized localized function calls (such as NSLocalizedString or custom macros) to ensure consistency.

[0144] 3. Generate unlocalized string report: The system can automatically detect and generate a detailed report of unlocalized strings, including file path, line number and string content, which is convenient for developers to review and supplement.

[0145] 4. Supports custom rule engine: Provides a flexible rule configuration interface, allowing developers to customize matching and replacement logic according to project needs.

[0146] 5. Non-intrusive code processing: Localization is completed without changing the original code structure, avoiding the introduction of potential risks.

[0147] like Figure 4 As shown, based on the aforementioned system architecture process, the code localization conversion method of this application can be implemented through the following steps:

[0148] 1. Configuration Loading: Dynamically loads user-defined JSON configuration files, including scan paths, matching rules, ignore patterns, and replacement templates.

[0149] 2. Code scanning: Use a multi-pattern matching engine to scan the source code and extract potential localized strings (such as strings containing Chinese characters).

[0150] 3. Context Analysis: Analyze code semantics through a context-aware processor to filter out content that does not need to be localized (such as comments and log code).

[0151] 4. String replacement: Based on the custom rule engine, the identified strings are replaced with standardized localized calls.

[0152] 5. Report Generation: Outputs a report of unlocalized strings and records the processing log, including untranslated strings and their locations.

[0153] The implementation logic of the technical solution of this application will be explained in detail below with some application scenario examples (for illustrative purposes only and should not be regarded as a limitation of this application):

[0154] 1. Implementation logic of the context-aware processor:

[0155] The context-aware processor is one of the core components of this system, responsible for ensuring that only valid localized strings are processed through semantic analysis. The specific implementation algorithms for its three sub-functions are as follows:

[0156] 1.1 Annotation Recognition:

[0157] Algorithm logic: Scan the code line by line, checking if each line begins with a comment marker (such as / / , / *) or ends with a comment marker (such as * / ). For non-Swift files (such as Objective-C .m or .h files), additionally check lines that begin with @ but do not contain a string (such as property declarations). Use regular expressions to match comment patterns to ensure that comment content is not mistaken for localized strings.

[0158] Data processing flow:

[0159] 1.1.1. Read the lines of code and remove leading and trailing whitespace.

[0160] 1.1.2. Use regular expressions (such as ^\s* / / , ^\s* / \*, ^\s*\* / ) to check if it is a comment.

[0161] 1.1.3. If it is a comment, skip the line and do not extract the string.

[0162] Rule Basis: Comments typically do not contain user-visible interface text, therefore localization is unnecessary. The system uses explicit syntax markers ( / / , / *, etc.) to ensure accuracy.

[0163] 1.2 Ignore code blocks:

[0164] Algorithm logic: By analyzing the semantics and structure of code blocks, code segments that do not require localization (such as log output and debugging code) are ignored. The system uses regular expressions to match specific keywords (such as NSLog, print, logEvent) or patterns (such as trackToCode), and combines this with the code block depth (the nesting level of curly braces {}) to determine the scope of the exclusion.

[0165] Data processing flow:

[0166] 1.2.1. Check if the current line contains an ignored pattern (such as NSLog, print).

[0167] 1.2.2. If the ignore pattern is matched, calculate the nesting depth of the curly braces in the current line (depth += line.count("{") - line.count("}")).

[0168] 1.2.3. Continue scanning subsequent lines, decreasing the nesting depth line by line, until the depth reaches zero, indicating the end of the code block.

[0169] 1.2.4. Ignore strings within the entire code block; do not extract or replace them.

[0170] Rule Basis: Logs or debug code are typically used for internal developer diagnostics and do not require translation. The system uses keyword matching and in-depth code block analysis to ensure precise exclusion scope and avoid mishandling.

[0171] 1.3 Language Feature Detection:

[0172] Algorithm logic: Based on file extensions (e.g., .swift, .m, .h) and code syntax characteristics, the algorithm automatically identifies the programming language and loads the corresponding matching rules and replacement templates. For example, Swift code uses the `ly_localizedStringKey` macro, while Objective-C code uses `NSLocalizedString`.

[0173] Data processing flow:

[0174] 1.3.1. Read the file extension to determine the programming language (e.g., .swift for Swift, .m or .h for Objective-C).

[0175] 1.3.2. Load predefined regular expression patterns based on the language type (such as Swift's setTitle call pattern or Objective-C's @ string prefix).

[0176] 1.3.3. Adjust and replace the template to ensure that the generated localized calls conform to the syntax of the target language.

[0177] Rule basis: Different programming languages ​​have different string syntax and localization calling methods. The system improves compatibility by adaptively adjusting the strategy based on file extensions and syntax features.

[0178] 2. Invoking and executing the custom rule engine:

[0179] The custom rules engine allows developers to define matching patterns, replacement templates, and capture groups via JSON configuration files, and apply them dynamically in the "code scanning" and "string replacement" steps. The following is its specific invocation and execution logic:

[0180] 2.1 Calls during code scanning:

[0181] Logic: During the code scanning phase, the multi-pattern matching engine first loads predefined general matching patterns (such as matching strings containing Chinese characters), and then loads user-defined custom patterns (such as the custom_patterns field) defined in config.json. Each custom pattern contains a regular expression (pattern), a replacement template (replacement), and a capture group index (capture_group_index).

[0182] Execution process:

[0183] 2.1.1. Compile all custom pattern regular expressions and cache them to improve performance.

[0184] 2.1.2. Scan the code line by line, using both general and custom patterns for parallel matching to extract strings containing Chinese characters.

[0185] 2.1.3. If the custom pattern matches successfully, extract the specified capture group (such as the group specified by capture_group_index) and record the string and its context information (such as line number and matching position).

[0186] Example: Custom patterns in the configuration file:

[0187] {

[0188] "pattern":"(?:\\w+)\\.setTitle\\s*\\(\\s*\"([^\"]*[\\u4e00-\\u9fff][^\"]*)\"\\s*,\\s*for:\\s*\\.\\w+\\s*\\)",

[0189] "replacement":"\\1.setTitle(\"\\2\".ly_localizedStringKey(\"{key}\"),for:.\\3)",

[0190] "capture_group_index":1

[0191] }

[0192] This pattern matches code like button.setTitle("Chinese Title", for:.normal), captures the Chinese string "Chinese Title", and uses it in subsequent replacements.

[0193] 2.2 Execution in string replacement:

[0194] Logic: In the string replacement phase, the system preferentially applies the matching custom replacement template based on the extracted string and its context. If there is no matching custom rule, the default localization call (such as ly_localizedStringKey or NSLocalizedString) is used.

[0195] Execution process:

[0196] 2.2.1. For each extracted string, check whether the line where it is located matches any custom pattern.

[0197] 2.2.2. If it matches, obtain the corresponding replacement template, and dynamically inject the localization key ({key}) and the captured group content (such as \1, \2).

[0198] 2.2.3. Use the sub method of regular expression to replace the original code line with the new localization call.

[0199] Example: For the code line button.setTitle("Chinese Title", for:.normal), the system performs the following replacement:

[0200] Matching pattern: Capturing group 1 is button, group 2 is Chinese Title, and group 3 is normal.

[0201] Replacement template: \1.setTitle("\2".ly_localizedStringKey("{key}"), for:.\3).

[0202] Assume the localization key is title_key, the replacement result is:

[0203] button.setTitle("Chinese Title".ly_localizedStringKey("title_key"), for:.normal).

[0204] 3. Example of custom rules:

[0205] The following is a complete example of custom rules, showing how it acts on the source code and completes the replacement:

[0206] Source code (Swift file):

[0207] let header = "Welcome to use";

[0208] Custom rules in the configuration file:

[0209] {

[0210] "pattern": "(?:let|var)\\s*(\\w+)\\s*=\\s*\"([^\"]*[\\u4e00-\\u9fff][^\"]*)\"",

[0211] "replacement": "\\1 = \"\\2\".ly_localizedStringKey(\"{key}\")",

[0212] "description": "Match variable assignments like let / var header = \"Chinese\"",

[0213] "capture_group_index": 2

[0214] }

[0215] Processing process:

[0216] 3.1. Code scanning: The regular expression matches let header = "Welcome to use", the capture group 1 is header, and the group 2 is Welcome to use.

[0217] 3.2. Context analysis: Confirm that this line is not a comment or an ignored block, and the string is valid.

[0218] 3.3. String replacement:

[0219] Query the localization mapping table. Assume that the key corresponding to "Welcome to use" is welcome_key.

[0220] Apply the replacement template to generate header = "Welcome to use".ly_localizedStringKey("welcome_key").

[0221] 3.4. Output code:

[0222] let header = "Welcome to use".ly_localizedStringKey("welcome_key").

[0223] 4. Division of labor and cooperation between code scanning and context analysis:

[0224] Division of labor:

[0225] Code scanning: This step is responsible for initially extracting potential localized strings. It uses a multi-pattern matching engine to scan lines of code and match strings containing Chinese characters (such as double quotes or the @ symbol). This step generates a list of candidate strings, including the string content, line number, and match position.

[0226] Context analysis: This step filters invalid strings by identifying comments, ignoring code blocks, and detecting language features to determine which candidate strings need localization. Based on code semantics and the context, it removes unnecessary strings such as comments and log entries.

[0227] Collaboration method:

[0228] Processing flow: Code scanning and context analysis are performed sequentially. First, all strings are scanned, then context analysis is performed line by line. The scanning phase generates a complete list of candidate strings, and the context analysis phase examines the context of each candidate string line by line to determine whether to retain it.

[0229] Dependencies: Context analysis relies on intermediate results provided by the multi-pattern matching engine (such as match positions and line numbers), but it also independently uses regular expressions to check comments and ignore patterns. For example, comment recognition directly checks line content, while code block ignoring combines line number information from the scanning phase to analyze code block depth.

[0230] Implementation logic:

[0231] 4.1. Code scanning: Match regular expressions line by line, extract candidate strings, and record line numbers and context.

[0232] 4.2. Context Analysis: For each candidate string, check whether the line it is located on is a comment or an ignored block, and filter out invalid strings.

[0233] 4.3. Valid strings proceed to the subsequent replacement stage, while invalid strings are discarded.

[0234] Advantages: Serial processing ensures logical separation between scanning and analysis, facilitating debugging and optimization. The scanning phase focuses on efficient extraction, while the analysis phase focuses on precise filtering; the combination of both improves the system's accuracy and robustness.

[0235] 5. Implementation methods for string replacement:

[0236] 5.1 Methods for modifying source code files:

[0237] Method: The system uses a copy replacement approach, which involves reading the source file, generating the modified content, and writing it to a new output file (located in the output_dir configuration). The original source file remains unchanged, avoiding the risks associated with direct modification.

[0238] process:

[0239] 5.1.1. Read all lines of the source file and store them as a list.

[0240] 5.1.2. Process line by line, apply replacement logic, and generate a new list of lines.

[0241] 5.1.3. Write the list of newlines to the output file, with the path based on the relative path of the input file.

[0242] Advantages: Copy replacement ensures code security, supports rollback operations, and facilitates comparison of differences before and after modification.

[0243] 5.2 Ensure the integrity of code formatting:

[0244] Method: The system preserves the original line's indentation, newline characters, and code structure of unmatched parts during replacement, modifying only the matched string portion. The replacement operation is based on the `sub` method of regular expressions, ensuring accurate replacement.

[0245] measure:

[0246] 5.2.1. Use re.sub for local replacement to avoid affecting code outside the string.

[0247] 5.2.2. Preserve the newline characters (such as \n) of the original lines to ensure that the output file format is consistent.

[0248] 5.2.3. For multi-line strings, process them line by line to maintain the hierarchical structure of the code blocks.

[0249] Verification: After the replacement, the system will generate a log, recording the line number and content of each modification. Developers can manually check the format of the output file.

[0250] 5.3 Handling strings containing variables, expressions, or special characters:

[0251] Method: The system uses regular expression capture groups to separate literal parts and dynamic content (such as variables, %s, {0}) from a string. Only the literal parts are replaced, while the dynamic content is preserved.

[0252] Processing logic:

[0253] 5.3.1. When matching strings, capture groups isolate literal and non-literal parts. For example, for let msg = "Welcome %s", capture "Welcome %s" and record the position of %s.

[0254] 5.3.2. During replacement, retain the dynamic content in the capture group and inject the localized key. For example, replace with msg = "welcome%s".ly_localizedStringKey("welcome_key").

[0255] 5.3.3. For escape characters (such as \n, \t), the system correctly processes the escape sequence in the regular expression to ensure that the semantics remain unchanged after replacement.

[0256] Replacement templates support dynamic content: Replacement templates for custom rules support variable injection (such as {key}) and capture group references (such as \\1), allowing dynamic generation of localized calls that conform to the syntax.

[0257] 6. Format and collection of unlocalized string reports:

[0258] Report format:

[0259] File path: missing_strings.txt, located in the same directory as the configuration file.

[0260] Content structure:

[0261] Untranslated or marked strings:

[0262] Newly found untranslated strings:

[0263] File:Classes / ViewController.swift

[0264] Line 10: Welcome!

[0265] Line 15: Confirm

[0266] File:Classes / Model.swift

[0267] -Line 5: Error Message

[0268] Previously marked untranslated strings:

[0269] File:Classes / ViewController.swift

[0270] -Line 20: Save settings

[0271] Information item:

[0272] File path (relative path).

[0273] Line number (the line where the string is located).

[0274] String content (unlocalized Chinese text).

[0275] Classification (newly discovered untranslated strings or previously marked untranslated strings).

[0276] Collection process:

[0277] Step: Unlocalized strings are identified and collected during the "string replacement" phase.

[0278] Logic:

[0279] 6.1. For each extracted string, query the localization mapping table (localization_map).

[0280] 6.2. If the string has no corresponding localization key, record it as an unlocalized string, and store its file path, line number, and content.

[0281] 6.3. If the string has been marked as untranslated (e.g., contains the comment / / ??? :- missing multilingual), record it as a "marked untranslated string".

[0282] Output: After processing, the system aggregates all unlocalized strings and writes them to a report file.

[0283] 7. Natural language description of the data processing logic:

[0284] The following is a natural language description of the data processing logic of the core mechanism, ensuring clarity and comprehensibility:

[0285] Multi-mode matching engine:

[0286] The system first loads the regular expression patterns in the configuration file (such as the pattern for matching Chinese strings). These patterns are pre-compiled and cached to avoid repeated calculations.

[0287] When scanning the code, the system reads the file content line by line and uses regular expressions to match strings containing Chinese (such as "Welcome to use").

[0288] After successful matching, extract the string and its context (such as line number, surrounding code), and generate a list of candidate strings for subsequent analysis and replacement.

[0289] Context-aware processor:

[0290] The system checks the semantics of each line of code to determine whether it needs to be processed. For example, if a line starts with / / , the system recognizes it as a comment and skips it directly.

[0291] For code that may contain logs, the system matches keywords such as NSLog or print and checks the nesting level of curly braces {}, ignoring the entire log code block.

[0292] Based on the file extension (such as.swift or.m), the system selects appropriate matching rules to ensure that the processing method conforms to the syntax of the programming language.

[0293] Custom rule engine:

[0294] Developers define rules in the configuration file, such as the pattern that matches button.setTitle("Chinese", for:.normal).

[0295] During scanning, the system attempts to match these custom patterns and extract Chinese strings (such as "Chinese") and their contexts (such as button, normal).

[0296] During replacement, the system generates new code (such as button.setTitle("Chinese".ly_localizedStringKey("key"), for:.normal)) according to the template in the rule, preserving the structure of the original code.

[0297] String replacement:

[0298] The system reads the source file, processes it line by line, and finds the strings that need to be replaced (such as "Welcome to use").

[0299] Query the localization mapping table to obtain the corresponding key (such as welcome_key). If there is no key, it is marked as unlocalized.

[0300] Use regular expressions to precisely replace the string, generating a new code line while preserving the original format (such as indentation, line breaks).

[0301] Write the modified content to a new file to ensure the security of the original file.

[0302] Unlocalized report:

[0303] During replacement, if the key of the string is not found, the system records it, including the file path (such as Classes / ViewController.swift), line number (such as 10), and string content (such as "Welcome to use").

[0304] After summarizing all unlocalized strings, a report file is generated to facilitate developers to supplement translations.

[0305] In summary, the technology presented in this application can be applied to the multilingual localization (i18n) processing flow in iOS and macOS application development, aiming to improve development efficiency, reduce error rates, and enhance system scalability through automation. This application combines static code analysis, a multi-pattern matching engine, and a context-aware algorithm, enabling efficient handling of localization requirements in complex codebases and making it suitable for large-scale international application development scenarios.

[0306] Compared with the prior art, this application has at least the following beneficial effects:

[0307] 1. Dynamic Template Replacement System: Supports custom capture groups for flexible handling of complex strings. Provides a variable injection mechanism to improve the versatility of replacement templates. Implements context-aware replacement to ensure that the replacement results conform to the code logic.

[0308] 2. Intelligent Ignore Mechanism: A semantically based ignore mode avoids mishandling non-localized content. Supports code block-level ignoring, suitable for nested structures. Provides file type filtering functionality to optimize the processing scope.

[0309] 3. Security Processing System: Implements Unicode standardization, compatible with multiple language character sets. Supports automatic encoding detection to prevent garbled characters. Provides an error isolation mechanism to ensure system stability.

[0310] 4. Scalable Architecture: A plug-in rule engine facilitates feature expansion. It supports hot reloading of patterns, allowing rules to be updated without restarting the system. It provides multi-language extension interfaces to adapt to different development environments.

[0311] In specific application scenarios, actual testing has shown that this application significantly outperforms traditional methods in terms of processing speed, memory usage, and accuracy, while also greatly improving configuration flexibility. Compared to Xcode's genstrings, the system supports more complex syntax, improves accuracy to over 99%, and increases processing speed by approximately 300%.

[0312] Furthermore, the system architecture applied in this application has been successfully implemented in several large-scale iOS projects, improving localization efficiency by an average of 300% and reducing manual intervention by over 90%. Through automated processes, development teams can dedicate more time to core functionality development, significantly improving the development quality and delivery speed of multilingual applications.

[0313] This application solves several technical challenges in traditional localization processes through innovative architecture and algorithm implementation: achieving high-precision recognition of localized strings; developing a zero-configuration automated processing flow to simplify operation steps; building a scalable rule engine to meet diverse needs; and providing complete localization lifecycle management, from scanning to verification. Specifically, this application significantly improves localization efficiency and reduces the possibility of human error through highly automated and intelligent design. The system is applicable to iOS and macOS development environments, but its design philosophy and architecture can also be extended to other platforms and languages.

[0314] like Figure 5 As shown, this application embodiment also provides a code localization conversion device 900, which can implement the above-described method. The device includes:

[0315] The data acquisition module 901 is used to acquire the configuration file; the configuration file includes the scan path, matching rules, ignore mode and replacement template.

[0316] Code loading module 902 is used to load the source code to be converted based on the scan path;

[0317] Capture module 903 is used to extract capture groups and their matching patterns from the source code based on matching rules and ignore patterns; wherein, the code in the source code other than the capture groups is marked as unlocalized to generate an unlocalized string report;

[0318] The localization module 904 is used to make localized calls to the capture group based on the matching pattern and the replacement template, and output localized code.

[0319] In some embodiments, the apparatus further includes:

[0320] The configuration module is used to generate configuration files in response to configuration operations on the target object.

[0321] It is understood that the content of the above method embodiments is applicable to the present device embodiments. The specific functions implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0322] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0323] It is understood that the content of the above method embodiments is applicable to this device embodiment. The specific functions implemented by this device embodiment are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0324] like Figure 6 As shown, Figure 6 The hardware structure of an electronic device 1000 according to another embodiment is illustrated. The electronic device 1000 includes:

[0325] The processor 1001 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (aSIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.

[0326] The memory 1002 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RaM). The memory 1002 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1002 and is called and executed by the processor 1001.

[0327] Input / output interface 1003 is used to implement information input and output;

[0328] The communication interface 1004 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0329] Bus 1005 transmits information between various components of the device (e.g., processor 1001, memory 1002, input / output interface 1003, and communication interface 1004);

[0330] The processor 1001, memory 1002, input / output interface 1003 and communication interface 1004 are connected to each other within the device via bus 1005.

[0331] The electronic device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0332] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.

[0333] It is understood that the content of the above method embodiments is applicable to this storage medium embodiment. The specific functions implemented in this storage medium embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.

[0334] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0335] It is understood that the content of the above method embodiments is applicable to the embodiments of this program product. The specific functions implemented by the embodiments of this program product are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0336] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0337] The code localization conversion method, apparatus, electronic device, storage medium, and program product provided in this application acquire a particle image to be processed, extracts a field of view from the particle image based on a preset selection range, and performs integral projection on the field of view to obtain a one-dimensional sequence group. The field of view includes the target particle to be captured, and the one-dimensional sequence group includes initial one-dimensional sequences in the horizontal and vertical projection directions of the field of view. The initial one-dimensional sequences are weighted and normalized based on the field of view size in the projection directions to obtain a weighted one-dimensional sequence. The weighted one-dimensional sequence is smoothed to obtain a smoothed one-dimensional sequence. Local peaks are marked based on the smoothed one-dimensional sequence to obtain local peak positions. Particle positions are obtained by converting the local peak positions corresponding to the horizontal and vertical projection directions. The code localization conversion of the target particle is then obtained from the field of view based on the particle position. This application provides an efficient, accurate, robust, and automated particle localization and capture method by introducing a weighted normalization step based on the field of view size and combining bidirectional integral projection, sequence smoothing, and local peak detection. This method can effectively overcome the challenges posed by changes in field of view size, image noise, complex backgrounds, and weak contrast, significantly improving the accuracy, efficiency, and reliability of code localization conversion, laying a solid foundation for particle analysis, while also having the advantage of low computational resource consumption.

[0338] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0339] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0340] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0341] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0342] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0343] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0344] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

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

[0346] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0347] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0348] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A code localization conversion method, characterized in that, The method includes the following steps: Obtain the configuration file; wherein the configuration file includes the scan path, matching rules, ignore mode, and replacement template; Based on the scan path, the source code to be converted is loaded; Based on the matching rules and the ignore patterns, capture groups and their matching patterns are extracted from the source code; wherein, code in the source code other than the capture groups is marked as unlocalized to generate an unlocalized string report; Based on the matching pattern, the capture group is called locally according to the replacement template, and localized code is output.

2. The method according to claim 1, characterized in that, The method further includes the following steps: The configuration file is generated in response to the configuration operation of the target object.

3. The method according to claim 1, characterized in that, The matching rules include various regular expressions, and the matching patterns include language features and matching positions. Extracting capture groups and their matching patterns from the source code based on the matching rules and the ignore patterns includes the following steps: The source code is scanned line by line using a first regular expression to identify comments and obtain the comment lines in the source code. Based on the ignored pattern, the semantics and structure of the source code are traversed to obtain the ignored code blocks in the source code; Obtain the file extension of the source code, and determine the programming language type of the source code as the language feature based on the file extension mapping; The capture group is extracted from the source code excluding the comment lines and the ignored code blocks using a second regular expression, and the matching position of the capture group is recorded.

4. The method according to claim 3, characterized in that, The step of scanning the source code line by line using a first regular expression to identify comments and obtain the comment lines in the source code includes the following steps: The source code is scanned line by line using the first regular expression to check whether each line contains the target comment tag; When a line of code contains the target comment marker, the line of code is determined to be the comment line.

5. The method according to claim 3, characterized in that, The step of traversing the semantics and structure of the source code based on the ignored pattern to obtain the ignored code blocks in the source code includes the following steps: Iterate through each line of the source code, taking the currently visited line as the target line. The target line is matched based on the ignore pattern. When the target line contains the ignore pattern, the nesting depth of the target line is obtained. The target line is taken as the first target line. The subsequent lines of the first target line are scanned and the nesting depth is decreased line by line until the nesting depth is zero. The scanned line of code is taken as the second target line. All lines of code from the first target line to the second target line are identified as the ignored code block; Take the next line after the second target line as the target line, and return to execute the step of matching the target line based on the ignore pattern until all lines of code in the source code have been traversed.

6. The method according to claim 3, characterized in that, The step of extracting the capture group from the source code (excluding comment lines and ignored code blocks) using a second regular expression and recording the matching position of the capture group includes the following steps: The second regular expression is used to match strings in the source code other than the comment lines and the ignored code blocks. Based on the successful matching results, the strings and their context information are extracted to obtain the capture group, and the matching position of the strings and their context is recorded.

7. The method according to any one of claims 1 to 6, characterized in that, The replacement template includes a custom template and a default template. The process of performing localized calls on the capture group based on the matching pattern and the replacement template, and outputting localized code, includes the following steps: Based on the matching pattern corresponding to the capture group, the target template is obtained by matching from the custom template; The capture group is called locally based on the target template, and the localized code is output. If the target template is not matched from the custom template, the capture group is called locally according to the default template, and the localized code is output.

8. A code localization conversion device, characterized in that, The device includes: The data acquisition module is used to acquire the configuration file; wherein the configuration file includes the scan path, matching rules, ignore mode and replacement template; The code loading module is used to load the source code to be converted based on the scan path; A capture module is used to extract capture groups and their matching patterns from the source code based on the matching rules and the ignore patterns; wherein, the code in the source code other than the capture groups is marked as unlocalized to generate an unlocalized string report; The localization module is used to make localized calls to the capture group based on the matching pattern and the replacement template, and output localized code.

9. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method according to any one of claims 1 to 7.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 7.