Resource updating method and system for multi-language translation application and storage medium

Through dynamic loading and proxy mechanisms, it solves the problems of slow update speed of multi-language translation applications and plug-in resource management conflicts, achieves real-time resource updates and application stability, and improves user experience.

CN118760459APending Publication Date: 2024-10-11SHENZHEN WANSHENG CULTURE TECH CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410670036.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-28
Publication Date
2024-10-11

Smart Images

  • Figure CN118760459A_ABST
    Figure CN118760459A_ABST
Patent Text Reader

Abstract

The invention provides a resource updating method and system for a multi-language translation application and a storage medium. The resource updating method comprises the steps that a starting operation of an application program is responded; based on a host resource file stored in the terminal, checking whether an update file exists in a server or not; creating a plug-in resource file based on the update file, and reflecting and creating a second resource management object capable of dynamically loading the plug-in resource file; and a third resource management object is defined, the first resource management object is agented through the third resource management object, and a resource loading method of the third resource management object is rewritten so as to realize dynamic loading of the plug-in file resource and the host file resource. According to the method, real-time updating of the resources is achieved, the updating speed of the translation resources is high, the translation problem can be solved in time, dynamic control over the resource loading process is achieved in the mode of using multiple resource management objects, new language translation can be easily added or existing translation can be easily updated, and an application program does not need to be recompiled or published.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software architecture, and in particular to a resource updating method, system and storage medium for a multi-language translation application. Background Art

[0002] In applications that adapt to multi-language translation, every time a response update involving a string is required, an updated version of the application often needs to be re-released. Therefore, the repair of translation issues reported online in the application will be delayed. Each update also requires users to download a new application installation package and reinstall it, affecting the user experience.

[0003] In some multi-language applications, a plug-in approach is used to merge the resource management objects of the application, which can easily lead to conflicts between the resource files in the plug-in and the resource files of the host, which can easily cause crashes. In addition, the merging of resource management objects is often irreversible, and there is a risk of tampering with the acquisition of the original resource management objects.

[0004] Therefore, there is a need for a solution to solve at least one of the above problems. Summary of the invention

[0005] In view of the defects in the prior art, the present application proposes a resource update method, system and storage medium for a multilingual translation application. To solve at least one of the above technical problems, the technical solution of the present application is:

[0006] A resource updating method for a multi-language translation application, comprising:

[0007] Respond to the application's launch operation;

[0008] Using a resource management object capable of dynamically loading a host resource file as a first resource management object, wherein the host resource file is stored in a preset terminal;

[0009] Based on the host resource file, checking whether there is an update file related to the host resource file in the preset server;

[0010] If an update file exists, the update file is obtained from the server and saved to the terminal, a plug-in resource file is created based on the update file, and a second resource management object capable of dynamically loading the plug-in resource file is reflectively created;

[0011] defining a third resource management object, and using the third resource management object as a proxy for the first resource management object;

[0012] The resource loading method of the third resource management object is rewritten to realize dynamic loading of the plug-in resource file and the host resource file.

[0013] In a specific embodiment, the process of checking whether there is an update file in the preset server includes:

[0014] Obtaining a version number of the resource file in the server as a first version number, and obtaining a version number of the host resource file as a second version number;

[0015] Comparing the first version number with the second version number, if the first version number is greater than the second version number, it indicates that there is an update file for the host resource file, and the update file is the resource file in the server;

[0016] If the first version number is not greater than the second version number, it means that there is no update file in the server.

[0017] In a specific embodiment, the process of obtaining the update file from the server and saving it to the terminal, and creating the plug-in resource file based on the update file further includes: determining the integrity of the update file;

[0018] If the hash value of the downloaded update file is the same as the hash value of the update file stored in the server, it means that there is no problem with the integrity of the update file;

[0019] If the hash value of the downloaded update file is different from the hash value of the update file stored in the server, it means that there is a problem with the integrity of the update file, and it is necessary to request the server to send the update file again.

[0020] In a specific embodiment, the process of creating a plug-in resource management object by reflection includes:

