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,MENUEXandVERSIONINFOresources.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_pagestatement 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 symbolAFX_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
TEXTINCLUDEandDESIGNINFOresources 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.
Resource | Texts that are read | Texts that are not read |
|---|---|---|
| All strings. | – |
|
| The name of the font ( |
| The texts of |
|
| The values of the localizable keys (for details, see the | The keys that identify the binary, e.g., |
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.
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
CAPTIONfor 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,0and65535occur several times in the same dialog. For those controls, the control's position in the dialog is added, e.g.,IDD_ABOUTBOX.IDC_STATIC.2for 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?"
ENDThe 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:
The code page stated in the
codepagesetting, if it is not 0.The byte-order-mark set for the file (UTF-8, UTF-16 LE, UTF-16 BE).
UTF-16 without byte-order-mark.
The
#pragma code_page(...)statement in the file.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
LANGUAGEelement gets the language and the sublanguage of the target locale, e.g.,LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIEDfor 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_pageelement gets the code page of the target file, orDEFAULTif the target file is written as UTF-16. The Resource Compiler then uses the file's byte-order mark.The MFC symbol
AFX_TARG_xxxgets the three-letter abbreviation that Windows uses for the target language, e.g.,AFX_TARG_CHSfor 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 theTEXTINCLUDEresources.
These statements can be switched off using the updateLanguageStatement, syncCodePagePragma, or updateAfxTargetSymbol parser settings.
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 |
|---|---|
|
|
|
|
|
|
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
.rcfiles.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
LANGUAGEstatements for the target locale in the target file. Example:LANGUAGE LANG_JAPANESEandSUBLANG_DEFAULTfor 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_xxxsymbols for the target locale in the target file. Example:AFX_TARG_JPNfor 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
STRINGTABLEresource strings.Parse dialogs (
parseDialogs).Default:
true.Reads the captions and control texts (
LTEXT,PUSHBUTTON,CHECKBOX,CONTROL, etc.) for theDIALOGandDIALOGEXresources.Parse menus (
parseMenus).Default:
true.Reads the
POPUPandMENUITEMtexts for theMENUandMENUEXresources.Parse version info (
parseVersionInfo).Default:
true.Reads the localizable values for the
VERSIONINFOresources.Version info keys (
versionInfoKeys).Default:
Comments FileDescription LegalCopyright LegalTrademarks PrivateBuild ProductName SpecialBuild
In this field, you can define the
VERSIONINFOkeys that contain a localizable value. Define one key per row.Skip resource editor blocks (
skipApStudioBlocks).Default:
true.Skips the resources between
#ifdef APSTUDIO_INVOKEDand#endif. These blocks contain theTEXTINCLUDEandDESIGNINFOresources, 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.