| Localization of PE32/PE32+ files - Resource library |
|
|
|
|
JPAGE_CURRENT_OF_TOTAL
Resource libraryTo localize using resource libraries, the user is required to create a separate library for each translation language. The name of a localized file is used for the name of a resource library file, and the extension is set based on the letter code of a language in Windows (en, de, ru, etc.). The localized program must have a field to store a resource module descriptor. This field is used as a parameter in all above mentioned functions. In the beginning, this field is initiated by the descriptor value of the executable module itself. Then, the required resource library is loaded if it is necessary to use localized resources. The extension of the library name is made by the language code of the current thread, or language code, defined by the user with the help of the “GetLocaleInfo” function. Once the library has been loaded, the descriptor of the loaded library is saved to the descriptor field. After this, all functions will get resources from the new module. This method of loading localized Win32/MFC resources is considered typical. Therefore when you localize such applications, it is recommended to follow the rule below: Resource libraries must contain all resources of the original file. Otherwise, the resource may not be found and the localized application will run incorrectly (not a single resource type or resource should have the status Ignore). Localization using resource libraries is perfect to make a dynamic switch of the application language during its run-time (an example of this application is available in the demo samples). If the user, for example, makes a language switch using multilingual files, then it’ll be necessary to use the functions that get the language code, which is not always convenient. To switch languages, the loaded resource library must be unloaded, a new library must be loaded and the descriptor field is initiated by the descriptor value of the loaded resource module. The original module contains language resources, used by the application author. As a rule, it is English (English is recommended as it is easier to find a translator from English to any other language than vice versa). To switch to the language of the original module, it is necessary to make the descriptor field of the resource module equal to the descriptor value of the original module, then the resource library can be unloaded. If the application contains several modules (for example, an executable file and several DLLs), it is necessary to create resource libraries for each module and the application must have a separate resource descriptor field for each module. The fields and descriptors of original modules can be organized into a list for convenience. PE files, made with the VCL library (Delphi/C++Builder), support automatic loading of the resource library for the current interface language on application launch. There is no need to add any extra code to the application to enable this feature. Also, there is no need to save all resources to the library as VCL searches for resources in the executable module. Typically .NET applications can also load resource assemblies on application launch (a resource assembly is a PE file, an analog of a resource library). Resource assemblies are loaded on application launch for forms, which are labeled as Localizable. |