Author: jani Date: Sun Mar 10 00:00:20 2013 New Revision: 1454775 URL: http://svn.apache.org/r1454775 Log: prepare to write .po
Modified: openoffice/branches/l10n/main/l10ntools/source/gCon.cxx openoffice/branches/l10n/main/l10ntools/source/gCon.hxx openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx openoffice/branches/l10n/main/l10ntools/source/gConPo.hxx openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gConSrcWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gConUlfWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gConXrmWrap.cxx openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx openoffice/branches/l10n/main/l10ntools/source/gLang.hxx openoffice/branches/l10n/main/l10ntools/source/makefile.mk Modified: openoffice/branches/l10n/main/l10ntools/source/gCon.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gCon.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gCon.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gCon.cxx Sun Mar 10 00:00:20 2013 @@ -50,15 +50,12 @@ convert_gen_impl * convert_gen_impl::mcI /********************** I M P L E M E N T A T I O N **********************/ -convert_gen::convert_gen(l10nMem& cMemory, const std::string& sSourceFile) +convert_gen::convert_gen(l10nMem& cMemory, const std::string& sSourceDir, const std::string& sSourceFile) { // do we have an old object if (convert_gen_impl::mcImpl) delete convert_gen_impl::mcImpl; - // and set environment - convert_gen_impl::mcImpl->msSourceFile = sSourceFile; - // did the user give a .xxx with the source file ? int nInx = sSourceFile.rfind("."); if (nInx == (int)std::string::npos) @@ -80,6 +77,7 @@ convert_gen::convert_gen(l10nMem& cMemor // and set environment convert_gen_impl::mcImpl->msSourceFile = sSourceFile; + convert_gen_impl::mcImpl->msSourcePath = sSourceDir + sSourceFile; } @@ -110,6 +108,63 @@ bool convert_gen::execute(const bool bMe /********************** I M P L E M E N T A T I O N **********************/ +void convert_gen::startSave(const std::string& sTargetDir, + const std::string& sLanguage, + const std::string& sFile) +{ + convert_gen_impl::mcImpl->startSave(sTargetDir, sLanguage, sFile); +} +void convert_gen_impl::startSave(const std::string& sTargetDir, + const std::string& sLanguage, + const std::string& sFile) +{ + std::string x; + + x = sTargetDir; + x = sLanguage; + x = sFile; + throw l10nMem::showError("startSave called with non .po file"); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_gen::save(const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy) +{ + convert_gen_impl::mcImpl->save(sKey, sENUStext, sText, bFuzzy); +} +void convert_gen_impl::save(const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy) +{ + std::string x; + + x = sKey; + x = sENUStext; + x = sText; + bFuzzy = bFuzzy; + throw l10nMem::showError("save called with non .po file"); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_gen::endSave() +{ + convert_gen_impl::mcImpl->endSave(); +} +void convert_gen_impl::endSave() +{ + throw l10nMem::showError("endSave called with non .po file"); +} + + + +/********************** I M P L E M E N T A T I O N **********************/ convert_gen_impl::convert_gen_impl(l10nMem& crMemory) : mcMemory(crMemory), miLineNo(1) @@ -129,7 +184,7 @@ convert_gen_impl::~convert_gen_impl() /********************** I M P L E M E N T A T I O N **********************/ bool convert_gen_impl::prepareFile(bool bAllowNoFile) { - std::ifstream inputFile(msSourceFile.c_str(), std::ios::binary); + std::ifstream inputFile(msSourcePath.c_str(), std::ios::binary); if (!inputFile.is_open()) @@ -137,7 +192,7 @@ bool convert_gen_impl::prepareFile(bool if (bAllowNoFile) return false; else - throw mcMemory.showError("Cannot open file"); + throw mcMemory.showError("Cannot open file (" + msSourcePath + ")"); } // get length of file: Modified: openoffice/branches/l10n/main/l10ntools/source/gCon.hxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gCon.hxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gCon.hxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gCon.hxx Sun Mar 10 00:00:20 2013 @@ -50,8 +50,19 @@ class convert_gen_impl // all converters MUST implement this function virtual void execute() = 0; + // ONLY po should implement these functions + virtual void startSave(const std::string& sTargetDir, + const std::string& sLanguage, + const std::string& sFile); + virtual void save(const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy); + virtual void endSave(); + // generic variables bool mbMergeMode; + std::string msSourcePath; std::string msSourceFile; l10nMem& mcMemory; std::string msCollector; Modified: openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx Sun Mar 10 00:00:20 2013 @@ -39,8 +39,8 @@ convert_db::~convert_db() /********************** I M P L E M E N T A T I O N **********************/ void convert_db::execute() { - std::string oldKey; - int iB, iE; + std::string newKey; + int i; msSourceBuffer += '\n'; @@ -49,33 +49,18 @@ void convert_db::execute() while (collectLine()) { - mcMemory.setFileName(0, msFields[1], true); - if (mbMergeMode) - { - iB = msFields[15].find("/"); - if (iB == (int)std::string::npos) - mcMemory.showError((char*)"missing / in en_US", miLineNo); - iE = msFields[15].find("/", iB+1); - if (iE == (int)std::string::npos) - mcMemory.showError((char*)"missing / in en_US", miLineNo); - oldKey = msFields[15].substr(iB+1, iE - iB -1); - iB = msFields[15].find("/",iE+1); - if (iB == (int)std::string::npos) - mcMemory.showError((char*)"missing / in en_US", miLineNo); - if (iB != iE+1) - oldKey += "." + msFields[15].substr(iE+1, iB - iE -1); - - // handle en-US (master) -//JIX mcMemory.loadEnUsKey(msFields[4], msFields[3], msFields[10], oldKey); - } - else - { - std::string newKey = msFields[4]; - if (msFields[5].size()) - newKey += "." + msFields[5]; -//JIX mcMemory.loadLangKey(msFields[9], newKey, msFields[3], msFields[10]); - } - } + newKey = msFields[4]; + if (msFields[5].size()) + newKey += "." + msFields[5]; + if (msFields[3].size()) + newKey += "." + msFields[3]; + + for (; (i = msFields[1].find('\\')) != std::string::npos;) + msFields[1][i] = '/'; + + // handle en-US or lang + mcMemory.loadENUSkey(miLineNo, msFields[1], newKey, msFields[10]); + } } Modified: openoffice/branches/l10n/main/l10ntools/source/gConPo.hxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConPo.hxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConPo.hxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConPo.hxx Sun Mar 10 00:00:20 2013 @@ -44,5 +44,14 @@ class convert_po : public convert_gen_im private: void execute(); + + void startSave(const std::string& sTargetDir, + const std::string& sLanguage, + const std::string& sFile); + void save(const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy); + void endSave(); }; #endif \ No newline at end of file Modified: openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx Sun Mar 10 00:00:20 2013 @@ -69,6 +69,43 @@ void convert_po::execute() PoWrap::yylex(); } + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::startSave(const std::string& sTargetDir, + const std::string& sLanguage, + const std::string& sFile) +{ + std::string x; + + x = sTargetDir; + x = sLanguage; + x = sFile; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::save(const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy) +{ + std::string x; + + x = sKey; + x = sENUStext; + x = sText; + bFuzzy = bFuzzy; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void convert_po::endSave() +{ +} + /********************** I M P L E M E N T A T I O N **********************/ @@ -107,7 +144,7 @@ void convert_po::stopCollectData(char *s #endif } else -//JIX mcMemory.setEnUsKey(miLineNo, useKey, std::string("dummy"), sCollectedText); + mcMemory.setSourceKey(miLineNo, msSourceFile, useKey, sCollectedText); // mbCollectingData = false; msCollector.clear(); Modified: openoffice/branches/l10n/main/l10ntools/source/gConSrcWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConSrcWrap.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConSrcWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConSrcWrap.cxx Sun Mar 10 00:00:20 2013 @@ -182,7 +182,7 @@ void convert_src::setList(char *syyText) void convert_src::setNL(char *syyText, bool bMacro) { int nL; - std::string sKey, sObject; + std::string sKey; copySource(syyText); @@ -206,9 +206,9 @@ void convert_src::setNL(char *syyText, b msValue.erase(nL,1); } - sObject = msCmd + "." + msTextName; -//JIX if (msValue.size() && msValue != "-") -//JIX mcMemory.setEnUsKey(miLineNo, sKey, sObject, msValue); + sKey += "." + msCmd + "." + msTextName; + if (msValue.size() && msValue != "-") + mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, msValue); } if (!bMacro && mbExpectMacro) @@ -294,13 +294,6 @@ void convert_src::setListItem(char *syyT // check key or add seq. buildKey(myKey); -//JIX if (!mcMemory.checkKey(myKey, (msCmd + "." + msTextName))) - { - ssBuf << miListCount; - msName += ".uniq" + ssBuf.str(); - mcStack.pop_back(); - mcStack.push_back(msName); - } } } } Modified: openoffice/branches/l10n/main/l10ntools/source/gConUlfWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConUlfWrap.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConUlfWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConUlfWrap.cxx Sun Mar 10 00:00:20 2013 @@ -89,5 +89,5 @@ void convert_ulf::setValue(char *syyText nL = sText.rfind("\""); sText.erase(nL); -//JIX mcMemory.setEnUsKey(miLineNo, msKey, std::string("LngText"), sText); + mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, sText); } Modified: openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx Sun Mar 10 00:00:20 2013 @@ -153,8 +153,8 @@ void convert_xcs::stopCollectData(char * } #endif } -//JIX else -//JIX mcMemory.setEnUsKey(miLineNo, sKey, std::string("dummy"), sText); + else + mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, sText); mbCollectingData = false; } Modified: openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx Sun Mar 10 00:00:20 2013 @@ -168,9 +168,9 @@ void convert_xcu::stopCollectData(char * } #endif } -//JIX else -//JIX if (useText.size()) -//JIX mcMemory.setEnUsKey(miLineNo, useKey, "value", useText); + else + if (useText.size()) + mcMemory.setSourceKey(miLineNo, msSourceFile, useKey, useText); } Modified: openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx Sun Mar 10 00:00:20 2013 @@ -238,7 +238,7 @@ void convert_xhp::closeTransTag(char *yy if (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG) { if (msCollector.size() && msCollector != "-") -//JIX mcMemory.setEnUsKey(miLineNo, msKey, std::string("text"), msCollector); + mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, msCollector); msKey.clear(); } copySource(yytext); Modified: openoffice/branches/l10n/main/l10ntools/source/gConXrmWrap.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConXrmWrap.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gConXrmWrap.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gConXrmWrap.cxx Sun Mar 10 00:00:20 2013 @@ -147,7 +147,7 @@ void convert_xrm::stopCollectData(char * if (!mbNoCollectingData) { msKey = msKey + "." + msKey; -//JIX mcMemory.setEnUsKey(miLineNo, msKey, std::string("text"), msCollector); + mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, msCollector); mbNoCollectingData = true; msKey.clear(); } Modified: openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx Sun Mar 10 00:00:20 2013 @@ -80,13 +80,11 @@ void handler::checkCommandLine(int argc, if (sLangText[0] == '\"') sLangText.erase(0,1); nLen = sLangText.size() -1; - if (sLangText[nLen] == '\"') + if (nLen > 0 && sLangText[nLen] == '\"') sLangText.erase(nLen); - if (!sLangText.size()) - throw "<languages> is mandatory"; - - // and convert language to a vector + if (sLangText.size()) { + // and convert language to a vector int current; int next = -1; do @@ -128,6 +126,7 @@ void handler::checkCommandLine(int argc, { switch (eGotArg) { + case ARG_NONE: break; case ARG_F: mvSourceFiles.push_back(sArg); break; case ARG_O: msPoOutDir = sArg; eGotArg = ARG_NONE; break; case ARG_S: msSourceDir = sArg; eGotArg = ARG_NONE; break; @@ -160,7 +159,8 @@ void handler::checkCommandLine(int argc, } catch(const char *sErr) { - showUsage(std::string(sErr)); + std::string myErr(sErr); + showUsage(myErr); exit(-1); } catch(std::string sErr) @@ -184,7 +184,7 @@ void handler::checkCommandLine(int argc, msPoOutDir.append("/"); // tell system - mcMemory.showVerbose("gLang starting to " + sWorkText + " in module " + msModuleName); + mcMemory.showVerbose("gLang starting to " + sWorkText + " from module " + msModuleName); } @@ -198,7 +198,8 @@ void handler::run() mcMemory.setModuleName(msModuleName); // build list of languages (to be loaded and later written - loadL10MEM(); + if (msPoDir.size()) + loadL10MEM(); // use workMode to start correct control part switch (meWorkMode) @@ -210,7 +211,7 @@ void handler::run() case DO_GENERATE: runGenerate(); break; } } - catch(bool) + catch(int) { exit(-1); } @@ -221,6 +222,7 @@ void handler::run() /********************** I M P L E M E N T A T I O N **********************/ void handler::runExtractMerge(bool bMerge, bool bKid) { + bKid = bKid; //JIX HANDLE KID // loop through all source files, and extract messages from each file @@ -229,16 +231,13 @@ void handler::runExtractMerge(bool bMerg // tell system mcMemory.showDebug("gLang extracting text from file " + *siSource); - // prepare translation memory - mcMemory.setFileName(0, *siSource, true); - // get converter and extract files - convert_gen convertObj(mcMemory, msSourceDir + *siSource); + convert_gen convertObj(mcMemory, msSourceDir, *siSource); convertObj.execute(bMerge); } // and generate language file - mcMemory.save(msTargetDir + msModuleName); + mcMemory.save(msPoOutDir); } @@ -290,7 +289,9 @@ void handler::showManual() "genLang merges .po files with AOO sources to add languages.\n" "\n" "genLang can also convert old .po files (generated from .sdf)\n" - "\n" + "\n"; + + std::cout << "Syntax:\n" " genLang extract <module> <po dir> <languages> [-v] [-d]\\\n" " [-o <po outdir>] -f <files> -s <source dir>\n" @@ -333,7 +334,9 @@ void handler::showManual() "\n" " genLang help\n" " this text\n" - "\n" + "\n"; + + std::cout << "Parameters:\n" " <module>\n" " name of module (directory in main)\n" @@ -344,7 +347,7 @@ void handler::showManual() " comma separated string with langauge id to be used\n" "\n" " -d\n" - " extensive verbose mode, tells what gLang is doing in detail\n"; + " extensive verbose mode, tells what gLang is doing in detail\n" " -f <files>\n" " list of files containing messages to be extracted\n" " \"convert\" expect sdf generated po files, to be converted\n" @@ -368,34 +371,28 @@ void handler::showManual() /********************** I M P L E M E N T A T I O N **********************/ void handler::loadL10MEM() { - std::string sMod = "/" + msModuleName + ".pot"; - std::string sLoad = msPoDir + "../en-US" + sMod; + std::string sMod = msModuleName + ".po"; + std::string sLoad = msPoDir + "en-US"; // load texts from en-US po file (master) { - // prepare translation memory - mcMemory.setFileName(0, sLoad, true); - // tell system mcMemory.showDebug("gLang loading master text from file " + sLoad); // and load file - convert_gen(mcMemory, sLoad).execute(true); + convert_gen(mcMemory, sLoad, sMod).execute(true); } // loop through all languages and load text for (std::vector<std::string>::iterator siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang) { - sLoad = msPoDir + *siLang + sMod; - - // prepare translation memory - mcMemory.setFileName(0, sLoad, true); + sLoad = msPoDir + *siLang; // tell system mcMemory.showDebug("gLang loading text from language file " + sLoad); // get converter and extract files - convert_gen(mcMemory, sLoad).execute(false, true); + convert_gen(mcMemory, sLoad, sMod).execute(false, true); } } Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx Sun Mar 10 00:00:20 2013 @@ -82,7 +82,7 @@ int l10nMem::showWarning(const std::str void l10nMem::showDebug(const std::string& sText, int iLineNo) { l10nMem_impl::mcImpl->showDebug(sText, iLineNo); } void l10nMem::showVerbose(const std::string& sText, int iLineNo) - { l10nMem_impl::mcImpl->showWarning(sText, iLineNo); } + { l10nMem_impl::mcImpl->showVerbose(sText, iLineNo); } @@ -95,8 +95,8 @@ bool l10nMem::isError() /********************** I M P L E M E N T A T I O N **********************/ -void l10nMem::setModuleName(const std::string& setModuleName) - { l10nMem_impl::mcImpl->setModuleName(setModuleName); } +void l10nMem::setModuleName(const std::string& sModuleName) + { l10nMem_impl::mcImpl->setModuleName(sModuleName); } void l10nMem::loadENUSkey(int iL, const std::string& sS, const std::string& sK, const std::string& sT) { l10nMem_impl::mcImpl->mcDb.loadENUSkey(iL, sS, sK, sT); } void l10nMem::setLanguage(const std::string& sL, bool bC) @@ -105,16 +105,14 @@ void l10nMem::loadLangKey(int iL, const { l10nMem_impl::mcImpl->mcDb.loadLangKey(iL, sS, sK, sO, sT, bI); } void l10nMem::convLangKey(int iL, const std::string& sS, const std::string& sK, const std::string& sO, const std::string& sT, bool bI) { l10nMem_impl::mcImpl->convLangKey(iL, sS, sK, sO, sT, bI); } -void l10nMem::setFileName(int iL, const std::string& sS, bool bC) - { l10nMem_impl::mcImpl->mcDb.setFileName(iL, sS, bC); } bool l10nMem::checkKey(const std::string& sKey, const std::string& sText) { return l10nMem_impl::mcImpl->mcDb.locateKey(0, sKey, sText, false); } -void l10nMem::setSourceKey(int iL, const std::string& sK, const std::string& sT) - { l10nMem_impl::mcImpl->setSourceKey(iL, sK, sT); } +void l10nMem::setSourceKey(int iL, const std::string& sF, const std::string& sK, const std::string& sT) + { l10nMem_impl::mcImpl->setSourceKey(iL, sF, sK, sT); } void l10nMem::reorganize() { l10nMem_impl::mcImpl->mcDb.reorganize(); } void l10nMem::save(const std::string& sTargetDir) - { l10nMem_impl::mcImpl->save(sTargetDir); } + { l10nMem_impl::mcImpl->save(*this, sTargetDir); } void l10nMem::dumpMem(const std::string& sTargetDir) { l10nMem_impl::mcImpl->dumpMem(sTargetDir); } @@ -183,98 +181,105 @@ void l10nMem_impl::setModuleName(const s /********************** I M P L E M E N T A T I O N **********************/ void l10nMem_impl::setSourceKey(int iLineNo, + const std::string& sSourceFile, const std::string& sKey, const std::string& sText) { // if key exist update state - if (mcDb.locateKey(iLineNo, sKey, sText, false)) + if (mcDb.findFileName(sSourceFile, mcDb.miCurENUSinx+1, true) && + mcDb.locateKey(iLineNo, sKey, sText, false)) { - mcDb.mcENUSlist[mcDb.miCurENUSinx].meState = ENTRY_NORMAL; + mcDb.mcENUSlist[mcDb.miCurENUSinx].meState = l10nMem::ENTRY_NORMAL; } else { - // add key, if changed text this is wrong but handled in loadCleanup - mcDb.addKey(iLineNo, sKey, sText, ENTRY_ADDED); + // add key, if changed text this is wrong but handled in reorganize + mcDb.addKey(iLineNo, sKey, sText, l10nMem::ENTRY_ADDED); } } - - - - - - -#if 0 - void convLangKey (const std::string& sSourceFile, - const std::string& sKey, - const std::string& sOrgText, - const std::string& sText, - bool bIsFuzzy); - - void extractedKey (int iLineNo, - const std::string& sKey, - const std::string& sText); - - void save (const std::string& sTargetDir); - void dumpMem (const std::string& sTargetDir); - - void formatAndShowText(std::string& sType, int iLineNo, std::string& sText); - std::cerr << "ERROR in " << msCurrentSourceFileName << ":" << iLineNo << ": " << sText << std::endl; +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_impl::convLangKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sOrgText, + const std::string& sText, + bool bIsFuzzy) +{ + std::string x; + iLineNo = iLineNo; + x = sSourceFile; + x = sKey; + x = sOrgText; + x = sText; + bIsFuzzy = bIsFuzzy; + //JIX (convLangKey) +} /********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_impl::save(const std::string& srTargetFile) +void l10nMem_impl::save(l10nMem& cMem, const std::string& sTargetDir) { - int i; - std::string sFile = srTargetFile + ".cnv"; + int iE, iEsize = mcDb.mcENUSlist.size(); + int iL, iLsize = mcDb.mcLangList.size(); + std::string fileName = msModuleName + ".po"; - if (mbInError) + // Save en-US { - showError(0, (char *)"Cannot save file due to preceding errors"); - return; - } - - std::ofstream outputFile(sFile.c_str(), std::ios::binary); - - if (!outputFile.is_open()) - throw showError(std::string("Could not open ")+srTargetFile); + convert_gen savePo(cMem, sTargetDir, fileName); + savePo.startSave(sTargetDir, "en_US", fileName); + for (iE = 1; iE < iEsize; ++iE) + { + l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE]; + + savePo.save(cE.msKey, cE.msText, cE.msText, false); + } + savePo.endSave(); + } - for (i = 0; i < (int)mcMemory.size(); ++i) + // save all languages + for (iL = 1; iL < iLsize; ++iL) { - outputFile << mcMemory[i].msModuleName << "\t" << mcMemory[i].msSourceFile << "\t" - << mcMemory[i].msKey; - //if (mcMemory[i].miIndex) - // outputFile << "." << mcMemory[i].miIndex; - outputFile << "\t" << mcMemory[i].msLanguage << "\t" << mcMemory[i].msText << std::endl; + convert_gen savePo(cMem, sTargetDir, fileName); + + savePo.startSave(sTargetDir, mcDb.mcLangList[iL], fileName); + for (iE = 1; iE < iEsize; ++iE) + { + l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE]; + l10nMem_lang_entry& cL = cE.mcLangList[iL]; + bool bF = cL.mbFuzzy || (cE.meState == l10nMem::ENTRY_CHANGED); + savePo.save(cE.msKey, cE.msText, cL.msText, false); + } + savePo.endSave(); } - // JIX } /********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_impl::loadLangKey(const std::string& srLang, const std::string& srKey, const std::string& srObjectType, - const std::string& srText) +void l10nMem_impl::dumpMem(const std::string& srTargetFile) { + std::string x; + + x = srTargetFile; + // JIX (dumpMem) } /********************** I M P L E M E N T A T I O N **********************/ -std::vector<l10nMem_entry *>& l10nMem_impl::getLanguagesForKey(const std::string& srKey) -{ - int nL = mcMemory.size(); - - mcCurrentSelection.clear(); - if (srKey.size()) - for (int i = 0; i < nL; ++i) - if (mcMemory[i].msLanguage != "en-US") - mcCurrentSelection.push_back(&mcMemory[i]); - - return mcCurrentSelection; -} -#endif \ No newline at end of file +void l10nMem_impl::formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText) +{ + std::string& cFile = mcDb.mcFileList[mcDb.miCurFileInx].msFileName; + + std::cerr << sType; + if (cFile.size()) + std::cerr << " in " << mcDb.mcFileList[mcDb.miCurFileInx].msFileName; + if (iLineNo) + std::cerr << "(" << iLineNo << ")"; + std::cerr << ": " << sText << std::endl; +} \ No newline at end of file Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx Sun Mar 10 00:00:20 2013 @@ -93,6 +93,7 @@ class l10nMem_db int miCurENUSinx; int miCurLastENUSinx; bool mbNeedWrite; + bool mbReorganizeNeeded; std::vector<l10nMem_enus_entry> mcENUSlist; std::vector<l10nMem_file_entry> mcFileList; std::vector<std::string> mcLangList; @@ -104,6 +105,7 @@ class l10nMem_db const std::string& sText); void setLanguage (const std::string& sLanguage, bool bCreate); + bool findFileName (const std::string& sSourceFile, int iStart, bool bCreate); void loadLangKey (int iLineNo, const std::string& sSourceFile, const std::string& sKey, @@ -111,19 +113,16 @@ class l10nMem_db const std::string& sText, bool bFuzzy); - void setFileName (int iLineNo, - const std::string& sFilename, - bool bCreate); - void reorganize(); bool locateKey (int iLineNo, const std::string& sKey, const std::string& sText, bool bThrow = true); + void reorganize(); void addKey (int iLineNo, const std::string& sKey, const std::string& sText, - l10nMem::ENTRY_STATE eState); + l10nMem::ENTRY_STATE eStat); }; @@ -145,6 +144,7 @@ class l10nMem_impl void setSourceKey (int iLineNo, + const std::string& sFilename, const std::string& sKey, const std::string& sText); @@ -156,7 +156,7 @@ class l10nMem_impl const std::string& sText, bool bIsFuzzy); - void save (const std::string& sTargetDir); + void save (l10nMem& cMem, const std::string& sTargetDir); void dumpMem (const std::string& sTargetDir); private: Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx Sun Mar 10 00:00:20 2013 @@ -51,11 +51,11 @@ l10nMem_lang_entry::~l10nMem_lang_entry( /********************** I M P L E M E N T A T I O N **********************/ -l10nMem_enus_entry::l10nMem_enus_entry(const std::string& sKey, - const std::string& sText, - int iLineNo, - int iFileInx, - ENTRY_STATE eState) +l10nMem_enus_entry::l10nMem_enus_entry(const std::string& sKey, + const std::string& sText, + int iLineNo, + int iFileInx, + l10nMem::ENTRY_STATE eState) : msKey(sKey), msText(sText), @@ -96,10 +96,15 @@ l10nMem_file_entry::~l10nMem_file_entry( l10nMem_db::l10nMem_db() : miCurFileInx(0), - miCurLangInx(-1), - miCurENUSinx(-1), - mbNeedWrite(false) -{ + miCurLangInx(0), + miCurENUSinx(0), + miCurLastENUSinx(0), + mbNeedWrite(false), + mbReorganizeNeeded(false) +{ + mcFileList.push_back(l10nMem_file_entry("", 0)); + mcLangList.push_back(""); + mcENUSlist.push_back(l10nMem_enus_entry("", "", 0, 0, l10nMem::ENTRY_DELETED)); } @@ -117,26 +122,15 @@ void l10nMem_db::loadENUSkey(int const std::string& sKey, const std::string& sText) { - setFileName(iLineNo, sSourceFile, true); + // create file name if needed + if (mcFileList[miCurFileInx].msFileName != sSourceFile) + { + miCurFileInx = mcFileList.size(); + mcFileList.push_back(l10nMem_file_entry(sSourceFile, miCurENUSinx+1)); + } // add it to vector and update file pointer - addKey(iLineNo, sKey, sText, ENTRY_DELETED); - mcFileList[miCurFileInx].miEnd = miCurENUSinx; -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::loadLangKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sOrgText, - const std::string& sText, - bool bFuzzy) -{ - locateKey(iLineNo, sKey, sOrgText); - - mcENUSlist[miCurENUSinx].mcLangList.push_back(l10nMem_lang_entry(sText, bFuzzy)); + addKey(iLineNo, sKey, sText, l10nMem::ENTRY_DELETED); } @@ -158,60 +152,73 @@ void l10nMem_db::setLanguage(const std:: { if (bCreate) throw l10nMem::showError("loading " + sLanguage + " twice"); + return; } - else - { - if (bCreate) - mcLangList.push_back(sLanguage); - else - throw l10nMem::showError("language " + sLanguage + " not loaded"); - } + + // language does not exist in db + if (!bCreate) + throw l10nMem::showError("language " + sLanguage + " not loaded"); + + // create language + mcLangList.push_back(sLanguage); + + // add language to all ENUS entries + iSize = mcENUSlist.size(); + for (int i = 0; i < iSize; ++i) + mcENUSlist[i].mcLangList.push_back(l10nMem_lang_entry("", false)); } /********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::setFileName(int iLineNo, - const std::string& sFilename, - bool bCreate) +bool l10nMem_db::findFileName(const std::string& sSourceFile, int iStart, bool bCreate) { int iSize = mcFileList.size(); - // Same file as last - if (mcFileList[miCurFileInx].msFileName == sFilename) - return; + // Check this or next file + if (mcFileList[miCurFileInx].msFileName == sSourceFile) + return true; + if (++miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName == sSourceFile) + return true; + + for (miCurFileInx = 0; + miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName == sSourceFile; + ++miCurFileInx) ; - // Locate file in index (or add it) - for (miCurFileInx = 0; miCurFileInx < iSize && - mcFileList[miCurFileInx].msFileName != sFilename; ++miCurFileInx) ; - if (miCurFileInx == iSize) + if (bCreate && miCurFileInx < iSize) { - if (bCreate) - mcFileList.push_back(l10nMem_file_entry(sFilename, mcENUSlist.size())); - else - throw l10nMem::showError("file " + sFilename + " not located in po files", iLineNo); + mcFileList.push_back(l10nMem_file_entry(sSourceFile, iStart)); + miCurFileInx = iSize; } + return (miCurFileInx < iSize); } /********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::loadCleanup(bool bMaster) +void l10nMem_db::loadLangKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sOrgText, + const std::string& sText, + bool bFuzzy) { - if (bMaster) - { - // JIX - } - else - { - // Insert dummy entries for missing lang entries - int i, iSizeENUS = mcENUSlist.size(); - int iSizeLang = mcLangList.size(); - - for (i = 0; i < iSizeENUS; ++i) - if (iSizeLang > (int)mcENUSlist[i].mcLangList.size()) - mcENUSlist[i].mcLangList.push_back(l10nMem_lang_entry("", true)); - } + if (!findFileName(sSourceFile, false, 0)) + throw l10nMem::showError(".po file contains unknown filename: " + sSourceFile); + + locateKey(iLineNo, sKey, sOrgText); + + l10nMem_lang_entry& xCur = mcENUSlist[miCurENUSinx].mcLangList[miCurLangInx]; + xCur.msText = sText; + xCur.mbFuzzy = bFuzzy; +} + + + +/********************** I M P L E M E N T A T I O N **********************/ +void l10nMem_db::reorganize() +{ + // JIX (reorganize) } @@ -225,6 +232,14 @@ bool l10nMem_db::locateKey(int // Start from beginning of file and to end l10nMem_file_entry& cCur = mcFileList[miCurFileInx]; + // Fast check first + if (miCurENUSinx < (int)mcENUSlist.size() -1) + { + l10nMem_enus_entry& nowEntry = mcENUSlist[++miCurENUSinx]; + if (nowEntry.msText == sText && nowEntry.msKey == sKey) + return true; + } + // Find match with key and text for (miCurENUSinx = cCur.miStart; miCurENUSinx <= cCur.miEnd; ++miCurENUSinx) { @@ -242,12 +257,12 @@ bool l10nMem_db::locateKey(int /********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::addKey(int iLineNo, - const std::string& sKey, - const std::string& sText, - ENTRY_STATE eState) +void l10nMem_db::addKey(int iLineNo, + const std::string& sKey, + const std::string& sText, + l10nMem::ENTRY_STATE eStat) { - // add it to vector and update file pointer miCurENUSinx = mcENUSlist.size(); - mcENUSlist.push_back(l10nMem_enus_entry(sKey, sText, iLineNo, miCurFileInx, eState)); -} \ No newline at end of file + mcENUSlist.push_back(l10nMem_enus_entry(sKey, sText, iLineNo, miCurFileInx, eStat)); + miCurLastENUSinx = mcFileList[miCurFileInx].miEnd = miCurENUSinx; +} Modified: openoffice/branches/l10n/main/l10ntools/source/gLang.hxx URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gLang.hxx?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/gLang.hxx (original) +++ openoffice/branches/l10n/main/l10ntools/source/gLang.hxx Sun Mar 10 00:00:20 2013 @@ -35,13 +35,6 @@ /******************* G L O B A L D E F I N I T I O N *******************/ -typedef enum -{ - ENTRY_DELETED, - ENTRY_ADDED, - ENTRY_CHANGED, - ENTRY_NORMAL -} ENTRY_STATE; @@ -56,6 +49,13 @@ class l10nMem l10nMem(); ~l10nMem(); + typedef enum + { + ENTRY_DELETED, + ENTRY_ADDED, + ENTRY_CHANGED, + ENTRY_NORMAL + } ENTRY_STATE; static void setShowVerbose (); static void setShowDebug (); @@ -64,16 +64,13 @@ class l10nMem static int showWarning (const std::string& sText, int iLineNo = 0); static void showDebug (const std::string& sText, int iLineNo = 0); static void showVerbose (const std::string& sText, int iLineNo = 0); - bool isError (); + bool isError (); void setModuleName (const std::string& sModuleName); - void loadENUSkey (int iLineNo, const std::string& sSourceFile, const std::string& sKey, const std::string& sText); - void loadCleanup (bool bMaster); - void setLanguage (const std::string& sLanguage, bool bCreate); void loadLangKey (int iLineNo, @@ -82,6 +79,8 @@ class l10nMem const std::string& sOrgText, const std::string& sText, bool bIsFuzzy); + + void convLangKey (int iLineNo, const std::string& sSourceFile, const std::string& sKey, @@ -89,14 +88,13 @@ class l10nMem const std::string& sText, bool bIsFuzzy); - void setFileName (int iLineNo, - const std::string& sFilename, - bool bCreate); bool checkKey (const std::string& sKey, const std::string& sText); void setSourceKey (int iLineNo, + const std::string& sFilename, const std::string& sKey, const std::string& sText); + void reorganize (); void save (const std::string& sTargetDir); void dumpMem (const std::string& sTargetDir); @@ -109,11 +107,21 @@ class l10nMem class convert_gen { public: - convert_gen(l10nMem& cMemory, const std::string& sSourceFile); + convert_gen(l10nMem& cMemory, const std::string& sSourceDir, const std::string& sSourceFile); ~convert_gen(); // do extract/merge bool execute(const bool bMerge, const bool bAllowNoFile = false); + + // ONLY po should implement these functions + void startSave(const std::string& sTargetDir, + const std::string& sLanguage, + const std::string& sFile); + void save(const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy); + void endSave(); }; Modified: openoffice/branches/l10n/main/l10ntools/source/makefile.mk URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/makefile.mk?rev=1454775&r1=1454774&r2=1454775&view=diff ============================================================================== --- openoffice/branches/l10n/main/l10ntools/source/makefile.mk (original) +++ openoffice/branches/l10n/main/l10ntools/source/makefile.mk Sun Mar 10 00:00:20 2013 @@ -169,7 +169,7 @@ APP7STDLIBS+= \ # localizer for new l10n framework APP8TARGET= genLang APP8OBJS= $(OBJ)$/gLang.obj $(OBJ)$/gL10nMem.obj \ - $(OBJ)$/gL10MemDB.obj $(OBJ)$/gHandler.obj \ + $(OBJ)$/gL10nMemDB.obj $(OBJ)$/gHandler.obj \ $(OBJ)$/gConProp.obj $(OBJ)$/gConTree.obj \ $(OBJ)$/gCon.obj $(OBJ)$/gConDB.obj \ $(OBJ)$/gConPoWrap.obj $(OBJ)$/gConSrcWrap.obj \