Resource Administrator


The Resource Administrator exists to maintain a complete set of resources in all languages. The emphasis is on maintaining the complete set as opposed to individual languages. Figure 10.1 shows the main screen of the Resource Administrator for the .NET Framework 2.0. (The functionality of the Resource Administrator for the .NET Framework 1.1 is almost the same, with a few differences that exist as a result of the differences between the two frameworks.)

Figure 10.1. Resource Administrator


The TreeView on the left lists the base names of all of the resources. The remainder of the space to the TreeView's right should be familiar if you are using Visual Studio 2005; it is a Resource Editor control that looks and behaves similarly to the Visual Studio 2005 Resource Editor. The Resource Administrator supports the following features:

  • Keeps sets of resources in synch

  • Automatically translates strings, as necessary

  • Is not limited to maintaining resources in resx files

  • Exports resources from one project or format to another project and/or format

  • Can create new resources automatically when new languages are added

  • Provides reports of missing target language resources and resource strings

  • Can automatically add missing target resources and strings

  • Provides the functionality of Visual Studio 2005's Resource Editor to Visual Studio 2003 applications

We look at these features in the following sections.

Keeping Sets of Resources in Synch

Although the resource editor in the Resource Administrator looks and behaves like the Resource Editor in Visual Studio 2005, there are some important differences. The resource editor in the Resource Administrator maintains the complete set of resources for a given base name. So if you have Form1Resources.resx, Form1Resources.fr.resx, and Form1Resources.es.resx (i.e., invariant, French, and Spanish resources), when you add a new string resource to Form1Resources, it adds the same entry to all the resx files. Similarly, if you delete an entry, the same entry is deleted from all resources. In this way, you do not have to make a change to the invariant resource and then manually open the resources for every language to apply the same change to those resources.

The "set" of resources is determined by the languages specified in the Tool, Languages menu option (see Figure 10.2).

Figure 10.2. Setting the Languages in the Resource Administrator


When you add one or more languages, the Resource Administrator can create the necessary resources for those languages for you. Figure 10.3 shows a dialog box offering to add new resources after Spanish and French have been added to the list of languages to support.

Figure 10.3. Automatically Adding New Language Resources


The Resource Administrator provides feedback on missing resources by popping up a panel on the right when one or more resources are missing (see Figure 10.4).

Figure 10.4. One or More Language Resources Missing


You can automatically create the missing resources by right-clicking on the resource in the resources TreeView and selecting "Create missing resource(s)" (see Figure 10.5).

Figure 10.5. Resources Context Menu for Creating Missing Resources


Automatic Translation of Strings

In Chapter 9, "Machine Translation," I created a translation engine that can be used for automatically translating resources. The Resource Administrator can use this engine when maintaining string resources. To turn automatic translation on or off, use the Tools, Automatic Translation menu item. When automatic translation is on, string resources are automatically translated before they are added to the target language resource. This occurs only when adding or editing a string resource. So if you add a new string resource with a value "Bank Account Name", then "Bank Account Name" is added to the invariant resource and "Bankkonto-Name" is added to the German resource. This is particularly useful if you are trying to maintain a pseudo translation. In this scenario, the automatic translation is always perfect because it is simply an algorithm and does not need checking by a human translator. If you were using the Visual Studio Resource Editor, you would have to first add the string to the invariant resource and then open the pseudo translation resource, pseudo translate the string, and add it to the pseudo translation resource (using the same key). This isn't difficult, but it is a human process and it will eventually go wrong (e.g., there could be a typo in the entries' key).

You can enable and disable the list of translators that the translation engine uses by selecting Tools, Translators (see Figure 10.6). Translators are automatically disabled if they fail (because they are unavailable, for example).

Figure 10.6. Enabling and Disabling Translators


If you want to perform an automatic translation on just the pseudo translation and leave the real languages for a human translator, you can disable all the translators except for the pseudo translator.

Resource Administrator Is Not Limited to Maintaining resx Files

In Chapter 12, "Custom Resource Managers," I introduce several new resource managers for providing additional resource manager functionality and maintaining resources in a different format (e.g., in a database). One of the drawbacks of using a format other than resx files is that support for your format is either lower or nonexistent. The Visual Studio Resource Editor maintains resources only for resx files. If you maintain resources in a database, for example, the editor cannot be used. The Resource Administrator, however, is format-agnostic. It uses the IResourcesGovernor and IResourceGovernor interfaces, explained later in this chapter, to maintain resources in any format (including a database). You can set the source that the Resource Administrator uses for resources in Tools, Resources Source (see Figure 10.7).

Figure 10.7. Setting the Source of Resources


The Resources Governor combo box lists three resource governors. A resource governor is a class in the downloadable source that governs or manages resources. The three choices are ResXResourceGovernor (for maintaining resx files), ResourcesResourceGovernor (for maintaining resources files), and DbResourceGovernor (for maintaining resources in a database). The Source Of Resources text box enables you to enter a string identifying the source of the resources. For a file-based resource governor (such as ResXResourceGovernor or ResourcesResourceGovernor), this is the name of an existing folder containing resx files. For a database-based resource governor (such as DbResourceGovernor), this is a valid connection string. The Invariant Language is the ISO 639 code for the language in which the invariant resources are written. This value is relevant only if automatic translation is switched on. Enter the values to find your resources and click OK; the Resource Administrator opens and maintains resources from your source.

Exporting Resources

Change is certain. One of the obstacles holding you back from using a format other than resx files might have been the lack of tools for other formats. Now with the Resource Administrator and the custom resource managers in Chapter 12, this stumbling block is removed and you might want to switch to another format. The Resource Administrator enables you to export resources in one format to another format. Select File, Export... (see Figure 10.8).

Figure 10.8. Exporting Resources to a Different Location or Format


This dialog is similar to the dialog in Figure 10.7, in that it demands a resource governor and a target string. To export to a database, select DbResourcesGovernor and enter a connection string to the database. If the target does not exist, the Resource Administrator will create it. For example, in Figure 10.8, the target is a database and the connection string is for a database called translatedApplication2. So a database called translatedApplication2 will be created, and a table called ResourceSets will be added to the database and filled with all the resources from the current source.

Another use for exporting resources is to allow WinRes to be used for localizing Windows Forms forms. WinRes supports resx and resources files only. If your resources are in a database, WinRes cannot be made to read the resources from your database. One workaround is to export the resources from the database to resx files and ship the resx files to the localizer. When the resx files are returned from the localizer, open them using Resource Administrator and export the resx files to the database.

Integrity Check

The integrity check is a comfort blanket for developers. It looks through the complete set of resources, looking for missing resources or for entries that are present in the invariant language but not in a target language. Select Tools, Integrity Check and answer Yes to the "Perform integrity check on the existence and completeness of language resources?" prompt to get a list of discrepancies (see Figure 10.9).

Figure 10.9. Resource Integrity Check


The Resource Administrator can automatically fix the problems listed by clicking the Fix Problems button.




.NET Internationalization(c) The Developer's Guide to Building Global Windows and Web Applications
.NET Internationalization: The Developers Guide to Building Global Windows and Web Applications
ISBN: 0321341384
EAN: 2147483647
Year: 2006
Pages: 213

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net