[0021] Reflection creates an AssetManager object;

[0022] Specify the file path of the plugin resource file through the addAssetPath.invoke() method, so that the AssetManager object can dynamically load the resources of the plugin resource file;

[0023] The AssetManager object is passed to the constructor of the Resources class to generate the second resource management object.

[0024] In a specific embodiment, a process of defining a third resource management object and proxying the first resource management object through the third resource management object includes:

[0025] The custom third resource management object inherits from the first resource management object;

[0026] Add a member variable to save the first resource management object;

[0027] The getResources() methods at the global level and the project level are rewritten respectively, and the return values ​​are set as the third resource management object respectively.

[0028] In a specific embodiment, the resource loading method includes: a getText() method and a getString() method;

[0029] The process of rewriting the resource loading method of the third resource management object includes:

[0030] Rewrite the getText() method and the getString() method respectively, set the return values ​​of the getText() method and the getString() method to the second resource management object, so as to control the process of obtaining the string by the first resource management object through method hijacking.

[0031] In a specific embodiment, when the plug-in resource file and the host resource file are dynamically loaded,

[0032] The third resource management object preferentially loads the target resource in the plug-in resource file through the method of the second resource management object. If the method of the second resource management object fails to load in the plug-in resource file or the corresponding target resource cannot be found, the corresponding target resource is loaded in the host resource file through the method of the first resource management object.

[0033] In a specific embodiment, the dynamic loading process of the plug-in file resource and the host file resource specifically includes:

[0034] Obtain the type and name of the resource id through the first resource management object;

[0035] Searching for a matching resource ID in the plug-in resource file through the second resource management object;

[0036] The character string in the plug-in resource file is obtained through the second resource management object.

[0037] A resource updating system for a multi-language translation application, used to implement a resource updating method for a multi-language translation application as described in any one of the first part, the system comprising:

[0038] A startup module is used to respond to the startup operation of the application;

[0039] An updating module, used for obtaining the update file from the server and saving it to the terminal;

[0040] A generation module, used for reflectively creating a second resource management object capable of dynamically loading the plug-in resource file resource, and defining a third resource management object;

[0041] The resource loading module is used to rewrite the resource loading method of the third resource management object to realize dynamic loading of the plug-in file resources and the host file resources.

[0042] In a specific embodiment, executable instructions are stored, and when the executable instructions are executed by a processor, the resource updating method of a multi-language translation application described in any one of the first part is implemented.

[0043] Beneficial effects:

[0044] The present invention provides a resource update method, system and storage medium for a multi-language translation application. By checking whether an update file exists on a server and dynamically loading a new resource management object after the application is started, real-time resource update is achieved. The translation resource is updated quickly, which helps to solve translation problems in a timely manner. By using multiple resource management objects, dynamic control of the resource loading process is achieved, and new language translations can be easily added or existing translations can be updated without recompiling or publishing the application.

[0045] Specifically, through proxy and method rewriting, the dynamic loading of host resources and plug-in resources by the application is realized, which can avoid unstable factors such as program crash caused by resource file conflicts generated during the merging of resource management objects. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0047] Figure 1 A schematic diagram of a flow chart of a resource updating method for a multi-language translation application of an embodiment;

[0048] Figure 2 A structural diagram of a plug-in resource file generation method and a host resource file coexistence method in an embodiment;

[0049] Figure 3 It is a diagram of the module composition of the resource update system of the multi-language translation application of the embodiment.

[0050] Reference numerals:

[0051] 1-Start module; 2-Update module; 3-Generate module; 4-Resource loading module. DETAILED DESCRIPTION

[0052] In the following, various embodiments of the present disclosure will be described more fully. The present disclosure may have various embodiments, and adjustments and changes may be made therein. However, it should be understood that there is no intention to limit the various embodiments of the present disclosure to the specific embodiments disclosed herein, but rather the present disclosure should be understood to cover all adjustments, equivalents and / or alternatives that fall within the spirit and scope of the various embodiments of the present disclosure.

