From fe150b57b6c146cb174bfe066d4f6a2ba9b65760 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Sun, 20 Mar 2016 11:18:06 +0100 Subject: genlang, generating .pot files for .xrm files Solved new pot directory structure only tested .xrm files, but should be able to extract all .pot files. The LO tools generated the KID as part of the msg, this is not implemented. msgctxt is used as comments, this requires a slight change of the lex programs. Change-Id: Id9aadbd419fb44b73b633410f7dddd90d310ee8d --- l10ntools/source/gConv.cxx | 42 +++++------ l10ntools/source/gConvPo.cxx | 99 ++++++++++++------------ l10ntools/source/gConvProp.cxx | 2 +- l10ntools/source/gConvSrc.cxx | 2 +- l10ntools/source/gConvTree.cxx | 2 +- l10ntools/source/gConvUlf.cxx | 2 +- l10ntools/source/gConvXcs.cxx | 2 +- l10ntools/source/gConvXcu.cxx | 2 +- l10ntools/source/gConvXhp.cxx | 2 +- l10ntools/source/gConvXrm.cxx | 2 +- l10ntools/source/gL10nMem.cxx | 168 ++++++++++++++++++++--------------------- l10ntools/source/gLang.cxx | 37 ++++----- 12 files changed, 175 insertions(+), 187 deletions(-) (limited to 'l10ntools/source') diff --git a/l10ntools/source/gConv.cxx b/l10ntools/source/gConv.cxx index d2446230497e..2dc4f126fccd 100644 --- a/l10ntools/source/gConv.cxx +++ b/l10ntools/source/gConv.cxx @@ -18,6 +18,7 @@ */ #include #include +using namespace std; #include "gL10nMem.hxx" #include "gConv.hxx" @@ -60,17 +61,17 @@ convert_gen::~convert_gen() convert_gen& convert_gen::createInstance(l10nMem& cMemory, - const std::string& sSourceDir, - const std::string& sTargetDir, - const std::string& sSourceFile) + const string& sSourceDir, + const string& sTargetDir, + const string& sSourceFile) { // did the user give a .xxx with the source file ? int nInx = sSourceFile.rfind("."); - if (nInx == (int)std::string::npos) + if (nInx == (int)string::npos) throw l10nMem::showError("source file: "+sSourceFile+" missing extension"); // find correct conversion class and create correct object - std::string sExtension = sSourceFile.substr(nInx+1); + string sExtension = sSourceFile.substr(nInx+1); convert_gen *x; if (sExtension == "hrc") x = new convert_src(cMemory); else if (sExtension == "src") x = new convert_src(cMemory); @@ -93,40 +94,37 @@ convert_gen& convert_gen::createInstance(l10nMem& cMemory, -bool convert_gen::execute(const bool bMerge, const bool bKid) +bool convert_gen::execute(const bool bMerge) { mbMergeMode = bMerge; - if (bKid) - throw l10nMem::showError("not implemented"); - // and load file if (!prepareFile()) return false; // and execute conversion - execute(); + doExecute(); return true; } -bool convert_gen::checkAccess(std::string& sFile) +bool convert_gen::checkAccess(string& sFile) { return (OS_ACCESS(sFile.c_str(), 0) == 0); } -bool convert_gen::createDir(std::string& sDir, std::string& sFile) +bool convert_gen::createDir(const string& sDir, const string& sFile) { - std::string sNewDir(sDir); + string sNewDir(sDir); int newPos, oldPos; for (oldPos = 0;; oldPos = newPos +1) { newPos = sFile.find_first_of("/\\", oldPos); - if (newPos == (int)std::string::npos) + if (newPos == (int)string::npos) break; sNewDir += sFile.substr(oldPos, newPos-oldPos) + "/"; @@ -142,7 +140,7 @@ bool convert_gen::createDir(std::string& sDir, std::string& sFile) bool convert_gen::prepareFile() { - std::ifstream inputFile(msSourcePath.c_str(), std::ios::binary); + ifstream inputFile(msSourcePath.c_str(), ios::binary); if (!inputFile.is_open()) { @@ -156,11 +154,11 @@ bool convert_gen::prepareFile() // get length of file: miSourceReadIndex = 0; - inputFile.seekg (0, std::ios::end); + inputFile.seekg (0, ios::end); msSourceBuffer.resize((unsigned int)inputFile.tellg()); - inputFile.seekg (0, std::ios::beg); + inputFile.seekg (0, ios::beg); - // get size, prepare std::string and read whole file + // get size, prepare string and read whole file inputFile.read(const_cast(msSourceBuffer.c_str()), msSourceBuffer.size()); if ((unsigned int)inputFile.gcount() != msSourceBuffer.size()) throw l10nMem::showError("cannot read whole file"); @@ -172,12 +170,12 @@ bool convert_gen::prepareFile() mcOutputFile.close(); // open output file - mcOutputFile.open((msTargetPath+msSourceFile).c_str(), std::ios::binary); + mcOutputFile.open((msTargetPath+msSourceFile).c_str(), ios::binary); if (mcOutputFile.is_open()) return true; if (convert_gen::createDir(msTargetPath, msSourceFile)) { - mcOutputFile.open((msTargetPath+msSourceFile).c_str(), std::ios::binary); + mcOutputFile.open((msTargetPath+msSourceFile).c_str(), ios::binary); if (mcOutputFile.is_open()) return true; } @@ -216,7 +214,7 @@ void convert_gen::lexRead(char *sBuf, int *nResult, int nMax_size) -void convert_gen::writeSourceFile(const std::string& line) +void convert_gen::writeSourceFile(const string& line) { if (!line.size()) return; @@ -227,7 +225,7 @@ void convert_gen::writeSourceFile(const std::string& line) -std::string& convert_gen::copySource(char const *yyText, bool bDoClear) +string& convert_gen::copySource(char const *yyText, bool bDoClear) { int nL; diff --git a/l10ntools/source/gConvPo.cxx b/l10ntools/source/gConvPo.cxx index f4460da359a4..1eccf9a08841 100644 --- a/l10ntools/source/gConvPo.cxx +++ b/l10ntools/source/gConvPo.cxx @@ -18,6 +18,7 @@ */ #include #include +using namespace std; #include "gL10nMem.hxx" #include "gConvPo.hxx" @@ -47,7 +48,7 @@ convert_po::~convert_po() void convert_po::startLook() { - std::string sFileName, sNewKey; + string sFileName, sNewKey; int i; @@ -132,7 +133,7 @@ void convert_po::handleNL() extern int polex(void); -void convert_po::execute() +void convert_po::doExecute() { if (mbMergeMode) throw l10nMem::showError("Merge not implemented"); @@ -143,71 +144,67 @@ void convert_po::execute() -void convert_po::startSave(const std::string& sLanguage, - const std::string& sFile) +void convert_po::startSave(const string& sName, + const string& sTargetDir, + const string& sFile) { - std::string sFilePath = msTargetPath + sLanguage + sFile; - outBuffer.open(sFilePath.c_str(), std::ios::out); + string sFilePath = sTargetDir + "/" + sFile; + + // create directories as needed + createDir(string(""), sFilePath); + outBuffer.open(sFilePath.c_str(), ios::out + ios::binary); if (!outBuffer.is_open()) throw l10nMem::showError("Cannot open " + sFilePath + " for writing"); l10nMem::showDebug("writing file (" + sFilePath + ")"); - std::ostream outFile(&outBuffer); + ostream outFile(&outBuffer); // Set license header - outFile << "#*************************************************************" << std::endl - << "#*" << std::endl - << "#* This file is part of the LibreOffice project. " << std::endl - << "#*" << std::endl - << "#* This Source Code Form is subject to the terms of the " << std::endl - << "#* Mozilla Public License, v. 2.0. If a copy of the MPL was " << std::endl - << "#* not distributed with this file, You can obtain one at " << std::endl - << "#* http://mozilla.org/MPL/2.0/." << std::endl - << "#*" << std::endl - << "#* This file incorporates work covered by the following " << std::endl - << "#* license notice :" << std::endl - << "#*" << std::endl - << "#* Licensed to the Apache Software Foundation (ASF) under one " << std::endl - << "#* or more contributor license agreements. See the NOTICE file" << std::endl - << "#* distributed with this work for additional information " << std::endl - << "#* regarding copyright ownership. The ASF licenses this file " << std::endl - << "#* to you under the Apache License, Version 2.0 " << std::endl - << "#* (the \"License\"); you may not use this file except in " << std::endl - << "#* compliance with the License.You may obtain a copy of the " << std::endl - << "#* License at http ://www.apache.org/licenses/LICENSE-2.0 . " << std::endl - << "#*" << std::endl - << "#************************************************************" << std::endl - << "msgid \"\"" << std::endl - << "msgstr \"\"" << std::endl - << "\"Project-Id-Version: AOO-4-xx\\n\"" << std::endl - << "\"POT-Creation-Date: \\n\"" << std::endl - << "\"PO-Revision-Date: \\n\"" << std::endl - << "\"Last-Translator: genLang (build process)\\n\"" << std::endl - << "\"Language-Team: \\n\"" << std::endl - << "\"MIME-Version: 1.0\\n\"" << std::endl - << "\"Content-Type: text/plain; charset=UTF-8\\n\"" << std::endl - << "\"Content-Transfer-Encoding: 8bit\\n\"" << std::endl - << "\"X-Generator: genLang\\n\"" << std::endl - << std::endl; + outFile << "#. extracted from " << sName << endl + << "msgid \"\"" << endl + << "msgstr \"\"" << endl + << "\"Project-Id-Version: PACKAGE VERSION\\n\"" << endl + << "\"Report-Msgid-Bugs-To: " + << "https://bugs.libreoffice.org/enter_bug.cgi?" + << "product=LibreOffice&bug_status=UNCONFIRMED" + << "&component=UI\\n\"" << endl + << "\"POT-Creation-Date: \\n\"" << endl + << "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"" << endl + << "\"Last-Translator: FULL NAME \\n\"" << endl + << "\"Language-Team: LANGUAGE \\n\"" << endl + << "\"MIME-Version: 1.0\\n\"" << endl + << "\"Content-Type: text/plain; charset=UTF-8\\n\"" << endl + << "\"Content-Transfer-Encoding: 8bit\\n\"" << endl + << "\"X-Generator: LibreOffice\\n\"" << endl + << "\"X-Accelerator-Marker: ~\\n\"" << endl; } -void convert_po::save(const std::string& sFileName, - const std::string& sKey, - const std::string& sENUStext, - const std::string& sText, +void convert_po::save(const string& sFileName, + const string& sKey, + const string& sENUStext, + const string& sText, bool bFuzzy) { - std::ostream outFile(&outBuffer); - - outFile << std::endl << "#: " << sFileName << "#" << sKey << std::endl; + string sName; + ostream outFile(&outBuffer); + int newPos; + + // isolate filename + newPos = sFileName.find_last_of("/\\", sFileName.length()); + sName = sFileName.substr(newPos + 1, sFileName.length()); + + outFile << "#. xxxxx" << endl + << "#: " << sName << endl + << "msgctxt \"\"" << endl + << "\"" << sName << "\\n\"" << endl; if (bFuzzy) - outFile << "#, fuzzy" << std::endl; - outFile << "msgid \"" << sENUStext << "\"" << std::endl - << "msgstr \"" << sText << "\"" << std::endl; + outFile << "#, fuzzy" << endl; + outFile << "msgid \"" << sENUStext << "\"" << endl + << "msgstr \"" << sText << "\"" << endl; } diff --git a/l10ntools/source/gConvProp.cxx b/l10ntools/source/gConvProp.cxx index c1f6bfa3428f..76d7c936c4d3 100644 --- a/l10ntools/source/gConvProp.cxx +++ b/l10ntools/source/gConvProp.cxx @@ -37,7 +37,7 @@ convert_prop::~convert_prop() -void convert_prop::execute() +void convert_prop::doExecute() { throw l10nMem::showError(std::string("convert_prop::execute not implemented")); } diff --git a/l10ntools/source/gConvSrc.cxx b/l10ntools/source/gConvSrc.cxx index 4eb41e681a43..b3f4736d65fc 100644 --- a/l10ntools/source/gConvSrc.cxx +++ b/l10ntools/source/gConvSrc.cxx @@ -44,7 +44,7 @@ convert_src::~convert_src() extern int srclex(void); -void convert_src::execute() +void convert_src::doExecute() { srclex(); } diff --git a/l10ntools/source/gConvTree.cxx b/l10ntools/source/gConvTree.cxx index 8ce85df5ea05..0b62ccaa6957 100644 --- a/l10ntools/source/gConvTree.cxx +++ b/l10ntools/source/gConvTree.cxx @@ -49,7 +49,7 @@ convert_tree::~convert_tree() extern int treelex(void); -void convert_tree::execute() +void convert_tree::doExecute() { std::string sLang; std::string sFile, sFile2; diff --git a/l10ntools/source/gConvUlf.cxx b/l10ntools/source/gConvUlf.cxx index 37b43147c3ee..fc532c18b7e4 100644 --- a/l10ntools/source/gConvUlf.cxx +++ b/l10ntools/source/gConvUlf.cxx @@ -29,7 +29,7 @@ convert_ulf::~convert_ulf() {} extern int ulflex(void); -void convert_ulf::execute() +void convert_ulf::doExecute() { ulflex(); } diff --git a/l10ntools/source/gConvXcs.cxx b/l10ntools/source/gConvXcs.cxx index c5de41a6819d..2d190d6663e8 100644 --- a/l10ntools/source/gConvXcs.cxx +++ b/l10ntools/source/gConvXcs.cxx @@ -39,7 +39,7 @@ convert_xcs::~convert_xcs() extern int xcslex(void); -void convert_xcs::execute() +void convert_xcs::doExecute() { if (mbMergeMode) throw l10nMem::showError("Merge not implemented"); diff --git a/l10ntools/source/gConvXcu.cxx b/l10ntools/source/gConvXcu.cxx index 668de0e09c6c..2579a38ca840 100644 --- a/l10ntools/source/gConvXcu.cxx +++ b/l10ntools/source/gConvXcu.cxx @@ -38,7 +38,7 @@ convert_xcu::~convert_xcu() extern int xculex(void); -void convert_xcu::execute() +void convert_xcu::doExecute() { xculex(); } diff --git a/l10ntools/source/gConvXhp.cxx b/l10ntools/source/gConvXhp.cxx index 93da8019751d..c2460a42fdfc 100644 --- a/l10ntools/source/gConvXhp.cxx +++ b/l10ntools/source/gConvXhp.cxx @@ -48,7 +48,7 @@ convert_xhp::~convert_xhp() extern int xhplex(void); -void convert_xhp::execute() +void convert_xhp::doExecute() { std::string sLang; std::string sFile, sFile2; diff --git a/l10ntools/source/gConvXrm.cxx b/l10ntools/source/gConvXrm.cxx index fb9f0dafca19..3184dc85176b 100644 --- a/l10ntools/source/gConvXrm.cxx +++ b/l10ntools/source/gConvXrm.cxx @@ -41,7 +41,7 @@ convert_xrm::~convert_xrm() extern int xrmlex(void); -void convert_xrm::execute() +void convert_xrm::doExecute() { xrmlex(); diff --git a/l10ntools/source/gL10nMem.cxx b/l10ntools/source/gL10nMem.cxx index ef7774fb918f..dcf117b0b6b4 100644 --- a/l10ntools/source/gL10nMem.cxx +++ b/l10ntools/source/gL10nMem.cxx @@ -21,6 +21,7 @@ #include #include #include +using namespace std; #include "gL10nMem.hxx" #include "gConvPO.hxx" @@ -31,14 +32,14 @@ l10nMem *myMem; class l10nMem_lang_list_entry { public: - l10nMem_lang_list_entry(const std::string& sName) + l10nMem_lang_list_entry(const string& sName) : msName(sName), mbChanged(false) {} ~l10nMem_lang_list_entry() {}; - std::string msName; // language Name + string msName; // language Name bool mbChanged; // used for "convert", true if language is modified }; @@ -46,22 +47,22 @@ class l10nMem_lang_list_entry class l10nMem_file_entry { public: - l10nMem_file_entry(const std::string& sFileName, int iStart) + l10nMem_file_entry(const string& sFileName, int iStart) : msFileName(sFileName), miStart(iStart), miEnd(iStart) { // Store fileName without relative path int i = msFileName.rfind("/"); - if (i == (int)std::string::npos) + if (i == (int)string::npos) msPureName = msFileName; else msPureName = msFileName.substr(i + 1); } ~l10nMem_file_entry() {}; - std::string msFileName; // file Name with relative path - std::string msPureName; // just filename + string msFileName; // file Name with relative path + string msPureName; // just filename int miStart; // start index of entries in mcMasterEntries (l10Mem_db::mcENUS) int miEnd; // last index of entries in mcMasterEntries (l10Mem_db::mcENUS) }; @@ -71,13 +72,13 @@ class l10nMem_file_entry class l10nMem_lang_entry { public: - l10nMem_lang_entry(const std::string& sMsgStr, bool bFuzzy) + l10nMem_lang_entry(const string& sMsgStr, bool bFuzzy) : msMsgStr(sMsgStr), mbFuzzy(bFuzzy) {} ~l10nMem_lang_entry() {}; - std::string msMsgStr; // translated text from po file + string msMsgStr; // translated text from po file bool mbFuzzy; // fuzzy flag }; @@ -86,8 +87,8 @@ class l10nMem_lang_entry class l10nMem_enus_entry { public: - l10nMem_enus_entry(const std::string& sKey, - const std::string& sMsgId, + l10nMem_enus_entry(const string& sKey, + const string& sMsgId, int iLineNo, int iFileInx, int iLangSize, @@ -110,12 +111,12 @@ class l10nMem_enus_entry ~l10nMem_enus_entry() {}; - std::string msKey; // key in po file and source file - std::string msMsgId; // en-US text from source file + string msKey; // key in po file and source file + string msMsgId; // en-US text from source file l10nMem::ENTRY_STATE meState; // status information int miFileInx; // index of file name int miLineNo; // line number - std::vector mcLangText; // language texts (index is languageId) + vector mcLangText; // language texts (index is languageId) }; @@ -146,7 +147,7 @@ l10nMem::~l10nMem() -int l10nMem::showError(const std::string& sText, int iLineNo) +int l10nMem::showError(const string& sText, int iLineNo) { myMem->mbInError = true; myMem->formatAndShowText("ERROR", iLineNo, sText); @@ -155,14 +156,14 @@ int l10nMem::showError(const std::string& sText, int iLineNo) -void l10nMem::showWarning(const std::string& sText, int iLineNo) +void l10nMem::showWarning(const string& sText, int iLineNo) { myMem->formatAndShowText("WARNING", iLineNo, sText); } -void l10nMem::showDebug(const std::string& sText, int iLineNo) +void l10nMem::showDebug(const string& sText, int iLineNo) { if (myMem->mbDebug) myMem->formatAndShowText("DEBUG", iLineNo, sText); @@ -170,7 +171,7 @@ void l10nMem::showDebug(const std::string& sText, int iLineNo) -void l10nMem::showVerbose(const std::string& sText, int iLineNo) +void l10nMem::showVerbose(const string& sText, int iLineNo) { if (myMem->mbVerbose) myMem->formatAndShowText("INFO", iLineNo, sText); @@ -185,21 +186,21 @@ bool l10nMem::isError() -void l10nMem::setModuleName(const std::string& sModuleName) +void l10nMem::setModuleName(const string& sModuleName) { msModuleName = sModuleName; } -const std::string& l10nMem::getModuleName() +const string& l10nMem::getModuleName() { return msModuleName; } -void l10nMem::setLanguage(const std::string& sLanguage, +void l10nMem::setLanguage(const string& sLanguage, bool bCreate) { int i, iSize; @@ -266,10 +267,10 @@ void l10nMem::setDebug(bool doDebug) void l10nMem::loadEntryKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - const std::string& sMsgStr, + const string& sSourceFile, + const string& sKey, + const string& sMsgId, + const string& sMsgStr, bool bIsFuzzy) { if (mbConvertMode) @@ -283,16 +284,16 @@ void l10nMem::loadEntryKey(int iLineNo, void l10nMem::setSourceKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, + const string& sSourceFile, + const string& sKey, + const string& sMsgId, bool bMustExist) { - std::string newText(sMsgId); + string newText(sMsgId); int i; // time to escape " and \ if contained in text or key - for (i = 0; (i = newText.find("\\", i)) != (int)std::string::npos;) { + for (i = 0; (i = newText.find("\\", i)) != (int)string::npos;) { ++i; if (i < (int)newText.size() && (newText[i] == '\\' || newText[i] == '<' || newText[i] == '>' || @@ -304,7 +305,7 @@ void l10nMem::setSourceKey(int iLineNo, ++i; } } - for (i = 0; (i = newText.find("\"", i)) != (int)std::string::npos;) { + for (i = 0; (i = newText.find("\"", i)) != (int)string::npos;) { newText.insert(i, "\\"); i += 2; } @@ -323,13 +324,10 @@ void l10nMem::setSourceKey(int iLineNo, -void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForce) +void l10nMem::saveTemplates(const string& sTargetDir, bool bKid, bool bForce) { + string target(msModuleName + ".pot"); int iE, iEsize = mcENUSlist.size(); - // std::string sFileName = msModuleName + ".pot"; - - // Fix for new LO standard, at least valid for xrm - std::string sFileName = sTargetDir; // Dummy to satisfy compiler if (bKid) @@ -340,7 +338,7 @@ void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForc reorganize(false); // no save if there has been errors - if (!needWrite(sFileName, bForce)) + if (!needWrite(target, bForce)) return; //JIX save HANDLE KID @@ -348,7 +346,7 @@ void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForc // Save en-US convert_po savePo(*this); - savePo.startSave("templates/", sFileName); + savePo.startSave(msModuleName, sTargetDir, target); for (iE = 1; iE < iEsize; ++iE) { l10nMem_enus_entry& cE = mcENUSlist[iE]; @@ -363,12 +361,12 @@ void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForc -void l10nMem::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool bForce) +void l10nMem::saveLanguages(l10nMem& cMem, const string& sTargetDir, bool bForce) { // int iE, iEsize = mcENUSlist.size(); // int iEsize = mcENUSlist.size(); int iL, iLsize = mcLangList.size(); - std::string sFileName = msModuleName + ".po"; + string sFileName = msModuleName + ".po"; cMem.dumpMem("jan"); showDebug(sTargetDir); @@ -426,7 +424,7 @@ void l10nMem::showNOconvert() -void l10nMem::convertToInetString(std::string& sText) +void l10nMem::convertToInetString(string& sText) { static const char *replacingStr[] = { "&", "\'", ">", "<", "\"", nullptr }; static const int replacingLen[] = { 1, 1, 1, 1, 1, 0 }; @@ -436,7 +434,7 @@ void l10nMem::convertToInetString(std::string& sText) for (i = 0; replacingStr[i]; i++) { pos = 0; - while ((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) { + while ((pos = sText.find(replacingStr[i], pos)) != (int)string::npos) { sText.replace(pos, replacingLen[i], newStr[i]); pos += newLen[i]; } @@ -445,7 +443,7 @@ void l10nMem::convertToInetString(std::string& sText) -void l10nMem::convertFromInetString(std::string& sText) +void l10nMem::convertFromInetString(string& sText) { static const char *replacingStr[] = { "&", "'", ">", "<", """, nullptr }; static const int replacingLen[] = { 5, 6, 4, 4, 6, 0 }; @@ -455,7 +453,7 @@ void l10nMem::convertFromInetString(std::string& sText) for (i = 0; replacingStr[i]; i++) { pos = 0; - while ((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) { + while ((pos = sText.find(replacingStr[i], pos)) != (int)string::npos) { sText.replace(pos, replacingLen[i], newStr[i]); pos += newLen[i]; } @@ -472,7 +470,7 @@ int l10nMem::prepareMerge() -void l10nMem::dumpMem(const std::string& sFileName) +void l10nMem::dumpMem(const string& sFileName) { // and reorganize db if needed reorganize(false); @@ -486,7 +484,7 @@ void l10nMem::dumpMem(const std::string& sFileName) -bool l10nMem::getMergeLang(std::string& sLang, std::string& sMsgStr) +bool l10nMem::getMergeLang(string& sLang, string& sMsgStr) { miCurLangInx++; if (miCurLangInx >= (int)mcLangList.size()) @@ -503,19 +501,19 @@ bool l10nMem::getMergeLang(std::string& sLang, std::string& sMsgStr) -void l10nMem::formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText) +void l10nMem::formatAndShowText(const string& sType, int iLineNo, const string& sText) { - std::cout << sType; + cout << sType; if (miCurFileInx > 0) - std::cout << " in " << mcFileList[miCurFileInx].msFileName; + cout << " in " << mcFileList[miCurFileInx].msFileName; if (iLineNo) - std::cout << "(" << iLineNo << ")"; - std::cout << ": " << sText << std::endl; + cout << "(" << iLineNo << ")"; + cout << ": " << sText << endl; } -bool l10nMem::needWrite(const std::string sFileName, bool bForce) +bool l10nMem::needWrite(const string sFileName, bool bForce) { int iE, iEsize = mcENUSlist.size(); int iCntDeleted = 0, iCntChanged = 0, iCntAdded = 0; @@ -540,26 +538,26 @@ bool l10nMem::needWrite(const std::string sFileName, bool bForce) if (!mbConvertMode) iCntDeleted -= iCntChanged; if (!iCntAdded && !iCntChanged && !iCntDeleted) { - std::cout << "genLang: No changes in " << sFileName; + cout << "genLang: No changes in " << sFileName; if (bForce) - std::cout << ", -o switch used, so files are saved" << std::endl; + cout << ", -o switch used, so files are saved" << endl; else - std::cout << " skipping \"save\"" << std::endl; + cout << " skipping \"save\"" << endl; return bForce; } - std::cout << "genLang statistics: " << iCntDeleted << " deleted, " + cout << "genLang statistics: " << iCntDeleted << " deleted, " << iCntChanged << " changed, " << iCntAdded << " added entries in " - << sFileName << std::endl; + << sFileName << endl; return true; } -bool l10nMem::convFilterWarning(const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId) +bool l10nMem::convFilterWarning(const string& sSourceFile, + const string& sKey, + const string& sMsgId) { // silent ignore deleted messages if (sMsgId == "-" || sMsgId == "") @@ -664,15 +662,15 @@ bool l10nMem::convFilterWarning(const std::string& sSourceFile, void l10nMem::convEntryKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - const std::string& sMsgStr, + const string& sSourceFile, + const string& sKey, + const string& sMsgId, + const string& sMsgStr, bool bIsFuzzy) { - std::vector ivEntryList; - std::string curFileName; - std::string curKeyUpper; + vector ivEntryList; + string curFileName; + string curKeyUpper; int curFileIndex, curENUSindex, i, iSize; @@ -731,7 +729,7 @@ void l10nMem::convEntryKey(int iLineNo, l10nMem_enus_entry& curE = mcENUSlist[ivEntryList[i]]; // compare keys, but be aware of different length - if (curKeyUpper.find(curE.msKey) != std::string::npos) { + if (curKeyUpper.find(curE.msKey) != string::npos) { curENUSindex = ivEntryList[i]; bIsFuzzy = true; break; @@ -759,9 +757,9 @@ void l10nMem::convEntryKey(int iLineNo, void l10nMem::loadENUSkey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId) + const string& sSourceFile, + const string& sKey, + const string& sMsgId) { // add it to vector and update file pointer addKey(iLineNo, sSourceFile, sKey, sMsgId, ENTRY_DELETED); @@ -770,10 +768,10 @@ void l10nMem::loadENUSkey(int iLineNo, void l10nMem::loadLangKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - const std::string& sMsgStr, + const string& sSourceFile, + const string& sKey, + const string& sMsgId, + const string& sMsgStr, bool bFuzzy) { if (!locateKey(iLineNo, sSourceFile, sKey, sMsgId, true)) @@ -790,7 +788,7 @@ void l10nMem::reorganize(bool bConvert) { int iE, iEsize = mcENUSlist.size(); int iD, iDsize; - std::vector listDel, listAdd; + vector listDel, listAdd; // Check number of changes @@ -839,12 +837,12 @@ void l10nMem::reorganize(bool bConvert) bool l10nMem::locateKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, + const string& sSourceFile, + const string& sKey, + const string& sMsgId, bool bThrow) { - std::string sUpperKey(sKey); + string sUpperKey(sKey); int i, iSize = sUpperKey.size(); char ch; @@ -886,9 +884,9 @@ bool l10nMem::locateKey(int iLineNo, void l10nMem::addKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, + const string& sSourceFile, + const string& sKey, + const string& sMsgId, l10nMem::ENTRY_STATE eStat) { // check file @@ -908,7 +906,7 @@ void l10nMem::addKey(int iLineNo, else { int iFsize = mcFileList.size(); l10nMem_file_entry& curF = mcFileList[miCurFileInx]; - std::vector::iterator it = mcENUSlist.begin(); + vector::iterator it = mcENUSlist.begin(); // file is registred, so we need to add the entry at the end of the file range curF.miEnd++; @@ -927,7 +925,7 @@ void l10nMem::addKey(int iLineNo, } -bool l10nMem::findFileName(const std::string& sSourceFile) +bool l10nMem::findFileName(const string& sSourceFile) { int iSize = mcFileList.size(); @@ -952,7 +950,7 @@ bool l10nMem::findFileName(const std::string& sSourceFile) -void l10nMem::keyToUpper(std::string& sKey) +void l10nMem::keyToUpper(string& sKey) { int i, iSize; diff --git a/l10ntools/source/gLang.cxx b/l10ntools/source/gLang.cxx index 1c09507fa9b1..6bcb5449b32b 100644 --- a/l10ntools/source/gLang.cxx +++ b/l10ntools/source/gLang.cxx @@ -39,7 +39,7 @@ class handler private: bool mbForceSave; - enum {DO_CONVERT, DO_EXTRACT, DO_MERGE_KID, DO_MERGE} meWorkMode; + enum {DO_CONVERT, DO_EXTRACT, DO_MERGE} meWorkMode; string msTargetDir; string msPoDir; vector mvSourceFiles; @@ -49,7 +49,7 @@ class handler void loadL10MEM(bool onlyTemplates); void runConvert(); void runExtract(); - void runMerge(bool bKid); + void runMerge(); }; @@ -78,7 +78,6 @@ void handler::showUsage(string sErr) " merge merge po files back to sources\n" " is a combination of\n" " -d show debug information\n" - " -k generate key identifier version\n" " -s save unconditionally\n" " -v show progress information\n" "\n" @@ -122,7 +121,7 @@ void handler::showManual() "\n\n"; cout << - " genLang merge [-v] [-d] [-s] [-k]\n" + " genLang merge [-v] [-d] [-s]\n" " --files \n" " --target \n" " --po \n" @@ -177,13 +176,6 @@ void handler::checkCommandLine(int argc, char *argv[]) if (sWorkText == "-d") { // show debug information mcMemory.setDebug(true); - mcMemory.setVerbose(true); - } - else if (sWorkText == "-k") { - // generate key identifier version - if (meWorkMode != DO_MERGE) - throw "-k requires \"merge\""; - meWorkMode = DO_MERGE_KID; } else if (sWorkText == "-v") { // show progress information @@ -222,7 +214,6 @@ void handler::checkCommandLine(int argc, char *argv[]) case DO_EXTRACT: bSourceFiles = bTargetDir = true; break; - case DO_MERGE_KID: case DO_MERGE: bPoDir = bTargetDir = true; break; @@ -241,10 +232,9 @@ void handler::run() // use workMode to start correct control part switch (meWorkMode) { - case DO_EXTRACT: runExtract(); break; - case DO_MERGE: runMerge(false); break; - case DO_MERGE_KID: runMerge(true); break; - case DO_CONVERT: runConvert(); break; + case DO_EXTRACT: runExtract(); break; + case DO_MERGE: runMerge(); break; + case DO_CONVERT: runConvert(); break; } } @@ -264,7 +254,7 @@ void handler::loadL10MEM(bool onlyTemplates) // and load file mcMemory.setLanguage("", true); - convert_gen::createInstance(mcMemory, sLoad, msTargetDir, "").execute(false, false); + convert_gen::createInstance(mcMemory, sLoad, msTargetDir, "").execute(false); if (onlyTemplates) return; @@ -302,7 +292,7 @@ void handler::runConvert() // get converter and extract files convert_gen& convertObj = convert_gen::createInstance(mcMemory, "./", msTargetDir, *siSource); - convertObj.execute(false, false); + convertObj.execute(false); mcMemory.showNOconvert(); @@ -331,6 +321,7 @@ void handler::runConvert() void handler::runExtract() { vector::iterator siSource; + int newPos; // no convert mcMemory.setConvert(false, false); @@ -340,9 +331,13 @@ void handler::runExtract() // tell system l10nMem::showDebug("genLang extracting text from file " + *siSource); + // set module name + newPos = (*siSource).find_last_of("/\\", (*siSource).length()); + mcMemory.setModuleName((*siSource).substr(0, newPos)); + // get converter and extract file convert_gen& convertObj = convert_gen::createInstance(mcMemory, "", msTargetDir, *siSource); - convertObj.execute(false, false); + convertObj.execute(false); } // and generate language file @@ -351,7 +346,7 @@ void handler::runExtract() -void handler::runMerge(bool bKid) +void handler::runMerge() { vector::iterator siSource; @@ -365,7 +360,7 @@ void handler::runMerge(bool bKid) // get converter and extract file convert_gen& convertObj = convert_gen::createInstance(mcMemory, "", msTargetDir, *siSource); - convertObj.execute(true, bKid); + convertObj.execute(true); } } -- cgit