+ for (ExtractedStrings::const_iterator i = str.begin(); i != str.end(); ++i)
+ {
+ const wxFileName filename(i->filename);
+
+ wxString s;
+ s.Printf("#line %d \"%s\"\n",
+ i->lineNo, filename.GetFullPath(wxPATH_UNIX));
+
+ fout.Write(s);
+ fout.Write("_(\"" + i->str + "\");\n");
+ }
+
+ if (!parOutput) fout.Detach();
+}
+
+
+
+ExtractedStrings XmlResApp::FindStrings()
+{
+ ExtractedStrings arr, a2;
+
+ for (size_t i = 0; i < parFiles.GetCount(); i++)
+ {
+ if (flagVerbose)
+ wxPrintf(wxT("processing ") + parFiles[i] + wxT("...\n"));
+
+ wxXmlDocument doc;
+ if (!doc.Load(parFiles[i]))
+ {
+ wxLogError(wxT("Error parsing file ") + parFiles[i]);
+ retCode = 1;
+ continue;
+ }
+ a2 = FindStrings(parFiles[i], doc.GetRoot());
+
+ WX_APPEND_ARRAY(arr, a2);
+ }
+
+ return arr;
+}
+
+
+
+static wxString ConvertText(const wxString& str)
+{
+ wxString str2;
+ const wxChar *dt;
+
+ for (dt = str.c_str(); *dt; dt++)
+ {
+ if (*dt == wxT('_'))
+ {
+ if ( *(dt+1) == 0 )
+ str2 << wxT('_');
+ else if ( *(++dt) == wxT('_') )
+ str2 << wxT('_');
+ else
+ str2 << wxT('&') << *dt;
+ }
+ else
+ {
+ switch (*dt)
+ {
+ case wxT('\n') : str2 << wxT("\\n"); break;
+ case wxT('\t') : str2 << wxT("\\t"); break;
+ case wxT('\r') : str2 << wxT("\\r"); break;
+ case wxT('\\') : if ((*(dt+1) != 'n') &&
+ (*(dt+1) != 't') &&
+ (*(dt+1) != 'r'))
+ str2 << wxT("\\\\");
+ else
+ str2 << wxT("\\");
+ break;
+ case wxT('"') : str2 << wxT("\\\""); break;
+ default : str2 << *dt; break;
+ }
+ }
+ }
+
+ return str2;
+}
+
+
+ExtractedStrings
+XmlResApp::FindStrings(const wxString& filename, wxXmlNode *node)
+{
+ ExtractedStrings arr;
+
+ wxXmlNode *n = node;
+ if (n == NULL) return arr;
+ n = n->GetChildren();
+
+ while (n)
+ {
+ if ((node->GetType() == wxXML_ELEMENT_NODE) &&
+ // parent is an element, i.e. has subnodes...
+ (n->GetType() == wxXML_TEXT_NODE ||
+ n->GetType() == wxXML_CDATA_SECTION_NODE) &&
+ // ...it is textnode...
+ (
+ node/*not n!*/->GetName() == wxT("label") ||
+ (node/*not n!*/->GetName() == wxT("value") &&
+ !n->GetContent().IsNumber()) ||
+ node/*not n!*/->GetName() == wxT("help") ||
+ node/*not n!*/->GetName() == wxT("longhelp") ||
+ node/*not n!*/->GetName() == wxT("tooltip") ||
+ node/*not n!*/->GetName() == wxT("htmlcode") ||
+ node/*not n!*/->GetName() == wxT("title") ||
+ node/*not n!*/->GetName() == wxT("item") ||
+ node/*not n!*/->GetName() == wxT("message") ||
+ node/*not n!*/->GetName() == wxT("note") ||
+ node/*not n!*/->GetName() == wxT("defaultdirectory") ||
+ node/*not n!*/->GetName() == wxT("defaultfilename") ||
+ node/*not n!*/->GetName() == wxT("defaultfolder") ||
+ node/*not n!*/->GetName() == wxT("filter") ||
+ node/*not n!*/->GetName() == wxT("caption")
+ ))
+ // ...and known to contain translatable string
+ {
+ if (!flagGettext ||
+ node->GetAttribute(wxT("translate"), wxT("1")) != wxT("0"))
+ {
+ arr.push_back
+ (
+ ExtractedString
+ (
+ ConvertText(n->GetContent()),
+ filename,
+ n->GetLineNumber()
+ )
+ );
+ }
+ }
+
+ // subnodes:
+ if (n->GetType() == wxXML_ELEMENT_NODE)
+ {
+ ExtractedStrings a2 = FindStrings(filename, n);
+ WX_APPEND_ARRAY(arr, a2);
+ }
+
+ n = n->GetNext();
+ }
+ return arr;