[0053] Hereinafter, the terms "include" or "may include" used in various embodiments of the present disclosure indicate the presence of disclosed functions, operations, or elements, and do not limit the addition of one or more functions, operations, or elements. In addition, as used in various embodiments of the present disclosure, the terms "include", "have", and their cognates are intended only to indicate specific features, numbers, steps, operations, elements, components, or a combination of the foregoing, and should not be understood as first excluding the presence of one or more other features, numbers, steps, operations, elements, components, or a combination of the foregoing or the possibility of adding one or more features, numbers, steps, operations, elements, components, or a combination of the foregoing.

[0054] In various embodiments of the present disclosure, the expression "or" or "at least one of A or / and B" includes any combination or all combinations of the words listed at the same time. For example, the expression "A or B" or "at least one of A or / and B" may include A, may include B, or may include both A and B.

[0055] The expressions (such as "first", "second", etc.) used in the various embodiments of the present disclosure may modify the various constituent elements in the various embodiments, but may not limit the corresponding constituent elements. For example, the above expressions do not limit the order and / or importance of the elements. The above expressions are only used for the purpose of distinguishing one element from other elements. For example, the first user device and the second user device indicate different user devices, although both are user devices. For example, without departing from the scope of the various embodiments of the present disclosure, the first element may be referred to as the second element, and similarly, the second element may also be referred to as the first element.

[0056] It should be noted that if it is described that one component element is “connected” to another component element, the first component element may be directly connected to the second component element, and a third component element may be “connected” between the first component element and the second component element. Conversely, when one component element is “directly connected” to another component element, it can be understood that there is no third component element between the first component element and the second component element.

[0057] The term “user” used in various embodiments of the present disclosure may indicate a person using an electronic device or a device (eg, an artificial intelligence electronic device) using the electronic device.

[0058] The terms used in the various embodiments of the present disclosure are only used for the purpose of describing specific embodiments and are not intended to limit the various embodiments of the present disclosure. As used herein, the singular form is intended to also include the plural form, unless the context clearly indicates otherwise. Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meaning as the meanings commonly understood by ordinary technicians in the field to which the various embodiments of the present disclosure belong. The terms (such as the terms defined in the generally used dictionary) will be interpreted as having the same meaning as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized meaning or an overly formal meaning, unless clearly defined in the various embodiments of the present disclosure.

[0059] Example 1

[0060] The present application embodiment proposes a resource update method for a multi-language translation application, such as Figure 1 , Figure 2 As shown, including:

[0061] S100, responding to the start operation of the application program;

[0062] S200, taking a resource management object capable of dynamically loading a host resource file as a first resource management object, and storing the host resource file in a preset terminal;

[0063] The terminal may be, but is not limited to, various computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices;

[0064] S300, based on the host resource file, checking whether there is an update file related to the host resource file in the preset server;

[0065] Host resource files refer to the main resource files in an application or system, usually files that contain the application's text, images, audio, video and other resources. They are usually stored in a specific directory structure and loaded and used by the application at runtime.

[0066] S400, if an update file exists, obtain the update file from the server and save it to the terminal, create a plug-in resource file based on the update file, and reflectively create a second resource management object capable of dynamically loading the plug-in resource file resource;

[0067] Plugin resource files refer to resource files associated with plugin functions. The content of plugin resource files varies depending on the function and purpose of the plugin. Plugin resource files are usually stored in the plugin's directory structure and are managed separately from the host resource files of the main application.

[0068] S500, defining a third resource management object, and using the third resource management object to represent the first resource management object;

[0069] S600, rewriting the resource loading method of the third resource management object to implement dynamic loading of the plug-in resource file and the host resource file.

[0070] In the prior art, conventional translation software adapted to multiple languages ​​usually updates the translation string resources by re-releasing the new version of the application to the application market. Specifically, it is necessary to prepare the translation string file resources of various countries in advance, and then upgrade the iterative version number of the translation software, and then release it to the application market again. If it is not re-released to the application market, users will not be able to obtain the latest application version in time, and thus will not be able to enjoy the latest functions, fixed vulnerabilities, and updated content. Since the preparation cycle and release cycle of the new version are long, it is easy to have the problem of untimely resource updates, and users are required to manually download and install the updates, which will affect the user experience.

