最終的には、.rc ファイルから文字列を抽出して翻訳できるようにしたかっただけですが、.rc ファイルに関連するものはすべて機能します。
6 に答える
プログラムがGNUライセンスに適合している場合は、 gettextファイルと.POファイルの使用を検討します
1)ステートマシンアルゴリズムを使用して.rcファイルから抽出することをお勧めします。
void ProcessLine(const char * str)
{
if (strstr(str, " DIALOG"))
state = Scan;
else if (strstr(str, " MENU"))
state = Scan;
else if (strstr(str, " STRINGTABLE"))
state = Scan;
else if (strstr(str, "END"))
state = DontScan;
if (state == Scan)
{
const char * cur = sLine;
string hdr = ...// for example "# file.rc:453"
string msgid;
string msgid = "";
while (ExtractString(sLine, cur, msgid))
{
if (msgid.empty())
continue;
if (IsPredefined(msgid))
continue;
if (msgid.find("IDB_") == 0 || msgid.find("IDC_") == 0)
continue;
WritePoString(hdr, msgid, msgstr);
}
}
}
2)ExtractString()内で文字列を抽出するときは、char"が""として表され、\ t \ n \ rのような文字もあることを考慮する必要があります。したがって、ここではステートマシンも適切なオプションです。
次の文字列:
LTEXT "Mother has washed ""Sony"", then \taquarium\\shelves\r\nand probably floors",IDC_TEXT1,24,14,224,19
ダイアログでそのようなラベルを表します:
Mother has washed "Sony", then aquarium\shelves
and probably floors
3)次に、プログラムの起動時にgettextを介して.poファイルをロードし、ダイアログごとに次のような関数を使用して起動時にその文字列を変換する必要があります。
int TranslateDialog(CWnd& wnd)
{
int i = 0;
CWnd *pChild;
CString text;
//Translate Title
wnd.GetWindowText(text);
LPCTSTR translation = Translate(text);
window.SetWindowText(translation);
//Translate child windows
pChild=wnd.GetWindow(GW_CHILD);
while(pChild)
{
i++;
Child->GetWindowText(Text);//including NULL
translation = Translate(Text);
pChild->SetWindowText(translation);
pChild = pChild->GetWindow(GW_HWNDNEXT);
}
return i;
}
rc ファイルは明らかに翻訳の出発点のように見えますが、そうではありません。開発者の仕事は、アプリが翻訳可能であることを確認することです。翻訳を管理することではありません。直観に反するかもしれませんが、exe から翻訳を開始する方が良い方法です。詳しくはこちらをご覧ください: http://www.apptranslator.com/misconceptions.html
多分これは役立ちますか?( http://social.msdn.microsoft.com/forums/en-US/regexp/thread/5e87fce9-ec73-42eb-b2eb-c821e95e0d31/ )
彼らは次の正規表現を使用して、rc ソースで文字列テーブルを見つけています。
(?<=\bSTRINGTABLE\s+BEGIN\s+).*?(?=\s+END\b)
編集 - MultiLine オプションを指定した次のステートメントで、キーと値のペアを読み取ることができます。
@"\s+(.*?)\s+""(.*)""";
これはSEDスクリプトの仕事のように聞こえます。
次のコマンドラインを実行する:sed.exe -n -f sed.txt test.rc
次のSEDスクリプトは、引用符で囲まれたすべての文字列を入力test.rcファイルから抽出します。
# Run Script Using This Command Line
#
# sed.exe -n -f sed.txt test.rc
#
# Check for lines that contain strings
/\".*\"/ {
# print the string part of the line only
s/\(.*\)\(\".*\"\)\(.*\)/\2/ p
}
ResxCrunchは近日中に公開される予定です。1 つのテーブルで複数の言語の複数のリソース ファイルを編集します。