Monday, August 11, 2014

Fitting multilungual resources in Visual Studio C++ project in user-friendly manner

Going to I18n with our MFC Visual Studio C++ projects, we were considering several methods for organizing resources, (read here for details):
  1. Language-dependent binary 
  2. One resource DLL for all languages 
  3. One resource DLL per target language 

I bet #2 is the best one, and here is how to organize .rc files and VS projects in the way good both: for machine and for humanity. Good for machine, because:
Good for humanity because:
  • resources for all languages will be capable of manual editing with Visual Studio (thus you can keep resources synchronized among different languages), 
  • It would be possible to edit TEXTINCLUDE from VS GUI.
Plenty of time spent for investigation, reading docs, exploring existing projects and collegial disputes made it possible to get desired structure of VS C++ project and .rc files. This structure might be used as a template for other projects, and even might be an Ariadne's thread in localization labyrinth.

1. File structure

Having multilingual resources in one module means having several resource binaries for each resource ID. This means that we should have all of them in .rc files for one project. The problem is that .rc files are created with different code pages, and one .rc file cannot contain resources for different langguages. It's suggested to include .rc files to root one (refer to INFO: Including RC File in Another RC File with a Different Codepage). But that way we'd loose possibility to edit resources manually from directly VS. It's better just to include all .rc files into VS project. Note that each .rc file needs it's own resource.h file, since VS modifies it when editing.
  • Different language resources are placed in different .rc files with using different code pages.
  • All additional staff like .rc2 files might be included in English .rc file.
  • Each .rc files are included into VS project.
  • Every .rc file has its own resource.h file
  • It's suggested to use Language Identifier Constants for .rc and .h file suffixes, i.e. ja-JP or zh-CN

2. Editing resources from GUI

Given described above project structures, we have developer-friendly way of editing resources from VS GUI, both for resources items like dialogs, menu, etc., and for TEXTNCLUDE sections.

pic 2.1 Editing localized resources from GUI


pic 2.2 Editing TEXTINCLUDE sections from GUI

3. Main .rc file check list

The following WinMerge screenshots show parts of main .rc file containing English resources

pic 3.1 .rс head


pic 3.1 .rс middle



pic 3.1 .rс tail

4. Localized ja-JP.rc file check list

The following WinMerge screenshots depict changes to ja-JP.rc file performed to "integrate" Japanese resource into VS project. Other languages should have the same structure, but with different code page.

pic 4.1 Head of .ja-JP.rc

pic 4.2 Middle of .ja-JP.rc file

pic 4.3 The tail

5. Solving TEXTINCLUDE .rc file section issue

There is a bug in VS2008 resource editor: when editing TEXTINCLUDE from GUI, last character gets eaten, destroying \r\n line sequences. For reference read Cure for broken TEXTINCLUDE section of VC++ resource files. 

As a workaround it's suggested to place this string at the end of TEXTINCLUDE 2 and 3 sections:
 "// Visual studio will eat this line for a long time................................................\0"

No comments:

Post a Comment