Skip to main content

Rigi Documentation

Windows Resource Script (RC) Parser

Parser ID: rc.

The RC parser is used for localizing the resource script files (.rc) for Win32 and MFC applications. The source texts are read from one resource script, and a resource script is generated for each target language.

Extensions: .rc,  .rc2,  .dlg.

Key features:

  • Reads localizable texts from the STRINGTABLE, DIALOG, DIALOGEX, MENU, MENUEX and VERSIONINFO resources.

  • Generates target files in which the only difference from the source file is that the original source-language texts are translated.Comments, preprocessor statements, styles, coordinates, accelerators, bitmaps and all other resources are copied unchanged. The target file therefore remains a valid resource script that can be compiled with rc.exe.

  • Auto-encoding. The RC parser supports:

    • UTF-16 with and without byte-order-mark.

    • UTF-8 with and without byte-order-mark.

    • single-byte code pages.

    The #pragma code_page statement in the source file is taken into account.

  • Writes the statements that declare the language of the resources in the target file: LANGUAGE, #pragma code_page, and the MFC symbol AFX_TARG_xxx.

  • Resolves both forms of an escaped double quote accepted by the resource compiler ("" and \").

  • Concatenates adjacent string literals, even when they span multiple lines.

  • Skips the TEXTINCLUDE and DESIGNINFO resources that are only used by the Visual Studio resource editor (#ifdef APSTUDIO_INVOKED).

  • Stores the developer comments as a note for the translator.

  • Aligns translations from resource scripts that have been translated outside Rigi.

  • Creates a unique string ID (for example, .NR1, .NR2, etc.) if a resource script contains the same ID more than once.

Table 17. Supported resources

Resource

Texts that are read

Texts that are not read

STRINGTABLE

All strings.

–

DIALOG

DIALOGEX

CAPTION and the texts of these control statements LTEXT, RTEXT, CTEXT, PUSHBUTTON, DEFPUSHBUTTON, PUSHBOX, CHECKBOX, AUTOCHECKBOX, STATE3, AUTO3STATE, RADIOBUTTON, AUTORADIOBUTTON, GROUPBOX and CONTROL.

The name of the font (FONT), the name of an icon or a bitmap (ICON), the window class of a CONTROL, and the controls that have no text (EDITTEXT, COMBOBOX, LISTBOX, SCROLLBAR).

MENU

MENUEX

The texts of POPUP and MENUITEM.

MENUITEM SEPARATOR.

VERSIONINFO

The values of the localizable keys (for details, see the versionInfoKeys setting below).

The keys that identify the binary, e.g., CompanyName, FileVersion and Translation.


Resources that do not contain UI texts, such as ACCELERATORS, BITMAP, ICON, CURSOR, RCDATA, TOOLBAR, MESSAGETABLE, TEXTINCLUDE, DESIGNINFO and DLGINIT, are not read.

Empty strings ("") are also not read. The parser copies them unchanged.

String IDs

The string ID is built from the resource name and the ID of the string within that resource.

Example 25.
STRINGTABLE.IDS_APP_TITLE            My Application
STRINGTABLE.IDS_WELCOME              Welcome, %s!
IDD_ABOUTBOX.CAPTION                 About My Application
IDD_ABOUTBOX.IDOK                    OK
IDD_ABOUTBOX.IDC_CHECK_HIDE          Do not show this dialog again
IDD_ABOUTBOX.IDC_STATIC.2            My Application, Version 1.0
IDR_MAINFRAME.POPUP1                 &File
IDR_MAINFRAME.ID_FILE_NEW            &New\tCtrl+N
VS_VERSION_INFO.FileDescription      My Application
  • String table. The resource name STRINGTABLE. is followed by the ID of the string, e.g., STRINGTABLE.IDS_APP_TITLE.

  • Dialog. The name of the dialog is followed by CAPTION for the title of the dialog, e.g., IDD_ABOUTBOX.CAPTION, or by the ID of the control for the texts of the controls, e.g., IDD_ABOUTBOX.IDOK.

  • Unnamed controls. A control that the application does not address has no unique ID: IDC_STATIC, -1, 0 and 65535 occur several times in the same dialog. For those controls, the control's position in the dialog is added, e.g., IDD_ABOUTBOX.IDC_STATIC.2 for the second control of the dialog.

  • Menu. The name of the menu is followed by the ID of the menu item, e.g., IDR_MAINFRAME.ID_FILE_NEW. A popup has no ID, so the position of the popup in the menu is used, e.g., IDR_MAINFRAME.POPUP1.

  • Version info. The resource name is followed by the key, e.g., VS_VERSION_INFO.FileDescription.


Important

String IDs are derived from the structure of the resource script and not from the position of a text in the file. Therefore, inserting a string, control, or menu item does not change the IDs of other texts. Also, translations created outside Rigi can be aligned from an existing translated resource script.

Escape sequences

In the Resource Compiler, there are two valid formats for entering a double quote inside a string: "" and \". Both are resolved when the compiler reads a string, so the translator only sees the text itself.

IDS_QUOTED   "Press the ""OK"" button to continue"   -->   Press the "OK" button to continue

All other escape sequences (\n, \t, \\, \xhh) remain as written, so the translator can keep the same sequences. Use the unescapeEscapeSequences setting to resolve these sequences into the characters they represent.

A carriage return or a line feed in a translation is always written as an escape sequence, because the Resource Compiler does not accept multi-line strings.

Long strings

The Resource Compiler concatenates adjacent string literals. A long string is often written as several literals, and the string ID can be on the line above the string:

STRINGTABLE
BEGIN
    IDS_LONG_MESSAGE        "This message is stored in two literals, "
                            "because it does not fit on a single line."
    IDS_APPROVE_PLAN
    "Approving the plan will approve the structure set too.\nContinue anyway?"
END

The parser reads strings of this kind as one text. When the target file is generated, the complete translation is written in the first literal, and the other literals are written as an empty string, so that the source file lines keep their layout.

Encoding

The source file encoding is detected in the following order:

  1. The code page stated in the codepage setting, if it is not 0.

  2. The byte-order-mark set for the file (UTF-8, UTF-16 LE, UTF-16 BE).

  3. UTF-16 without byte-order-mark.

  4. The #pragma code_page(...) statement in the file.

  5. UTF-8 without byte-order-mark.

By default, the target files are written as UTF-16 with byte-order mark. The Resource Compiler supports that encoding, and guarantees that all translated characters and Rigi signatures are written correctly, regardless of the source file's code page.

The target files have the same line endings as the source file.

Use the unicodeTarget parser setting to write the target files with the same encoding as the source file.

Target file language

The Resource Compiler stores the language of the LANGUAGE statement with every resource that follows it. The application uses that language to select its resources at runtime. For this reason, a target file must declare the target language, not the source language. The parser writes three statements for the target locale:

  • The LANGUAGE element gets the language and the sublanguage of the target locale, e.g., LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED for zh-CN. If the locale has no name for its language or sublanguage, the numeric form is written, e.g., LANGUAGE 0x1a, 0x03. The Resource Compiler accepts both forms.

  • The #pragma code_page element gets the code page of the target file, or DEFAULT if the target file is written as UTF-16. The Resource Compiler then uses the file's byte-order mark.

  • The MFC symbol AFX_TARG_xxx gets the three-letter abbreviation that Windows uses for the target language, e.g., AFX_TARG_CHS for zh-CN. An MFC application that loads its resources from a satellite resource DLL uses that symbol to select the language resources. This symbol is also written in the copies of the preprocessor statements inside the TEXTINCLUDE resources.

These statements can be switched off using the updateLanguageStatement, syncCodePagePragma, or updateAfxTargetSymbol parser settings.

Example 26.

Source file

LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)

Target file for ja-JP

LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
#pragma code_page(DEFAULT)
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_JPN)

