Home |
Make String Table |
Make String TableProgram Mkstrtab is a command line utility to maintain multi-language string tables without using Window Builder to manage the user interface design. Mkstrtab can build a complete string table from one or more ASCII and/or Unicode text files: MkStrTab [-Ocp] outfile [-Icp] textfiles... Parameters-OcpOutput code page. cp must be replaced with a numeric value specifying the code page used by the font(s) used on the target. The default value is 1252. You should specify 1200 if Unicode fonts are used on the target. UTF-8 is not supported for this option. outfileBase name of the output file. Mkstrtab will write the resulting C++ source code to outfile.hpp and outfile.cpp. -IcpInput code page. cp must be replaced with a numeric value specifying the code page used by subsequent textfile parameters. The default value is 1252. You can change the code page any number of times on the command line. The input code page is ignored for UTF-16 and UTF-8 Unicode text files if the text file contains valid Unicode text markers/signatures. For Unicode files without Unicode markers/signatures, specify code page 1200 for UTF-16 and 65001 for UTF-8. textfileThe names of one or more text files containing string constants. See below for a description on how such files are formatted. Note that 8-bit ASCII files of any Windows-supported code page as well as UTF-16 and UTF-8 Unicode text files are supported. However, no multi-byte character sets other than UTF-8 can be used. The Windows version of program Notepad as well as Microsoft Visual Studio.NET can save text files in Unicode formats UTF-16 (Unicode) and UTF-8. Text files to be read by Mkstrtab must contain string constants to be associated with a string ID and a language index. The files are line-oriented where each line must have one of the following formats: StringId [LangIdx] "String" StringId [LangIdx] MappedIdx WithStringIdC/C++ identifier to be used at run-time to denote a string. The StringId is case sensitive. LangIdxZero-based Language index. If not specified, LangIdx is 0 for the first file given on the MkStrTab command line, 1 for the second, etc. StringThe actual string. All C/C++ escape sequences such as \r, \n, or \x34 are supported. MappedIdxLanguage index to map this string to. Use this form if a string is identical in two languages and you do not want to store it twice on the target. If a string has not been defined in all languages, a default language will be used for all undefined languages of that string ID. The default language is the lowest language index for which the string ID has been defined. There are basically two different approaches to managing the strings of a multi-lingual application: all strings reside in the same file or a separate file is created for each language. In the latter case, specification of the LangIdx is not required (but still possible). Here is a short example for a two-language application with all strings (two in this case) maintained in a single text file: File Text.txtSID_HELLO 0 "Hi, how are you?" SID_HELLO 1 "Hallo, wie geht's?" SID_BYE 0 "See ya!" SID_BYE 1 "Und tschüß!" Running command: Mkstrtab Wbstring Text.txt will produce these output files: Wbstring.hpp:extern const PEGCHAR * const * const wbStringTable[]; extern int gbCurrentLanguage; #define LookupString(SID) wbStringTable[gbCurrentLanguage][SID] #define LS LookupString enum STRING_IDS { SID_HELLO, SID_BYE }; Wbstring.cpp:#include <peg.hpp> #include "Wbstring.hpp" int gbCurrentLanguage = 0; static const PEGCHAR S_0_0[] = PTEXT("Hi, how are you?"); static const PEGCHAR S_1_0[] = PTEXT("Hallo, wie geht's?"); static const PEGCHAR S_0_1[] = PTEXT("See ya!"); static const PEGCHAR S_1_1[] = PTEXT("Und tschüß!"); static const PEGCHAR * const LID_0[] = { S_0_0, S_0_1 }; static const PEGCHAR * const LID_1[] = { S_1_0, S_1_1 }; const PEGCHAR * const * const wbStringTable[] = { LID_0, LID_1 }; File Wbstring.hpp should be included by the application source code. At run-time, changing the current default language is achieved by assigning a language index to global variable gbCurrentLanguage. Macros LookupString and LS can be used to retrieve a pointer to the string for a given string ID and the current language. ExampleAdd(new PegString(10, 10, LS(SID_HELLO))); Demo program Multilang is a complete multi-language application built with Mkstrtab.
|