| Localization of .NET assemblies |
|
|
|
.NET assemblies are PE files that contain .NET metadata. Metadata contains information about the types used in code, references to other assemblies, list of .NET resources, digital signature, etc. Usually .NET assemblies contain only managed code but you can create assemblies with mixed code as well. Installation of .NET Framework is required to run executable .NET files. The list of resources contains references to resource files. Resource files can be separate files (external resource files), or files, whose images are stored in PE files. A resource file can be a binary .NET resource file, graphic file, text file, etc. External resource files are localized separately.
For example: somefile.exe => somefile.resources.dll. The letter code of a language is inserted to names of localized .NET resources. someresource.resources => someresource.ru.resources. An assembly can contain resources of several languages. Resources of different languages have their own language code in the name. A localized assembly must contain the code that enables loading resource assemblies. Usually the System.Resources.ResourceManager class is used for this purpose. You can find an example of localization using assemblies in the demo samples. In addition to resource assemblies, Radialix 2 can create localized .NET assemblies. If necessary, it can add required resources and embed code for their loading into a localized file automatically. .NET resourcesA standard .NET resource may have different formats, such as binary (- .resources), XML (- .resx), text and others. Regardless of the format, a resource contains a list of properties (fields, IDs, etc) and their values. The user can specify the type of value for properties. The type of string values is not specified. See an example of a resource file in XML (fragment): <data name="Label1.Size" type="System.Drawing.Size, System.Drawing"> <value>109, 13</value> </data> <data name="Label1.TabIndex" type="System.Int32, mscorlib"> <value>15</value> </data> <data name="Label1.Text" xml:space="preserve"> <value>UI Current Culture</value> </data>
A .NET application stores and processes all string data in UNICODE (UTF-8 in resources, USC-2 in code). Files of .NET resources built in a PE file have the binary format. Resources of visual objects and code to load them are generated by the development environment automatically as the user designs a form, or a user control in the form designer. Some properties are not saved to a resource if their values match the default values. However, special properties can be saved to a resource, which are, as a rule, used only by the design environment and ignored by the code of a PE file. Usually, the prefix >> is added to the name of such properties (>> in XML): <data name=">>ColumnHeader6.Name" xml:space="preserve"> <value>ColumnHeader6</value> </data> <data name=">>ColumnHeader6.Type" xml:space="preserve"> <value>System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </data> <data name=">>$this.Name" xml:space="preserve"> <value>MainForm</value> </data> <data name=">>$this.Type" xml:space="preserve"> <value>System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </data>
By default, special properties are labeled as Read-only. The development environment generates the data of a resource and code for its loading dynamically depending on the state of properties. The code for loading a resource of a visual object is created in the InitializeComponent method in the source file of an application as text. Then, source files are compiled to create PE files. The InitializeComponent method is called from the object constructor. The code loads necessary resources on application launch depending on the culture settings of the calling thread (Thread.CurrentThread.CurrentUICulture). If a visual object does not require localization and it is specified in the design environment, the design environment creates a resource with a minimal set of data or does not create it at all. This also means that the code for loading resources is not created either. Of course, the developer can embed his own code into an application but it is not typical. As resources are extracted from a .NET assembly, Radialix 2 analyses classes – ancestors of visual components, interprets the code of the InitializeComponent method and adds missing resources to a project and inserts missing hard-coded elements (H status) to resources themselves. This is necessary to edit properties and update resources correctly. When localized assembles are created, the code for loading resources can be embedded to the created file. This function is not supported for creation of resource assemblies. Strings from stream #USThread #US in metadata of a .NET application contains strings, which are not loaded from resources – an analog of hard-coded strings in a PE file. Strings of stream #US are stored in UNICODE. To extract these strings, you need to tick the Extract Hardcoded Strings checkbox in the File Properties dialog. By default, this option is disabled. Thread #US strings are placed to a relevant section of metadata in the project. Names of these strings represent a hexadecimal value of a string token with prefix 0x. You can localize #US strings only when a localized file is created. Creation of multilingual files is not supported. By default, #US strings are labeled as Read-only (R) because it is not known exactly which strings can be edited. You decide yourself which strings to localize and disable their Read-only status. After creating localized files, you need to make sure the application runs well. .NET form designerRadialix 2 can edit forms and user controls visually, using the standard components of the designer and .NET properties inspector (.NET Framework and its localization packages are required). Because a form resource does not contain all data required for correct creation of a form, the designer tries to create the form by interpreting the code of the InitializeComponent method. If this method does not work, the form is created from data in the resource, and a message about form reconstruction appears in the message window. Similar to the dialog designer, inherited components (components declared in the ancestor class) have an icon in the upper-left corner. Components, which are locked for editing, have an icon. Icons of non-visual components are shown at the bottom of the designer. Using the separator, you can change the height of the area for non-visual components. As you edit, the designer can align and resize controls automatically by snapping controls to the guide lines and to the grid. You can access the designer commands from the context menu, by pressing hot keys, or by using the Form Designer - Alignment and Form Designer - Coordinates toolbars on the main menu. If the toolbars are missing, you can choose to display them from the View menu in the main menu (View>Toolbars). As you edit, the .NET designer adds necessary properties to a resource automatically. The added elements are marked as Added (A). There is no support for adding user controls. Added properties can be deleted in the .NET resource editor. Additionally, you can delete them by selecting the Untranslate and Use original options of the context menu. .NET resource editorThe .NET resource editor is similar to the VCL resource editor. It is displayed on the Resource tab too. You can use the editor to modify resource data directly. This can be useful if a resource has a property, which cannot be modified in the form designer or the property inspector. Direct editing of resource data also helps when a resource cannot be represented visually. The resource editor has these columns:
|