Dialog layouts

Warning

The parser replaces the resource script texts without changing the dialog layout. A translation that is longer than the source text does not resize the control that shows it, and it does not move the controls next to it.

Target file names

The default target rule adds the target locale to the name of the file:

$(sourceFilePath)/$(sourceFileNameNoExtNoLocale).$(targetLocale)$(sourceFileExt)

You can use other conventions that are commonly used for resource scripts. See the examples for the source file res/EVAL.rc and the target locale ja-JP below:

Target rule

Target file

$(sourceFilePath)/$(sourceFileNameNoExt)$(targetLocale)$(sourceFileExt)

res/EVALja-JP.rc

$(sourceFilePath)/$(sourceFileNameNoExt)$(targetLocalexxx)$(sourceFileExt)

res/EVALjpn.rc

$(sourceFilePath)/$(targetLocale)/$(sourceFileName)

res/EVALjpn.rc

Placeholders

The parser protects the following patterns from being translated or from Rigi signatures being written inside them:

  • %%.

  • The insert sequences of FormatMessage: %1, %2, %1!s!.

  • The format specifiers of the C runtime: %s, %d, %lu, %I64d, %10s, %05d, %8.2f.

  • The escape sequences of the Resource Compiler: \n, \r, \t, \a, \b.

  • $(variable) and {0.

Important

The left-justify flag of a format specifier (%-10s) is not recognized, because this pattern also occurs inside a Rigi signature that is present in the alphanumeric format. If your application uses it, add it via the additionalPlaceholders setting (for details, see Generic parser settings).

Parser settings:

  • Code page (codepage0).

    Specifies the code page used to read .rc files.

    Default: 0.

    Keep the default value to detect the encoding automatically (byte-order mark, #pragma code_page).

    Example 27.

    For ANSI (Windows Latin-1) files without byte-order mark, enter 1252.


  • Unicode target files (unicodeTarget).

    Default: true.

    Writes the target files in UTF-16 format (with byte-order mark), encoding supported by the Resource Compiler. It guarantees that all translated characters and Rigi signatures are written correctly.

    When set to false, the target file is written with the same encoding as the source file.

  • Update code page pragma (syncCodePagePragma).

    Default: true.

    Updates the #pragma code_page(...) statements in the target file so that they match the encoding of the target file.

    A target file that is written in UTF-16 format gets #pragma code_page(DEFAULT).

  • Update language statement (updateLanguageStatement).

    Default: true.

    Writes the LANGUAGE statements for the target locale in the target file. Example: LANGUAGE LANG_JAPANESE and SUBLANG_DEFAULT for the ja-JP language.

    The Resource Compiler stores that language with every resource, so a target file must declare the target language.

    When set to false, the statements in the source file are copied unchanged.

  • Update MFC target symbol (updateAfxTargetSymbol).

    Default: true.

    Write the MFC AFX_TARG_xxx symbols for the target locale in the target file. Example: AFX_TARG_JPN for the ja-JP language.

    An MFC application that loads its resources from a satellite resource DLL uses that symbol to select the resources of a language.

    When set to false, the symbols in the source file are copied unchanged.

  • Store comments (parseCommentstrue).

    Default: true.

    Stores the comment that trails a string, or the comment on the lines above it, as a note for the translator.

  • Parse string tables (parseStringTables).

    Default: true.

    Read the STRINGTABLE resource strings.

  • Parse dialogs (parseDialogs).

    Default: true.

    Reads the captions and control texts (LTEXT, PUSHBUTTON, CHECKBOX, CONTROL, etc.) for the DIALOG and DIALOGEX resources.

  • Parse menus (parseMenus).

    Default: true.

    Reads the POPUP and MENUITEM texts for the MENU and MENUEX resources.

  • Parse version info (parseVersionInfo).

    Default: true.

    Reads the localizable values for the VERSIONINFO resources.

  • Version info keys (versionInfoKeys).

    Default:

    Comments
    FileDescription
    LegalCopyright
    LegalTrademarks
    PrivateBuild
    ProductName
    SpecialBuild

    In this field, you can define the VERSIONINFO keys that contain a localizable value. Define one key per row.

  • Skip resource editor blocks (skipApStudioBlocks).

    Default: true.

    Skips the resources between #ifdef APSTUDIO_INVOKED and #endif. These blocks contain the TEXTINCLUDE and DESIGNINFO resources, which are only used by the Visual Studio resource editor.

  • Escape quotes with backslash (escapeQuoteWithBackslash).

    Default: false.

    When set to true, writes a double quote inside a string as \" instead of "".

    The Resource Compiler supports both forms.

  • Resolve escape sequences (unescapeEscapeSequences).

    Default: false.

    When set to true, converts the escape sequences (\n, \t, \\, \xhh) into the characters they represent. By default, the escape sequences are kept so that the translator sees and keeps the same sequences as in the source file.

For other parser settings, see the Generic parser settings article.