[0071] Some multilingual translation software can update translation string resources through plug-in methods. The specific process includes: creating a plug-in resource file containing new translation content and update logic, and storing it in the terminal; reflecting and merging the plug-in resource file and the existing resource management object of the application into the same new resource management object, and obtaining the resources in the resource file through this new resource management object; under this method, although no manual operation by the user is required, the host resources and the plug-in resources need to be merged. When the resource file of the plug-in conflicts with the resource file of the host, it is easy to crash; the original resource management object in the application will be completely modified, which is highly invasive. There is a risk of tampering with the acquisition of the original resources, and the failure of resource file fusion is irreversible, which may lead to the complete loss of the original application function.

[0072] It can be understood that by creating a second resource management object that can dynamically load the plug-in resource file and obtain the string in the plug-in resource file through plug-in reflection, and then proxying the first resource management object through the third resource management object and rewriting the resource loading method of the third resource management object, flexible and dynamic loading and calling of the strings of the plug-in resource file and the host resource file are realized; the problem of slow update of string resources in multi-national language translation applications and the need to release iterative versions again for each update is solved; the plug-in method of reflection modification and merging of resource management objects is solved, which is easy to cause resource conflicts between plug-in resource files and host resource files, and the risk of tampering with the original resource management objects. The original resource files and resource management objects can be kept unchanged. When the update fails, the original functions will not be lost, and it has fallback.

[0073] Furthermore, the process of checking whether the update file exists in the server includes:

[0074] Get the version number of the resource file in the server and the version number of the host resource file;

[0075] The version number of the server's resource file is used as the first version number, and the version number of the host's resource file is used as the second version number;

[0076] Compare the first version number with the second version number. If the first version number is greater than the second version number, it indicates that there is an update file for the host resource file, and the update file is a resource file in the server.

[0077] If the first version number is not greater than the second version number, it means that there is no update file in the server.

[0078] Specifically, if the first version number is greater than the second version number, it means that the resource file of the server is a newer version than the host resource file, that is, the application has updated resources; if the first version number is less than or equal to the second version number, it means that the resource file cached by the terminal is already the latest version and there is no need to download the resource file stored on the server;

[0079] By obtaining the version number and comparing the version numbers, the process of determining whether a resource is an updated resource and whether the resource needs to be updated is simplified, which helps to avoid waste and occupation of resources and improves update efficiency.

[0080] Furthermore, the process of obtaining the update file from the server and saving it to the terminal, and creating the plug-in resource file based on the update file, further includes: judging the integrity of the update file;

[0081] If the hash value of the downloaded update file is the same as the hash value of the update file stored on the server, it means that there is no problem with the integrity of the update file;

[0082] If the hash value of the downloaded update file is different from the hash value of the update file stored on the server, it means that there is a problem with the integrity of the update file, and it is necessary to request the server to send the update file again.

[0083] Specifically, the integrity of the downloaded update file is verified by the hash value. The hash value of the update file is generated on the server and transmitted to the terminal together with the update file. After the update file is downloaded, the hash value of the update file is calculated using the same hash algorithm and compared with the hash value transmitted by the server. If the two hash values ​​match, it can be determined that the update file has not been tampered with during the transmission process, so the update file is complete; if the hash values ​​do not match, it means that the update file may have been tampered with or damaged, and needs to be downloaded again or processed in other ways.

[0084] Optionally, the hash algorithm may use any one of MD5, SHA-1, and SHA-256.

[0085] Furthermore, the process of reflecting and creating a plug-in resource management object includes:

[0086] Reflection creates an AssetManager object;

[0087] Reflection is a mechanism for dynamically obtaining and using class information and calling class methods at runtime. In Java, the reflection API (Application Programming Interface) allows programs to check the structure of classes, obtain class attributes and method information, call class methods, and create object instances at runtime. This capability allows Java programs to operate on these classes through reflection when certain classes are unknown or inaccessible at compile time.

