Multiple Languages

Topics: CAB & Smart Client Software Factory
Apr 13, 2006 at 12:47 AM
originally posted by: fballem

In the Bank Branch Workbench, could you please add a multiple language requirement (using Resources)? The language requirement not only applies to forms and smartparts (relatively easy) but also to any error, warning, or information messages that may be produced.

For instance, in HandleException of the application shell, the following code appears:

private static void HandleException(Exception ex)
{
if (ex == null)
return;

ExceptionPolicy.HandleException(ex, "Default Policy");
MessageBox.Show("An unhandled exception occurred, and the application is terminating. For more information, see your Application event log.");
Application.Exit();
}

The message string, in English only, would not be legally acceptable for a product being marketed in Quebec, Canada.

Basically, anyplace where a hard-coded string appears needs to use a string resource. Under SC Bat, what is the most efficient way to structure and use multiple language string based resources?

Many thanks,

Flavelle Ballem
Apr 13, 2006 at 4:26 AM
originally posted by: fballem

Some additional thoughts, based on some initial puttering:

1. Each project has a Properties folder, that contains a file called Resources.resx. This is the ideal location for strings, and is treated as an Invariant culture (will load regardless of the CurrentUICulture setting).

2. Within the project, the Resources that are identified in Resources.resx appear to be typed. For example, if there is a string resource named "UnhandledException", with a value of "An unhandled exception has occurred ...", then the code in the Application Shell for the unhandled exception becomes:

private static void HandleException(Exception ex)
{
if (ex == null)
return;

ExceptionPolicy.HandleException(ex, "Default Policy");
MessageBox.Show(Properties.Resources.UnhandledException);
Application.Exit();
}

IntelliSense works for these resources (no need to identify additional constants to convert a string to a class property).

3. In an ideal world, the developer would be able to right-click on the Properties folder within a project, and be able to add a second, language specific Resource file. In the current implementation of Visual Studio, this is not possible.

4. There is a workaround:
a. Right-click on a project (for example the Application Shell project) and Add New Item.
b. Select Resources file and name it Resources.fr.resx. This will create a Resources file for French.
c. Select OK.
d. This will add Resources.fr.resx in the main directory of the project.
e. Drag and drop Resources.fr.resx into the Properties Folder.
f. Open the original Resources.resx and select all of the resources. Ctrl-C will copy these resources.
g. Open the Resources.fr.resx and paste the copied items.
h. Translate the strings (not the name) in Resources.fr.resx. For testing purposes, just add (French) at the beginning or the end of the string.

5. Once there is one new resource, then it is easy to add additional resources. Highlight one of the new Resource files in property, then copy and paste. A second copy of the resource file will appear as "Copy of Resource.xx.resx". Rename the copied (for example Resources.fr-CA.resx, which is French(Canada)). Translate the resources in this file.

6. In terms of building, the best strategy is probably to build the entire application using Invariant Culture resources first, then when ready for release, add the specific language resources. In developing the application, if you are about to enter a hard-coded string, particularly if a user is going to see it, then it is probably better to use a Resource String.

7. Have not figured out a good strategy for Global Strings (probably a set of items in Common).

I would very much appreciate any insight and guidance as to whether this approach has merit, is there a better, simpler way to achieve the same result, and how to organize this approach better in the context of SC-BAT. Also if the senior members of this forum have any pull with the Visual Studio developers, maybe they could encourage them to provide a simpler mechanism for putting multiple language resources in the Properties of a project (see ugly workaround in notes 3 through 5).

Regards,

Flavelle Ballem
Apr 14, 2006 at 11:00 AM
originally posted by: kozaczynski

Agree on the need to globalize. It will be done before we are finished; it is part of the test exit condition.

Please keep in mind that weekly drops are work-in-progress.
Apr 14, 2006 at 11:12 AM
originally posted by: fballem

Understood - being new to the project, do you have a target as to when it will be more or less completed (recognising that these things are never truly complete).

A couple of small items of follow-up on my prior note:

1. Rather than use Resources.rex in Properties, create a new Resource file (like Strings.resx), which will appear outside of the Properties folder. This new Resource file can then be dragged and dropped into Properties in the Solution Explorer. The strings can be used as Properties.Strings.XX, where XX is the name of one of the strings.

2. I gather that Properties is internal in scope, which means the strings can only be used within the Assembly.

3. In considering the solution to Multiple Languages, anything that makes the Resources easily accessible would be useful (ResourceManager is a pain).