57
static const wxString m_sFooter1 =
58
_T("Send your comments and sugesstions to LenMus team (www.lenmus.org)");
59
static const wxString m_sFooter2 =
60
_T("Licensed under the terms of the GNU Free Documentation License (see copyrights page for details.)");
56
63
lmEbookProcessor::lmEbookProcessor()
58
65
m_pTocFile = (wxFile*) NULL;
59
66
m_pHtmlFile = (wxFile*) NULL;
60
m_pPoFile = (wxFile*)NULL;
67
m_pLangFile = (wxFile*)NULL;
61
68
m_pLmbFile = (wxTextOutputStream*)NULL;
62
69
m_pZipFile = (wxZipOutputStream*)NULL;
71
78
if (m_pTocFile) delete m_pTocFile;
72
79
if (m_pHtmlFile) delete m_pHtmlFile;
73
if (m_pPoFile) delete m_pPoFile;
80
if (m_pLangFile) delete m_pLangFile;
74
81
if (m_pLmbFile) delete m_pLmbFile;
75
82
if (m_pZipFile) delete m_pZipFile;
79
bool lmEbookProcessor::GenerateLMB(wxString sFilename, int nOptions)
86
bool lmEbookProcessor::GenerateLMB(wxString sFilename, wxString sLangCode, int nOptions)
81
88
// returns false if error
89
// PO and lang.cpp are created in sDestName (langtool\locale\)
90
// book.lmb is created in sDestName (lenmus\books\xx\)
91
// book.toc is temporarily created in sDestName (lenmus\books\xx\)
83
93
// Prepare for a new XML file processing
84
94
m_fProcessingBookinfo = false;
85
m_fOnlyPoFile = nOptions & lmPO_FILE;
95
m_fOnlyLangFile = nOptions & lmLANG_FILE;
96
m_fGenerateLmb = !m_fOnlyLangFile;
87
99
// load the XML file as tree of nodes
88
100
wxXml2Document oDoc;
292
304
// are for filtering ou these lines
293
305
wxString tmp = sContent.Trim();
294
306
if (!tmp.IsEmpty()) {
295
if (nWriteOptions & eTOC) WriteToToc(sContent, ltNO_INDENT); //text not indented
296
if (nWriteOptions & eHTML) WriteToHtml(sContent);
297
if (m_fOnlyPoFile && (nWriteOptions & eTRANSLATE)) WriteToPo(sContent);
307
wxString sTrans = wxGetTranslation(sContent);
308
if (nWriteOptions & eTOC) WriteToToc(sTrans, ltNO_INDENT); //text not indented
309
if (nWriteOptions & eHTML) WriteToHtml(sTrans);
310
if (m_fOnlyLangFile && (nWriteOptions & eTRANSLATE)) WriteToLang(sContent);
298
311
//if (fIdx) WriteToIdx(sContent);
299
312
if (pText) *pText += sContent;
846
859
wxString sTitleNum = wxEmptyString;
847
860
if (m_nTitleLevel >= 0)
848
sTitleNum += wxString::Format(_T("$d"), m_nNumTitle[0] );
861
sTitleNum += wxString::Format(_T("%d"), m_nNumTitle[0] );
849
862
for (int i=1; i <= m_nTitleLevel; i++) {
850
sTitleNum += wxString::Format(_T(".$d"), m_nNumTitle[i] );
863
sTitleNum += wxString::Format(_T(".%d"), m_nNumTitle[i] );
852
865
if (sTitleNum != wxEmptyString) sTitleNum += _T(" ");
1001
1014
_T("<table width='100%' cellpadding='0' cellspacing='0'>\n")
1002
1015
_T("<tr><td bgcolor='#ff8800'><img src='ebook_line.png'></td></tr>\n")
1003
1016
_T("<tr><td bgcolor='#7f8adc' align='center'>\n")
1004
_T(" <font size='-1' color='ffffff'><br /><br />\n")
1005
_T("Send your comments and sugesstions to LenMus team (www.lenmus.org)")
1007
_T("Licensed under the terms of the GNU Free Documentation License (see copyrights page for details.)")
1017
_T(" <font size='-1' color='ffffff'><br /><br />\n") + m_sFooter1 +
1018
_T("<br />\n") + m_sFooter2 +
1009
1020
_T(" </font>\n")
1010
1021
_T("</td></tr>\n")
1044
1055
//------------------------------------------------------------------------------------
1047
bool lmEbookProcessor::StartLmbFile(wxString sFilename)
1058
bool lmEbookProcessor::StartLmbFile(wxString sFilename, wxString sLangCode)
1049
1060
// returns true if success
1051
1062
wxFileName oFNP( sFilename );
1052
oFNP.SetExt(_T("lmb"));
1053
m_pZipOutFile = new wxFFileOutputStream( oFNP.GetFullName() );
1063
wxFileName oFDest( g_pPaths->GetBooksRootPath() );
1064
oFDest.AppendDir(sLangCode);
1065
oFDest.SetName( oFNP.GetName() );
1066
oFDest.SetExt(_T("lmb"));
1067
m_pZipOutFile = new wxFFileOutputStream( oFDest.GetFullPath() );
1054
1068
//wxFFileOutputStream out( oFNP.GetFullName() );
1055
//if (!m_pPoFile->IsOpened()) {
1069
//if (!m_pLangFile->IsOpened()) {
1056
1070
// wxLogMessage(_T("Error: File %s can not be created"), oFNP.GetFullName());
1057
// m_pPoFile = (wxFile*)NULL;
1071
// m_pLangFile = (wxFile*)NULL;
1058
1072
// return false; //error
1060
1074
m_pZipFile = new wxZipOutputStream(*m_pZipOutFile);
1098
1112
//------------------------------------------------------------------------------------
1099
// PO file management
1113
// Lang (.cpp) file management
1100
1114
//------------------------------------------------------------------------------------
1103
bool lmEbookProcessor::StartPoFile(wxString sFilename)
1105
// returns true if success
1107
wxFileName oFNP( sFilename );
1108
oFNP.SetExt(_T("po"));
1109
m_pPoFile = new wxFile(oFNP.GetFullName(), wxFile::write);
1110
if (!m_pPoFile->IsOpened()) {
1111
wxLogMessage(_T("Error: File %s can not be created"), oFNP.GetFullName());
1112
m_pPoFile = (wxFile*)NULL;
1117
bool lmEbookProcessor::StartLangFile(wxString sFilename)
1119
// returns true if success
1121
wxFileName oFNP( sFilename );
1122
wxFileName oFDest( g_pPaths->GetLocalePath() );
1123
oFDest.AppendDir(_T("src"));
1124
::wxSetWorkingDirectory( oFDest.GetPath() );
1125
oFDest.AppendDir( oFNP.GetName() );
1126
//if dir does not exist, create it
1127
bool fError = ::wxMkDir( oFNP.GetName() );
1129
oFDest.SetName( oFNP.GetName() );
1130
oFDest.SetExt(_T("cpp"));
1131
m_pLangFile = new wxFile(oFDest.GetFullPath(), wxFile::write);
1132
if (!m_pLangFile->IsOpened()) {
1133
wxLogMessage(_T("Error: File %s can not be created"), oFDest.GetFullPath());
1134
m_pLangFile = (wxFile*)NULL;
1135
return false; //error
1138
m_pLangFile->Write(_T("wxString sTxt;\n"));
1140
// add texts included by Langtool (footers, headers, etc.)
1141
WriteToLang( m_sFooter1 );
1142
WriteToLang( m_sFooter2 );
1148
void lmEbookProcessor::WriteToLang(wxString sText)
1150
//add text to Lang file
1152
if (!m_pLangFile || sText == _T("")) return;
1155
wxString sContent = sText;
1156
sContent.Replace(_T("\n"), _T("\\n"));
1157
m_pLangFile->Write(_T("sTxt = _(\""));
1158
m_pLangFile->Write(sContent + _T("\");\n"));
1162
bool lmEbookProcessor::CreatePoFile(wxString& sFilename, wxString& sCharSet,
1163
wxString& sLangName, wxString& sLangCode)
1165
// returns true if success
1167
wxFileName oFNP( sFilename );
1168
wxFileName oFDest( g_pPaths->GetLocalePath() );
1169
oFDest.AppendDir(sLangCode);
1170
oFDest.SetName( oFNP.GetName() );
1171
oFDest.SetExt(_T("po"));
1172
wxFile oFile(oFDest.GetFullPath(), wxFile::write);
1173
if (!m_pLangFile->IsOpened()) {
1174
wxLogMessage(_T("Error: File %s can not be created"), oFDest.GetFullPath());
1175
m_pLangFile = (wxFile*)NULL;
1113
1176
return false; //error
1118
1181
wxString sHeader = sNil +
1119
1182
_T("msgid \"\"\n")
1120
1183
_T("msgstr \"\"\n")
1121
_T("\"Project-Id-Version: LenMus 3.3\\n\"\n")
1184
_T("\"Project-Id-Version: LenMus 3.4\\n\"\n")
1122
1185
_T("\"POT-Creation-Date: \\n\"\n")
1123
1186
_T("\"PO-Revision-Date: 2006-08-25 12:19+0100\\n\"\n")
1124
1187
_T("\"Last-Translator: \\n\"\n")
1125
1188
_T("\"Language-Team: <cecilios@gmail.com>\\n\"\n")
1126
1189
_T("\"MIME-Version: 1.0\\n\"\n")
1127
_T("\"Content-Type: text/plain; charset=utf-8\\n\"\n")
1190
_T("\"Content-Type: text/plain; charset=") + sCharSet + _T("\\n\"\n")
1128
1191
_T("\"Content-Transfer-Encoding: 8bit\\n\"\n")
1129
_T("\"X-Poedit-Language: English\\n\"\n")
1130
_T("\"X-Poedit-SourceCharset: iso-8859-1\\n\"\n\n");
1132
m_pPoFile->Write(sHeader);
1192
_T("\"X-Poedit-Language: ") + sLangName + _T("\\n\"\n")
1193
_T("\"X-Poedit-SourceCharset: iso-8859-1\\n\"\n")
1194
_T("\"X-Poedit-Basepath: c:\\usr\\desarrollo_wx\\lenmus\\langtool\\locale\\src\\n\"\n")
1195
_T("\"X-Poedit-SearchPath-0: ") + oFNP.GetName() + _T("\\n\"\n\n");
1198
oFile.Write(sHeader);
1137
void lmEbookProcessor::WriteToPo(wxString& sText)
1139
//add text to PO file
1141
if (!m_pPoFile || sText == _T("")) return;
1144
wxString sContent = sText;
1145
sContent.Replace(_T("\n"), _T("\\n"));
1146
m_pPoFile->Write(_T("msgid \""));
1147
m_pPoFile->Write(sContent + _T("\"\n"));
1148
m_pPoFile->Write(_T("msgstr \"\"\n\n"));
1153
1205
//------------------------------------------------------------------------------------
1154
1206
// Debug methods