[0088] Since the constructor of AssetManager is private, it cannot be instantiated directly using the new keyword. You need to obtain the constructor of the AssetManager class through reflection and then use the constructor to create an AssetManager object.

[0089] Specify the file path of the plugin resource file through the addAssetPath.invoke() method, so that the AssetManager object can dynamically load the resources of the plugin resource file;

[0090] addAssetPath.invoke() can be used to dynamically specify the loading path of resource files, allowing one or more resource paths to be added to the AssetManager so that the AssetManager can access the resource files under these paths.

[0091] Pass the AssetManager object to the constructor of the Resources class to generate a second resource management object.

[0092] Among them, in Android development, AssetManager is a class used to access the resource files of an application; it provides the ability to access resource files stored inside an application, such as text files, image files, audio files, etc.; AssetManager can be used to read files in the application's directory, and these files are usually packaged in the APK (Android Package is the standard package file format for Android applications) file when the application is installed. Resources is a class used to access various resources of an application, providing a convenient way to obtain resources in an application, such as layout files, strings, colors, images, etc.; the Resources class is obtained through the getResources() method of the Context object.

[0093] If Resources wants to access the resources in the plug-in, it needs to use an AssetManager object pointing to the plug-in resources. The AssetManager object needs to point to the plug-in resource file through the addAssetPath.invoke() method.

[0094] Through the above method, the application can dynamically load the plug-in resource file at runtime without including it in the original resources of the application, thus realizing plug-in development and making the application's functions more flexible and extensible; separating the plug-in resource file from the application can reduce the size of the application's installation package, reduce the cost for users to download and install the application, and also reduce the frequency of application updates; separating the resource management logic from the application's code allows the application to manage and use resource files more flexibly, while also facilitating future functional expansion and improvement.

[0095] Furthermore, a third resource management object is defined, and a process of using the third resource management object as a proxy for the first resource management object includes:

[0096] The custom third resource management object inherits from the first resource management object;

[0097] The third resource management object can directly inherit the function of the first resource management object, thereby reducing the work of repeatedly writing basic functions, and can also maintain compatibility with the original functions, and can be expanded on the basis of the original functions to achieve more customized functions.

[0098] Add a member variable to save the first resource management object;

[0099] The first resource management object can be easily accessed in the third resource management object, thereby achieving more flexible resource management. For example, when the third resource management object needs to call certain methods or properties in the first resource management object, it only needs to access the member variables that store the first resource management object.

[0100] The getResources() methods of the global level (Application) Context and the project level (Activity) Context are rewritten respectively, and the return values ​​are set to the third resource management object respectively, thereby realizing the proxy of the third resource management object to the first resource management object.

[0101] By proxying the first resource management object through the third resource management object, the source of resources can be expanded to plug-in resources rather than being limited to the resources that come with the application. Resources can be managed more flexibly, thereby improving the adaptability of the application. By encapsulating and isolating resource management objects, the modularity of the code can be improved, and the coupling between modules can be reduced, thereby improving the maintainability and scalability of the code.

[0102] In software design, proxy is a structural design pattern used to provide indirect access to other objects. The proxy object controls access to the actual object and can add additional functionality when accessing it. In proxy mode, the proxy object can control access to the actual object, such as restricting access to certain methods or properties; the proxy object can add additional functionality when accessing the actual object, such as logging, caching, security checks, etc.; the proxy object can improve performance through techniques such as caching or lazy loading, such as lazy loading to reduce startup time when accessing expensive resources; the proxy object can provide a simplified interface for the client, hiding the complexity of the actual object; the proxy object can decouple the client code from the actual object, making the system easier to expand and maintain.

[0103] Specifically, in some embodiments of the present application, by overriding the getResources() method of Application and Activity, a customized third resource management object is returned internally. In this way, when the getResources() method is used in the entire application, the method of the customized third resource management object will be used instead of the method of the original first resource management object. In this way, the resource acquisition behavior can be customized to meet specific needs or realize specific functions.

