Lingobit Extractor · C and C++
Extract hard-coded strings from C and C++ code into resources.
Text written in _T("…") or L"…" never reaches a translator. Lingobit Extractor moves it into a string table in a separate .rc2 file and puts _LS( IDS_… ) in its place, so the text is in the build's resources and can be translated.
- Files
- .c, .cpp, .h, .hpp
- Resources
- String table in a separate .rc2
- In the code
- _LS, _LSW, or _LSA with the ID
- Trial
- 30 days, a separate download
What Extractor changes in your C++ code.
One string, before and after. The ID is made from the words of the text: IDS_ and the words in upper case, joined with _. Numbers come from the range you set for the file, 15000–25000 by default.
Before: OrderDlg.cpp
void COrderDlg::OnSave()
{
SaveOrder();
SetStatus(_T("Order saved"));
}
After: OrderDlg.cpp
void COrderDlg::OnSave()
{
SaveOrder();
SetStatus(_LS( IDS_ORDER_SAVED ));
}
New in the resources: Strings.rc2 and Strings.h
// Strings.rc2
STRINGTABLE
BEGIN
IDS_ORDER_SAVED "Order saved"
END
// Strings.h
#define IDS_ORDER_SAVED 15000
From hard-coded text to resources in five steps.
Not every string is text: a class name, an SQL query, or a registry key stays in the code. You decide what moves, and Extractor remembers it.
Create a projectFile > New Project, then add your source files or the whole folder. Set which files to parse: most teams leave out
stdafx.handstdafx.cpp.Add a resource fileProject > Add Resource creates the
.rc2for the extracted strings, with the ID range, the header file, and the template.Scan, then Skip or ExtractExtractor highlights every string literal in the preview. Skip the technical ones, extract the text.
Include the new filesAdd the
.rc2to your main.rc(Resource View > Resource Includes in Visual Studio), and includeResString.hand the header, usually in the precompiled header.BuildBuild as usual. The strings are now in the string table of your EXE or DLL.
The code that loads the string.
Each extracted string gets a replace template. Pick one per resource file or per string.
_LS( $(ID) )
Loads the string asTCHAR const *. The default._LSW( $(ID) )
Loads it aswchar_t const *._LSA( $(ID) )
Loads it aschar const *.
The three macros are defined in ResString.h. Each string is loaded from the resources once, at the first call. You can also write your own template with $(ID), $(NUM_ID), $(SRC_STR), and $(SRC_TEXT).
Then translate the build.
Lingobit Localizer reads the string table from your EXE or DLL, together with the dialogs and menus, and writes a resource-only DLL for each language, or a localized EXE.
Before translation, check the result with Pseudo Translate in Lingobit Localizer: if a text still stays in English, it is still in the code. Pseudo Translate: Professional and higher.
C++ string extraction FAQ
Does Extractor change my main .rc file?
No. The strings go into a separate .rc2 that Extractor creates and fills; you include it in the main .rc once. Extractor works only with resource files it created.
What is _LS?
A macro from ResString.h that loads a string from the resources by its ID and returns TCHAR const *. _LSW returns wchar_t const *, _LSA returns char const *. Each string is loaded once.
Can I use my own loading function?
Yes. Set your own replace template for the resource file, for example with $(ID) for the identifier or $(NUM_ID) for its number.
What happens to strings I skip?
They stay in the code and keep the Skip state. At the next Scan only new strings show up.
Try Extractor on your own C++ code.
The trial runs for 30 days with every function. In each resource file the first 50 extracted strings are written as they are; after that, some may end in _TRIAL.
Other languages
- Lingobit ExtractorAll languages, how to work with Extractor, and the check after extraction.
- C#Hard-coded strings in C# code into .resx resources.
- Visual Basic .NETHard-coded strings in Visual Basic .NET code into .resx resources.
- DelphiHard-coded strings in Delphi code into a resourcestring unit.
- JavaHard-coded strings in Java code into .properties files.