2

Ulimately I just wanted to extract strings from the .rc file so I could translate them, but anything that goes with .rc files works for me.

4

6 回答 6

2

如果您的程序符合 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;
}
于 2012-11-29T13:35:35.427 回答
1

Maybe this helps? (http://social.msdn.microsoft.com/forums/en-US/regexp/thread/5e87fce9-ec73-42eb-b2eb-c821e95e0d31/)

They are using the following regex to find the stringtable in the rc source:

(?<=\bSTRINGTABLE\s+BEGIN\s+).*?(?=\s+END\b)

Edit - And you can read the key values pairs with the following statement with the MultiLine option:

@"\s+(.*?)\s+""(.*)""";

于 2008-09-10T09:31:45.783 回答
1

尽管 rc 文件似乎是翻译的明显起点,但事实并非如此。开发人员的工作是确保应用程序是可翻译的。这不是管理翻译。从 exe 开始翻译,虽然有点违反直觉,但这是一个更好的主意。在此处阅读更多信息:http: //www.apptranslator.com/misconceptions.html

于 2008-09-20T21:01:20.540 回答
0

这听起来像是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
}
于 2008-09-19T00:49:09.830 回答
0

如果是 rc,最好使用高级解析器,例如http://www.soft-gems.net/index.php/java/windows-resource-file-parser-and-converter

于 2014-11-16T06:27:47.947 回答
-2

RexCrunch有时很快就会发布。它将在一个表中以多种语言编辑多个资源文件。

于 2009-03-20T14:45:44.373 回答