[0104] Furthermore, the resource loading method includes: getText() method and getString() method;

[0105] getText() and getString() are two common methods used to obtain resource strings in Android;

[0106] The process of rewriting the resource loading method of the third resource management object includes:

[0107] Rewrite the resource loading methods getText() and getString() respectively, set the return values ​​of the getText() method and the getString() method to the second resource management object respectively, so as to control the process of obtaining the string by the first resource management object through method hijacking.

[0108] Method hijacking is a programming technique that is often used to modify or replace the behavior of existing methods at runtime; it allows programmers to intercept method calls and insert custom code logic before, after, or in the middle of method execution; method hijacking is usually implemented through technologies such as proxies, decorators, or AOP (aspect-oriented programming). The original method is "hijacked" instead of being completely replaced, which means that the basic functionality of the original method still exists, but its behavior can be enhanced or modified by adding additional logic.

[0109] By proxying the first resource management object through the third resource management object and overriding the getText() method and getString() method of the third resource management object, the specific process of resource loading can be controlled, and the source of resources can be dynamically switched, making the system easier to expand and maintain.

[0110] For example, if the Activity obtains a string through the context.getResources().getString(id) method, it uses the method of the original resource management object, that is, the method of the first resource management object. We can cleverly intercept this method, which is essentially to let it obtain the string through the DynamicResources.dynamicGetString(id) method of the second resource management object.

[0111] The above method enables the newer resource content in the plug-in resource file to be loaded first during string search instead of directly accessing the host resource file, and at the same time retains the resource loading and resource acquisition methods of the first resource management object and the second resource management object, without affecting the content of the first resource management object and the second resource management object, thereby enhancing the scalability of the application and effectively avoiding conflicts between the host resource file and the plug-in resource file caused by the merging of the host resource management object and the plug-in resource management object, thereby reducing the possibility of application crashes and enhancing the stability and reliability of the application.

[0112] Furthermore, when dynamically loading plugin resource files and host resource files,

[0113] The third resource management object preferentially loads the target resource in the plug-in resource file through the method of the second resource management object. If the method of the second resource management object fails to load in the plug-in resource file or cannot find the corresponding target resource, the corresponding target resource is loaded from the host resource file through the method of the first resource management object.

[0114] Prioritize trying to load the plug-in resource file target resource through the second resource management object, so that the system can easily expand functions or customize; and the plug-in resource file is generated based on the update file, which is a newer resource, which helps to implement the update of the application without changing the content of the original host resource file.

[0115] When the second resource management object fails to load in the plug-in resource file or cannot find the corresponding target resource, for example, the plug-in resource file is unavailable, a specific resource is missing, or there is no corresponding updated string content, the system can fall back to the host resource file for search; it has strong flexibility, which helps to use it in the development process and can be easily tested and deployed in different environments. For example, when the plug-in resource file is erroneous, damaged, or not installed, the application can still run normally and can automatically fall back to the host resource, which enhances the fault tolerance of the application, thereby increasing the reliability and availability of the system, reducing application crashes or exceptions caused by problems with plug-ins or plug-in resource files, thereby reducing security risks; under this mechanism, it also helps to maintain the stability of host resources and simplifies maintenance work.

[0116] Furthermore, the dynamic loading process of the plug-in file resources and the host file resources specifically includes:

[0117] Obtain the type and name of the resource id through the first resource management object;

[0118] Searching for a matching resource ID in the plug-in resource file through the second resource management object;

[0119] The string in the plug-in resource file is obtained through the second resource management object.

[0120] Specifically, the first step is to obtain the type of resource id through the getResourceTypeName() method; the second step is to obtain the name of the resource id through the getResourceEntryName() method; the third step is to find the matching resource id in the plug-in resource file through the getIdentifier() method of the second resource management object; the last step is to obtain the string in the external resource package through the getString(id) method of the second resource management object.

