+void XmlResApp::OutputGettext()
+{
+ wxArrayString str = FindStrings();
+
+ wxFFile fout;
+ if (!parOutput) fout.Attach(stdout);
+ else fout.Open(parOutput, _T("wt"));
+
+ for (size_t i = 0; i < str.GetCount(); i++)
+ fout.Write(_T("_(\"") + str[i] + _T("\")\n"));
+
+ if (!parOutput) fout.Detach();
+}
+
+
+
+wxArrayString XmlResApp::FindStrings()
+{
+ wxArrayString arr, a2;
+
+ for (size_t i = 0; i < parFiles.Count(); i++)
+ {
+ if (flagVerbose)
+ wxPrintf("processing " + parFiles[i] + "...\n");
+
+ wxXmlDocument doc;
+ if (!doc.Load(parFiles[i]))
+ {
+ wxLogError("Error parsing file " + parFiles[i]);
+ retCode = 1;
+ continue;
+ }
+ a2 = FindStrings(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) == 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;
+ default : str2 << *dt; break;
+ }
+ }
+ }
+
+ return str2;
+}
+
+
+wxArrayString XmlResApp::FindStrings(wxXmlNode *node)
+{
+ wxArrayString 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() == _T("label") ||
+ (node/*not n!*/->GetName() == _T("value") &&
+ !n->GetContent().IsNumber()) ||
+ node/*not n!*/->GetName() == _T("help") ||
+ node/*not n!*/->GetName() == _T("longhelp") ||
+ node/*not n!*/->GetName() == _T("tooltip") ||
+ node/*not n!*/->GetName() == _T("htmlcode") ||
+ node/*not n!*/->GetName() == _T("title")
+ ))
+ // ...and known to contain translatable string
+ {
+ arr.Add(ConvertText(n->GetContent()));
+ }
+
+ // subnodes:
+ if (n->GetType() == wxXML_ELEMENT_NODE)
+ {
+ wxArrayString a2 = FindStrings(n);
+ WX_APPEND_ARRAY(arr, a2);
+ }
+
+ n = n->GetNext();
+ }
+ return arr;