[0121] The getResourceTypeName() method is a method in Android (Android system) that is used to obtain the type name of a resource and return the name of the resource type specified in the resource identifier (Resource Identifier). Usually, resource types include anim, color, drawable, layout, string, etc.

[0122] The getResourceEntryName() method is a method in Android that is used to obtain the entry name (Entry Name) of a resource and return the name of the resource specified in the resource identifier (Resource Identifier), that is, the resource type and package name are removed.

[0123] The getIdentifier() method is a method in the Resources class, which is used to obtain the resource identifier (Resource Identifier); it needs to accept three parameters: name (the name of the resource, that is, the part without the resource type and package name), defType (the type of resource, such as drawable, string, layout, etc.), and defPackage (the package name where the resource is located); this method will return the integer identifier of the corresponding resource based on the provided resource name, type, and package name. If the corresponding resource is not found, it returns 0. Normally, the getIdentifier() method is used to dynamically obtain the resource identifier at runtime, so that the resource can be dynamically loaded or processed according to the resource name.

[0124] getString(id) is a commonly used method in Android, used to get a string from a resource file. It accepts an integer parameter id, which is a reference to the string resource to be obtained.

[0125] The above steps allow you to dynamically obtain string resources in the plugin resource file at runtime without hard-coding these updated resources into the application at compile time. You can flexibly add, modify, or delete string resources without affecting the stability of the application.

[0126] By using the second resource management object, the application can support plug-inization, and the plug-in can contain its own string resource file, which can help the application dynamically load the string resources in the plug-in at runtime. Placing updated string resources in the plug-in resource file can reduce the size of the application. These resources no longer need to be directly packaged into the application's APK, but can be distributed as a separate resource package, thereby reducing the size of the application's installation package.

[0127] The embodiment of the present application also proposes a resource update system for a multi-language translation application, which is used to implement the resource update method for a multi-language translation application. Figure 3 As shown, the system includes:

[0128] The startup module 1 is used to respond to the startup operation of the application program;

[0129] Update module 2, used to obtain update files from the server and save them to the terminal;

[0130] Generate module 3, used for reflectively creating a second resource management object capable of dynamically loading plug-in resource file resources, and customizing a third resource management object;

[0131] The resource loading module 4 is used to rewrite the resource loading method of the third resource management object to realize dynamic loading of the plug-in file resources and the host file resources.

[0132] The embodiment of the present application also proposes a storage medium storing executable instructions, which, when executed by a processor, implements a resource update method for a multi-language translation application in the first part.

[0133] The embodiments of the present application have at least the following beneficial effects:

[0134] By checking whether there are update files in the server, the latest resource files can be obtained in time, so that the application always has the latest translation resources and functions, and the application's resource update and modification speeds are fast; by dynamically loading plug-in resource files, the application can be flexibly expanded, allowing new translation languages ​​or functional modules to be added without modifying the core code of the application, and there is no need to merge the plug-in resource management object with the host resource management object, which can avoid possible conflicts between the plug-in resource file and the host resource file during the merging process. After the resources are updated, it will not affect the user's normal use, thereby optimizing the user experience.

[0135] Those skilled in the art will appreciate that the modules in the device in the implementation scenario can be distributed in the device in the implementation scenario according to the implementation scenario description, or can be changed accordingly and located in one or more devices different from the implementation scenario. The modules in the above implementation scenario can be combined into one module, or can be further split into multiple sub-modules.

[0136] The above serial numbers of the present invention are only for description and do not represent the advantages or disadvantages of the implementation scenarios.

[0137] Disclosed above are only several specific implementation scenarios of the present invention, but the present invention is not limited thereto, and any changes that can be conceived by those skilled in the art should fall within the protection scope of the present invention.

Claims

1. A resource updating method for a multi-language translation application, characterized in that: include: Respond to the application's launch operation; Using a resource management object capable of dynamically loading a host resource file as a first resource management object, wherein the host resource file is stored in a preset terminal; Based on the host resource file, checking whether there is an update file related to the host resource file in the preset server; If an update file exists, the update file is obtained from the server and saved to the terminal, a plug-in resource file is created based on the update file, and a second resource management object capable of dynamically loading the plug-in resource file is reflectively created; defining a third resource management object, and using the third resource management object as a proxy for the first resource management object; The resource loading method of the third resource management object is rewritten to realize dynamic loading of the plug-in resource file and the host resource file.

2. The resource updating method for a multi-language translation application according to claim 1, characterized in that: The process of checking whether the update file exists in the preset server includes: Obtaining a version number of the resource file in the server as a first version number, and obtaining a version number of the host resource file as a second version number; Comparing the first version number with the second version number, if the first version number is greater than the second version number, it indicates that there is an update file for the host resource file, and the update file is the resource file in the server; If the first version number is not greater than the second version number, it means that there is no update file in the server.

3. The resource updating method for a multi-language translation application according to claim 1, characterized in that: The process of obtaining the update file from the server and saving it to the terminal, and creating a plug-in resource file based on the update file, further includes: determining the integrity of the update file; If the hash value of the downloaded update file is the same as the hash value of the update file stored in the server, it means that there is no problem with the integrity of the update file; If the hash value of the downloaded update file is different from the hash value of the update file stored in the server, it means that there is a problem with the integrity of the update file, and it is necessary to request the server to send the update file again.

4. The resource updating method for a multi-language translation application according to claim 1, characterized in that: The process of creating a plug-in resource management object through reflection includes: Reflection creates an AssetManager object; Specify the file path of the plugin resource file through the addAssetPath.invoke() method, so that the AssetManager object can dynamically load the resources of the plugin resource file; The AssetManager object is passed to the constructor of the Resources class to generate the second resource management object.

5. The resource updating method for a multi-language translation application according to claim 1, characterized in that: The process of defining a third resource management object and proxying the first resource management object through the third resource management object includes: The custom third resource management object inherits from the first resource management object; Add a member variable to save the first resource management object; The getResources() methods at the global level and the project level are rewritten respectively, and the return values ​​are set as the third resource management object respectively.

6. The resource updating method for a multi-language translation application according to claim 5, characterized in that: The resource loading method includes: getText() method and getString() method; The process of rewriting the resource loading method of the third resource management object includes: Rewrite the getText() method and the getString() method respectively, set the return values ​​of the getText() method and the getString() method to the second resource management object, so as to control the process of obtaining the string by the first resource management object through method hijacking.

7. The resource updating method for a multi-language translation application according to claim 1, characterized in that: When dynamically loading the plug-in resource file and the host resource file, The third resource management object preferentially loads the target resource in the plug-in resource file through the method of the second resource management object. If the method of the second resource management object fails to load in the plug-in resource file or the corresponding target resource cannot be found, the corresponding target resource is loaded in the host resource file through the method of the first resource management object.

8. The resource updating method for a multi-language translation application according to claim 1, characterized in that: The dynamic loading process of the plug-in file resource and the host file resource specifically includes: Obtain the type and name of the resource id through the first resource management object; Searching for a matching resource ID in the plug-in resource file through the second resource management object; The character string in the plug-in resource file is obtained through the second resource management object.

9. A resource updating system for a multi-language translation application, characterized in that: A resource updating method for implementing a multilingual translation application as claimed in any one of claims 1 to 8, the system comprising: A startup module is used to respond to the startup operation of the application; An updating module, used for obtaining the update file from the server and saving it to the terminal; A generation module, used for reflectively creating a second resource management object capable of dynamically loading the plug-in resource file resource, and defining a third resource management object; The resource loading module is used to rewrite the resource loading method of the third resource management object to realize dynamic loading of the plug-in file resources and the host file resources.

10. A storage medium, characterized in that: Executable instructions are stored, and when the executable instructions are executed by a processor, a resource updating method for a multi-language translation application as claimed in any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Input method customization method and system, intelligent terminal and storage medium

    CN118963565A

  • Input method customization method, system, intelligent terminal and storage medium

    CN118963565B

  • Equipment function extension method and device, electronic equipment and storage medium

    CN121603529A