You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ja...@apache.org on 2013/03/03 22:53:35 UTC
svn commit: r1452135 - in /openoffice/branches/l10n/main/l10ntools/source:
gCon.cxx gCon.hxx gConDB.cxx gConDB.hxx gConPoWrap.cxx gConXcsWrap.cxx
gConXcuWrap.cxx gConXhpWrap.cxx gHandler.cxx gL10nMem.cxx gL10nMem.hxx
gLang.hxx
Author: jani
Date: Sun Mar 3 21:53:34 2013
New Revision: 1452135
URL: http://svn.apache.org/r1452135
Log:
Load of modified sdf works for languages (de,da,fr)
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/gConDB.hxx
openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.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/gHandler.cxx
openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx
openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx
openoffice/branches/l10n/main/l10ntools/source/gLang.hxx
Modified: openoffice/branches/l10n/main/l10ntools/source/gCon.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gCon.cxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gCon.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gCon.cxx Sun Mar 3 21:53:34 2013
@@ -19,6 +19,7 @@
*
*************************************************************/
#include "gCon.hxx"
+#include "gConDB.hxx"
#include "gConPo.hxx"
#include "gConProp.hxx"
#include "gConSrc.hxx"
@@ -49,7 +50,7 @@ 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(const std::string& srSourceFile, l10nMem& crMemory, const bool bMerge)
+convert_gen::convert_gen(l10nMem& crMemory, const std::string& srSourceFile)
{
// did the user give a .xxx with the source file ?
int nInx = srSourceFile.rfind(".");
@@ -65,6 +66,7 @@ convert_gen::convert_gen(const std::stri
if (sExtension == "hrc") convert_gen_impl::mcImpl = new convert_src(crMemory);
else if (sExtension == "src") convert_gen_impl::mcImpl = new convert_src(crMemory);
else if (sExtension == "po") convert_gen_impl::mcImpl = new convert_po(crMemory);
+ else if (sExtension == "pot") convert_gen_impl::mcImpl = new convert_db(crMemory);
else if (sExtension == "tree") convert_gen_impl::mcImpl = new convert_tree(crMemory);
else if (sExtension == "ulf") convert_gen_impl::mcImpl = new convert_ulf(crMemory);
else if (sExtension == "xcu") convert_gen_impl::mcImpl = new convert_xcu(crMemory);
@@ -75,7 +77,6 @@ convert_gen::convert_gen(const std::stri
// and set environment
convert_gen_impl::mcImpl->msSourceFile = srSourceFile;
- convert_gen_impl::mcImpl->mbMergeMode = bMerge;
}
@@ -89,8 +90,10 @@ convert_gen::~convert_gen()
/********************** I M P L E M E N T A T I O N **********************/
-void convert_gen::execute()
+void convert_gen::execute(const bool bMerge)
{
+ convert_gen_impl::mcImpl->mbMergeMode = bMerge;
+
// and load file
convert_gen_impl::mcImpl->prepareFile();
@@ -102,8 +105,8 @@ void convert_gen::execute()
/********************** 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)
+ : mcMemory(crMemory),
+ miLineNo(1)
{
}
@@ -127,7 +130,7 @@ void convert_gen_impl::prepareFile()
throw showError((char *)"Cannot open file");
// get length of file:
- mnSourceReadIndex = 0;
+ miSourceReadIndex = 0;
inputFile.seekg (0, std::ios::end);
msSourceBuffer.resize((unsigned int)inputFile.tellg());
inputFile.seekg (0, std::ios::beg);
@@ -146,26 +149,26 @@ void convert_gen_impl::prepareFile()
void convert_gen_impl::lexRead(char *sBuf, int *nResult, int nMax_size)
{
// did we hit eof
- if (mnSourceReadIndex == -1)
+ if (miSourceReadIndex == -1)
{
*nResult = 0;
return;
}
// assume we can copy all that are left.
- *nResult = msSourceBuffer.size() - mnSourceReadIndex;
+ *nResult = msSourceBuffer.size() - miSourceReadIndex;
// space enough for the whole line ?
if (*nResult <= nMax_size)
{
- msSourceBuffer.copy(sBuf, *nResult, mnSourceReadIndex);
- mnSourceReadIndex = -1;
+ msSourceBuffer.copy(sBuf, *nResult, miSourceReadIndex);
+ miSourceReadIndex = -1;
}
else
{
- msSourceBuffer.copy(sBuf, nMax_size, mnSourceReadIndex);
+ msSourceBuffer.copy(sBuf, nMax_size, miSourceReadIndex);
*nResult = nMax_size;
- mnSourceReadIndex += nMax_size;
+ miSourceReadIndex += nMax_size;
}
}
@@ -193,7 +196,7 @@ std::string& convert_gen_impl::copySourc
// write text for merge
if (mbMergeMode)
- writeSourceFile(msCollector + msCopyText);
+ writeSourceFile(msCopyText);
if (bDoClear)
msCollector.clear();
@@ -203,13 +206,13 @@ std::string& convert_gen_impl::copySourc
// remove any CR
for (nL = 0; nL < (int)msCopyText.size(); ++nL)
{
- if (msCopyText[nL] == '\r')
- {
- msCopyText.erase(nL, 1);
- --nL;
- continue;
- }
- if (msCopyText[nL] == '\n')
+ if (msCopyText[nL] == '\r')
+ {
+ msCopyText.erase(nL, 1);
+ --nL;
+ continue;
+ }
+ if (msCopyText[nL] == '\n')
++miLineNo;
}
Modified: openoffice/branches/l10n/main/l10ntools/source/gCon.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gCon.hxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gCon.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gCon.hxx Sun Mar 3 21:53:34 2013
@@ -59,14 +59,14 @@ class convert_gen_impl
// utility functions for converters
- void lexRead (char *sBuf, int *nResult, int nMax_size);
- void writeSourceFile(const std::string& line);
- std::string showError(char *sText);
+ void lexRead (char *sBuf, int *nResult, int nMax_size);
+ void writeSourceFile(const std::string& line);
+ std::string showError(char *sText);
std::string& copySource(char *yyText, bool bDoClear = true);
- private:
+ protected:
std::string msSourceBuffer, msCopyText;
- int mnSourceReadIndex;
+ int miSourceReadIndex;
void prepareFile();
Modified: openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx Sun Mar 3 21:53:34 2013
@@ -39,4 +39,70 @@ convert_db::~convert_db()
/********************** I M P L E M E N T A T I O N **********************/
void convert_db::execute()
{
-}
\ No newline at end of file
+ std::string oldKey;
+ int iB, iE;
+
+
+ msSourceBuffer += '\n';
+ miSize = msSourceBuffer.size() -1;
+
+ while (collectLine())
+ {
+ mcMemory.setFileName(msFields[0]);
+ if (mbMergeMode)
+ {
+ iB = msFields[15].find("/");
+ if (iB == (int)std::string::npos)
+ showError("missing / in en_US");
+ iE = msFields[15].find("/", iB+1);
+ if (iE == (int)std::string::npos)
+ showError("missing / in en_US");
+ oldKey = msFields[15].substr(iB+1, iE - iB -1);
+ iB = msFields[15].find("/",iE+1);
+ if (iB == (int)std::string::npos)
+ showError("missing / in en_US");
+ if (iB != iE+1)
+ oldKey += "." + msFields[15].substr(iE+1, iB - iE -1);
+
+ // handle en-US (master)
+ mcMemory.loadEnUsKey(msFields[4], msFields[3], msFields[10], oldKey);
+ }
+ else
+ {
+ std::string newKey = msFields[4];
+ if (msFields[5].size())
+ newKey += "." + msFields[5];
+ mcMemory.loadLangKey(msFields[9], newKey, msFields[3], msFields[10]);
+ }
+ }
+}
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+bool convert_db::collectLine()
+{
+ int i, iStart;
+ bool bLineEnd;
+
+ for (i = 0; i < NUMFIELD; ++i)
+ msFields[i].clear();
+
+ for (i = 0, bLineEnd = false, iStart = miSourceReadIndex; !bLineEnd; ++miSourceReadIndex)
+ {
+ if (msSourceBuffer[miSourceReadIndex] == '\r' ||
+ msSourceBuffer[miSourceReadIndex] == '\n' ||
+ miSourceReadIndex == miSize)
+ bLineEnd = true;
+ if (msSourceBuffer[miSourceReadIndex] == '\t' || bLineEnd)
+ {
+ if (i >= NUMFIELD)
+ {
+ showError("TOO many fields");
+ exit(-1);
+ }
+ msFields[i++] = msSourceBuffer.substr(iStart, miSourceReadIndex - iStart);
+ iStart = miSourceReadIndex +1;
+ }
+ }
+ return (miSourceReadIndex < miSize);
+}
Modified: openoffice/branches/l10n/main/l10ntools/source/gConDB.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConDB.hxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConDB.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConDB.hxx Sun Mar 3 21:53:34 2013
@@ -40,6 +40,11 @@ class convert_db : public convert_gen_im
~convert_db();
private:
+ static const int NUMFIELD = 16;
+ std::string msFields[NUMFIELD];
+ int miSize;
+
void execute();
+ bool collectLine();
};
#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=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx Sun Mar 3 21:53:34 2013
@@ -77,6 +77,7 @@ void convert_po::stopCollectData(char *s
if (mbMergeMode)
{
+#if 0
// get all languages (includes en-US)
std::vector<l10nMem_entry *>& cExtraLangauges = mcMemory.getLanguagesForKey(useKey);
std::string sNewLine;
@@ -89,6 +90,7 @@ void convert_po::stopCollectData(char *s
cExtraLangauges[i]->msText + "</value>";
writeSourceFile(sNewLine);
}
+#endif
}
else
mcMemory.setEnUsKey(miLineNo, useKey, std::string("dummy"), sCollectedText);
Modified: openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConXcsWrap.cxx Sun Mar 3 21:53:34 2013
@@ -136,6 +136,7 @@ void convert_xcs::stopCollectData(char *
if (mbMergeMode)
{
+#if 0
// get all languages (includes en-US)
std::vector<l10nMem_entry *>& cExtraLangauges = mcMemory.getLanguagesForKey(sKey);
std::string sNewLine;
@@ -150,6 +151,7 @@ void convert_xcs::stopCollectData(char *
writeSourceFile(sNewLine);
}
+#endif
}
else
mcMemory.setEnUsKey(miLineNo, sKey, std::string("dummy"), sText);
Modified: openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConXcuWrap.cxx Sun Mar 3 21:53:34 2013
@@ -155,6 +155,7 @@ void convert_xcu::stopCollectData(char *
if (mbMergeMode)
{
// get all languages (includes en-US)
+#if 0
std::vector<l10nMem_entry *>& cExtraLangauges = mcMemory.getLanguagesForKey(useKey);
std::string sNewLine;
nL = cExtraLangauges.size();
@@ -165,6 +166,7 @@ void convert_xcu::stopCollectData(char *
cExtraLangauges[i]->msText + "</value>";
writeSourceFile(sNewLine);
}
+#endif
}
else
if (useText.size())
Modified: openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConXhpWrap.cxx Sun Mar 3 21:53:34 2013
@@ -215,7 +215,7 @@ void convert_xhp::setRef(char *yytext)
break;
case VALUE_NOT_USED:
- VALUE_IS_VALUE:
+ case VALUE_IS_VALUE:
break;
}
}
Modified: openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx Sun Mar 3 21:53:34 2013
@@ -35,148 +35,133 @@
/********************** I M P L E M E N T A T I O N **********************/
-handler::handler() {}
-handler::~handler() {}
+handler::handler()
+ : mbVerbose(false)
+{
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+handler::~handler()
+{
+}
/********************** I M P L E M E N T A T I O N **********************/
void handler::checkCommandLine(int argc, char *argv[])
{
+ enum {ARG_NONE, ARG_F, ARG_O, ARG_S, ARG_T} eGotArg = ARG_NONE;
std::string sWorkText;
+ int argNow, nLen;
// make internal throw test (to avoid if cascades
try
{
- // check for parameter count
- if (argc <= 1)
- throw std::string("");
+ // check for fixed parameter: genLang <cmd> <module> <po dir> <languages>
+ if (argc <= 5)
+ throw std::string("Not enough parameters");
// check for working mode
sWorkText = argv[1];
+ if (sWorkText == "convert") meWorkMode = DO_CONVERT;
+ else if (sWorkText == "extract") meWorkMode = DO_EXTRACT;
+ else if (sWorkText == "help") showManual();
+ else if (sWorkText == "merge") meWorkMode = DO_EXTRACT;
+ else throw std::string("<command> is mandatory");
+
+ // and set fixed parameters
+ msModuleName = argv[2];
+ msPoOutDir = msPoDir = argv[3];
+ sWorkText = argv[4];
+ if (sWorkText[0] == '\"')
+ sWorkText.erase(0,1);
+ nLen = sWorkText.size() -1;
+ if (sWorkText[nLen] == '\"')
+ sWorkText.erase(nLen);
+ if (!sWorkText.size())
+ throw std::string("<languages> is mandatory");
- if (sWorkText == "extract") meWorkMode = DO_EXTRACT;
- else if (sWorkText == "merge") meWorkMode = DO_EXTRACTMERGE;
- else if (sWorkText == "generate") meWorkMode = DO_GENERATE;
- else if (sWorkText == "insert") meWorkMode = DO_INSERT;
- else if (sWorkText == "--help") throw std::string("");
- else throw std::string("unknown mode (1 argument)");
-
+ // and convert language to a vector
+ {
+ int current;
+ int next = -1;
+ do
+ {
+ current = next + 1;
+ next = sWorkText.find_first_of( ",", current );
+ mvLanguages.push_back(sWorkText.substr(current,next-current));
+ }
+ while (next != (int)std::string::npos);
+ }
+
// decode parameters and translate to variables
- for (int n = 2; n < argc; ++n)
+ for (argNow = 5; argNow < argc;)
{
- std::string sArg(argv[n]);
+ std::string sArg(argv[argNow++]);
- // all -x is followed by a directory
- if (sArg.at(0) == '-')
+ // all -x is followed by a directory/file name
+ if (sArg[0] == '-')
{
- if (n == argc)
- throw std::string("missing directory after ")+sArg;
-
- // find directory type, and set it
- if (sArg == "-m") msModuleName = argv[++n];
- else if (sArg == "-t") msTargetDir = argv[++n];
- else if (sArg == "-s") msSourceDir = argv[++n];
- else if (sArg == "-v") mbVerbose = true;
- else throw std::string("unknown parameter: ")+sArg;
+ // Terminate collection ?
+ if (eGotArg == ARG_F)
+ eGotArg = ARG_NONE;
+
+ // Are we waiting for a directory
+ if (eGotArg != ARG_NONE)
+ throw (std::string("missing argument to ") + argv[argNow-1]);
+
+ // is it a known parameter
+ if (sArg == "-f") eGotArg = ARG_F;
+ else if (sArg == "-o") eGotArg = ARG_O;
+ else if (sArg == "-s") eGotArg = ARG_S;
+ else if (sArg == "-t") eGotArg = ARG_T;
+ else if (sArg == "-v") mbVerbose = true;
+ else throw std::string("unknown parameter: ")+sArg;
}
else
- msSourceFiles.push_back(sArg);
+ {
+ switch (eGotArg)
+ {
+ 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;
+ case ARG_T: msTargetDir = sArg; eGotArg = ARG_NONE; break;
+ }
+ }
}
// check parameters according to function
- switch (meWorkMode)
- {
- case DO_EXTRACT:
- // required parameters
- if (!msModuleName.size()) throw std::string("missing -m <module name>");
- if (!msTargetDir.size()) throw std::string("missing -t <target dir>");
- if (!msSourceFiles.size()) throw std::string("missing source files");
- break;
-
- case DO_EXTRACTMERGE:
- // required parameters
- if (!msSourceDir.size()) throw std::string("missing -s <source dir>");
- if (!msTargetDir.size()) throw std::string("missing -t <target dir>");
-
- // not allowed parameters
- if (msModuleName.size()) throw std::string("-m is invalid with merge");
- if (msSourceFiles.size()) throw std::string("<source> is invalid with merge");
- break;
-
- case DO_GENERATE:
- // required parameters
- if (!msSourceDir.size()) throw std::string("missing -s <source dir>");
- if (!msTargetDir.size()) throw std::string("missing -t <target dir>");
-
- // not allowed parameters
- if (msModuleName.size()) throw std::string("-m is invalid with generate");
- if (!msSourceFiles.size()) throw std::string("<source> is invalid with generate");
- break;
-
- case DO_INSERT:
- // required parameters
- if (!msModuleName.size()) throw std::string("missing -m <module name>");
- if (!msSourceDir.size()) throw std::string("missing -s <source dir>");
-
- // not allowed parameters
- if (!msSourceFiles.size()) throw std::string("<source> is invalid with generate");
- break;
- }
+ if (!mvSourceFiles.size())
+ throw std::string("-f <files> is mandatory");
+
+ // partly valid
+ if (meWorkMode != DO_MERGE && msTargetDir.size())
+ throw std::string("-t is mandatory using \"extract\"");
+ if (meWorkMode == DO_MERGE && !msTargetDir.size())
+ throw std::string("-t is only valid using \"extract\"");
}
catch(std::string sErr)
{
- // do we have an error text ?
- if (sErr.size())
- std::cerr << "commandline error:" << sErr << std::endl;
-
- // give the correct usage
- std::cout << "genLang (c)2013 by Apache Software Foundation\n"
- "====================================\n"
- "As part of the L10N framework, genLang extracts and merges translations\n"
- "out of and into the whole source tree.\n\n"
- "Syntax:\n"
- " genLang extract -m <name> [-s <source dir>] -t <target dir> <sources>\n"
- " genLang merge -s <source dir> -t <target dir>\n"
- " genLang generate -s <source dir> -t <target dir>\n"
- " genLang insert -s <source dir> -m <name> [-t <target dir>]\n"
- " genLang --help\n"
- "Parameters:\n"
- " extract, causes a scan of the <sources> for en-US text, and creates\n"
- " a module file: <target dir>/<module name>\n"
- " -s can optionally be used to specify the root of <source>\n"
- " merge, causes a merge of the en-US files in <source dir> with the\n"
- " native language files in <target dir>/*\n"
- " generate, uses the native language files in <source dir> to build\n"
- " module files in <target dir> with all language\n"
- " insert, uses the module file <source dir>/<module name> to\n"
- " update the source files in the module"
- "\n"
- " -v verbose mode, tells what gLang is doing\n"
- " -m <modulename> name of the module, used in file naming\n"
- " -s <source dir> extract: source file directory\n"
- " merge: language staging input directory\n"
- " generate: native language directory\n"
- " insert: language staging output directory\n"
- " -t <target dir> extract: language staging input directory\n"
- " merge: native language directory\n"
- " generate: language output staging directory\n"
- " <sources> list of files containing messages to be extracted\n";
+ showUsage(sErr);
exit(-1);
}
// update directories to include final /
- {
- int nLen;
-
- nLen = msSourceDir.size();
- if (nLen && msSourceDir.at(nLen-1) != '/')
- msSourceDir.append("/");
- nLen = msTargetDir.size();
- if (msTargetDir.at(nLen-1) != '/')
- msTargetDir.append("/");
- }
+ nLen = msSourceDir.size();
+ if (nLen && msSourceDir.at(nLen-1) != '/')
+ msSourceDir.append("/");
+ nLen = msTargetDir.size();
+ if (nLen && msTargetDir.at(nLen-1) != '/')
+ msTargetDir.append("/");
+ nLen = msPoDir.size();
+ if (nLen && msPoDir.at(nLen-1) != '/')
+ msPoDir.append("/");
+ nLen = msPoOutDir.size();
+ if (nLen && msPoOutDir.at(nLen-1) != '/')
+ msPoOutDir.append("/");
// tell system
if (mbVerbose)
@@ -190,13 +175,18 @@ void handler::run()
{
try
{
+ // prepare translation memory to module type
+ mcMemory.setModuleName(msModuleName);
+
+ // build list of languages (to be loaded and later written
+ loadL10MEM();
+
// use workMode to start correct control part
switch (meWorkMode)
{
- case DO_EXTRACT: runExtractMerge(false); break;
- case DO_EXTRACTMERGE: runExtractMerge(true); break;
- case DO_GENERATE: runGenerate(); break;
- case DO_INSERT: runInsert(); break;
+ case DO_EXTRACT: runExtractMerge(false); break;
+ case DO_MERGE: runExtractMerge(true); break;
+ case DO_CONVERT: runConvert(); break;
}
}
catch(std::string sErr)
@@ -211,11 +201,9 @@ void handler::run()
/********************** I M P L E M E N T A T I O N **********************/
void handler::runExtractMerge(bool bMerge)
{
- // prepare translation memory to module type
- mcMemory.setModuleName(msModuleName);
// loop through all source files, and extract messages from each file
- for (std::vector<std::string>::iterator siSource = msSourceFiles.begin(); siSource != msSourceFiles.end(); ++siSource)
+ for (std::vector<std::string>::iterator siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource)
{
// tell system
if (mbVerbose)
@@ -225,26 +213,155 @@ void handler::runExtractMerge(bool bMerg
mcMemory.setFileName(*siSource);
// get converter and extract files
- convert_gen convertObj(msSourceDir + *siSource, mcMemory, bMerge);
- convertObj.execute();
+ convert_gen convertObj(mcMemory, msSourceDir + *siSource);
+ convertObj.execute(bMerge);
}
// and generate language file
- mcMemory.save(msTargetDir + msModuleName);
+// mcMemory.save(msTargetDir + msModuleName);
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void handler::runConvert()
+{
+ throw std::string("handler::runConvert not implemented");
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void handler::showUsage(std::string& sErr)
+{
+ // do we have an error text ?
+ if (sErr.size())
+ std::cerr << "commandline error:" << sErr << std::endl;
+
+ std::cout <<
+ "syntax oveview, use \"genLang help\" for full description\n"
+ "genLang <cmd> <module> <po dir> <languages> [-f <files>] [-o <dir>] [-s <dir>] [-t <dir>] [-v]\n"
+ "<cmd> is one of \"convert\", \"extract\", \"help\", \"merge\"\n";
+
+ exit(-1);
}
/********************** I M P L E M E N T A T I O N **********************/
-void handler::runGenerate()
+void handler::showManual()
{
- throw std::string("handler::runGenerate not implemented");
+ // give the correct usage
+ std::cout <<
+ "genLang (c)2013 by Apache Software Foundation\n"
+ "=============================================\n"
+ "As part of the L10N framework for Apache Open Office (AOO),\n"
+ "genLang extracts en-US texts sources of the following types:\n"
+ " .xrm, .xhp, .xcu, .xcs, .ulf, .tree, .src, .prop and .po\n"
+ "and merges with .po files in different languages.\n"
+ "genLang merges .po files with AOO sources to add languages.\n"
+ "\n"
+ "genLang can also convert old .po files (generated from .sdf)\n"
+ "\n"
+ "Syntax:\n"
+ " genLang extract <module> <po dir> <languages> [-v] \\\n"
+ " [-o <po outdir>] -f <files> -s <source dir>\n"
+ " reads <po dir>/*lang/<module>.po files and extract text\n"
+ " from <source dir>/<files>, result is merged and\n"
+ " written to <po outdir>/*lang/<module>.po if -o present\n"
+ " or <po dir>/*lang/<module>.po is overwritten\n"
+ " - File will only be written if they are changes\n"
+ " - Keys in .po files, not in sources files (deleted keys)\n"
+ " are moved to '-p <dir>'/<module>.deleted.po\n"
+ " - Keys in .po files, with changed text in the source\n"
+ " are marked \"fuzzy\"\n"
+ " - Keys in source files not in .po files (new keys)\n"
+ " are added and marked \"fuzzy\"\n"
+ "\n"
+ " genLang merge <module> <po dir> <languages> [-v]\\\n"
+ " [-o <po outdir>] -f <files> -s <source dir> \\\n"
+ " -t <target dir>\n"
+ " works as \"extract\" and additionally merges\n"
+ " <source dir>/<files> with all native language text\n"
+ " from <po dir>/*lang/<module>.po\n"
+ " The result is stored in <target dir>/<files>\n"
+ "\n"
+ " genLang convert <module> <po dir> <languages> [-v] \\\n"
+ " [-o <po outdir>] -f <files>\n"
+ " reads sdf generated .po <files> and merges with\n"
+ " <po dir>/*lang/<module>.po\n"
+ " Result is written to <po outdir>/*lang/<module>.po if\n"
+ " - present or <po dir>/*lang/<module>.po is overwritten\n"
+ " - File will only be written if they are changes\n"
+ " - Keys in <files>, not in <module>.po\n"
+ " are moved to <po dir>/<module>.deleted.po\n"
+ " - Keys in <files>, with changed translation\n"
+ " are marked \"fuzzy\"\n"
+ " Result is written to <po outdir>/*lang/<module>.po if\n"
+ " -o present or <po dir>/*lang/<module>.po is overwritten\n"
+ "\n"
+ " genLang help\n"
+ " this text\n"
+ "\n"
+ "Parameters:\n"
+ " <module>\n"
+ " name of module (directory in main)\n"
+ " <po dir>\n"
+ " directory containing a directory for each language which contains\n"
+ " a .po file for each module\n"
+ " <languages>\n"
+ " comma separated string with langauge id to be used\n"
+ "\n"
+ " -f <files>\n"
+ " list of files containing messages to be extracted\n"
+ " \"convert\" expect sdf generated po files, to be converted\n"
+ " -o <po outdir>\n"
+ " directory to write .po files, same structure as -p\n"
+ " -s <source dir>\n"
+ " directory containing all source files (root path for <files>\n"
+ " -t <target dir>\n"
+ " <directory> used to write merged source files (root path for <files>\n"
+ " -v\n"
+ " verbose mode, tells what gLang is doing\n";
+
+ exit(0);
}
/********************** I M P L E M E N T A T I O N **********************/
-void handler::runInsert()
+void handler::loadL10MEM()
{
- throw std::string("handler::runInsert not implemented");
+ std::string sMod = "/" + msModuleName + ".pot";
+ std::string sLoad = msPoDir + "en-US" + sMod;
+
+
+ // load texts from en-US po file (master)
+ {
+ // prepare translation memory
+ mcMemory.setFileName(sLoad);
+
+ // tell system
+ if (mbVerbose)
+ std::cout << "gLang loading master text from file " << sLoad << std::endl;
+
+ // and load file
+ convert_gen(mcMemory, sLoad).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(sLoad);
+
+ // tell system
+ if (mbVerbose)
+ std::cout << "gLang loading text from language file " << sLoad << std::endl;
+
+ // get converter and extract files
+ convert_gen(mcMemory, sLoad).execute(false);
+ }
}
Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx Sun Mar 3 21:53:34 2013
@@ -18,7 +18,7 @@
* under the License.
*
*************************************************************/
-#include "gLang.hxx"
+#include "gL10nMem.hxx"
#include <algorithm>
#include <iostream>
#include <fstream>
@@ -35,18 +35,109 @@
+/******************* G L O B A L D E F I N I T I O N *******************/
+l10nMem_impl * l10nMem_impl::mcImpl = NULL;
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+l10nMem::l10nMem()
+{
+ l10nMem_impl::mcImpl = new l10nMem_impl();
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+l10nMem::~l10nMem()
+{
+ delete l10nMem_impl::mcImpl;
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+std::string l10nMem::showError(int iLineNo, char *sText, bool bWarning)
+{
+ return l10nMem_impl::mcImpl->showError(iLineNo, sText, bWarning);
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+bool l10nMem::isError()
+{
+ return l10nMem_impl::mcImpl->isError();
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+bool l10nMem::checkKey(const std::string& sKey, const std::string& sObjectType)
+{
+ return l10nMem_impl::mcImpl->checkKey(sKey, sObjectType);
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem::setFileName(const std::string& srSourceFile)
+{
+ return l10nMem_impl::mcImpl->setFileName(srSourceFile);
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem::setModuleName(const std::string& srModuleName)
+{
+ return l10nMem_impl::mcImpl->setModuleName(srModuleName);
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem::setEnUsKey(int iLineNo, const std::string& srKey, const std::string& srObjectType,
+ const std::string& srText, int iIndex)
+{
+ return l10nMem_impl::mcImpl->setEnUsKey(iLineNo, srKey, srObjectType, srText, iIndex);
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem::loadEnUsKey(const std::string& srKey, const std::string& srObjectType,
+ const std::string& srText, const std::string& oldKey)
+{
+ l10nMem_impl::mcImpl->loadEnUsKey(srKey, srObjectType, srText, oldKey);
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem::loadLangKey(const std::string& srLang, const std::string& srKey, const std::string& srObjectType,
+ const std::string& srText)
+{
+ l10nMem_impl::mcImpl->loadLangKey(srLang, srKey, srObjectType, srText);
+}
+
+
+
/********************** I M P L E M E N T A T I O N **********************/
l10nMem_entry::l10nMem_entry(const std::string& srSourceFile, const std::string& srModuleName,
const std::string& srKey, const std::string& srObjectType,
- const std::string& srLanguage, const std::string& srText,
- const int iIndex)
+ const std::string& srLanguage, const std::string& srText,
+ const int iIndex,
+ const std::string srOldKey)
: msSourceFile(srSourceFile),
msModuleName(srModuleName),
msKey(srKey),
- msObjectType(srObjectType),
+ msObjectType(srObjectType),
msLanguage(srLanguage),
msText(srText),
- miIndex(iIndex)
+ miIndex(iIndex),
+ msOLDKEY(srOldKey),
+ mbDeleted(true)
{
}
@@ -59,9 +150,8 @@ l10nMem_entry::~l10nMem_entry()
/********************** I M P L E M E N T A T I O N **********************/
-l10nMem::l10nMem()
+l10nMem_impl::l10nMem_impl()
: mbInError(false),
- miStartInx(0),
miLastUniqResort(0)
{
}
@@ -69,14 +159,14 @@ l10nMem::l10nMem()
/********************** I M P L E M E N T A T I O N **********************/
-l10nMem::~l10nMem()
+l10nMem_impl::~l10nMem_impl()
{
}
/********************** I M P L E M E N T A T I O N **********************/
-std::string l10nMem::showError(int iLineNo, char *sText, bool bWarning)
+std::string l10nMem_impl::showError(int iLineNo, char *sText, bool bWarning)
{
if (!bWarning)
mbInError = true;
@@ -88,7 +178,7 @@ std::string l10nMem::showError(int iLine
/********************** I M P L E M E N T A T I O N **********************/
-bool l10nMem::isError()
+bool l10nMem_impl::isError()
{
return mbInError;
}
@@ -96,11 +186,11 @@ bool l10nMem::isError()
/********************** I M P L E M E N T A T I O N **********************/
-bool l10nMem::checkKey(const std::string& sKey, const std::string& sObjectType)
+bool l10nMem_impl::checkKey(const std::string& sKey, const std::string& sObjectType)
{
int i;
- for (i = miStartInx; i < (int)mcMemory.size(); ++i)
+ for (i = 0; i < (int)mcMemory.size(); ++i)
if (mcMemory[i].msModuleName == msCurrentModuleName &&
mcMemory[i].msSourceFile == msCurrentSourceFileName &&
mcMemory[i].msObjectType == sObjectType &&
@@ -112,7 +202,7 @@ bool l10nMem::checkKey(const std::string
/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem::save(const std::string& srTargetFile)
+void l10nMem_impl::save(const std::string& srTargetFile)
{
int i;
std::string sFile = srTargetFile + ".cnv";
@@ -143,7 +233,7 @@ void l10nMem::save(const std::string& sr
/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem::clear()
+void l10nMem_impl::clear()
{
mcMemory.clear();
// JIX
@@ -152,10 +242,9 @@ void l10nMem::clear()
/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem::setFileName(const std::string& srSourceFile)
+void l10nMem_impl::setFileName(const std::string& srSourceFile)
{
msCurrentSourceFileName = srSourceFile;
- miStartInx = mcMemory.size();
// modify to please current sdf format
std::replace(msCurrentSourceFileName.begin(), msCurrentSourceFileName.end(), '/', '\\' );
@@ -164,7 +253,7 @@ void l10nMem::setFileName(const std::str
/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem::setModuleName(const std::string& srModuleName)
+void l10nMem_impl::setModuleName(const std::string& srModuleName)
{
msCurrentModuleName = srModuleName;
}
@@ -172,7 +261,7 @@ void l10nMem::setModuleName(const std::s
/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem::setEnUsKey(int iLineNo, const std::string& srKey, const std::string& srObjectType, const std::string& srText, int iIndex)
+void l10nMem_impl::setEnUsKey(int iLineNo, const std::string& srKey, const std::string& srObjectType, const std::string& srText, int iIndex)
{
std::string baseLanguage = "en-US";
std::string myKey = srKey;
@@ -193,8 +282,52 @@ void l10nMem::setEnUsKey(int iLineNo, co
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem_impl::loadEnUsKey(const std::string& srKey, const std::string& srObjectType,
+ const std::string& srText, const std::string& oldKey)
+{
+ std::string baseLanguage = "en-US";
+
+
+ if (!checkKey(srKey, srObjectType))
+ {
+ showError(0, "en-US key is not uniq");
+ }
+ mcMemory.push_back(l10nMem_entry(msCurrentSourceFileName, msCurrentModuleName,
+ srKey, srObjectType, baseLanguage, srText, 0, oldKey));
+}
+
+
+
+/********************** 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)
+{
+ int i;
+
+
+ for (i = 0; i < (int)mcMemory.size(); ++i)
+ {
+ if (mcMemory[i].msSourceFile != msCurrentSourceFileName)
+ continue;
+ if (mcMemory[i].msKey == srKey || mcMemory[i].msOLDKEY == srKey)
+ break;
+ }
+ if (i < (int)mcMemory.size())
+ {
+ mcMemory[i].mcLang.push_back(l10nMem_entry(msCurrentSourceFileName, msCurrentModuleName,
+ srKey, srObjectType, srLang, srText, 0, std::string("")));
+ return;
+ }
+
+ showError(0, (char *)(("cannot find key: " + srKey + " for lang " + srLang).c_str()));
+}
+
+
+
/********************** I M P L E M E N T A T I O N **********************/
-std::vector<l10nMem_entry *>& l10nMem::getLanguagesForKey(const std::string& srKey)
+std::vector<l10nMem_entry *>& l10nMem_impl::getLanguagesForKey(const std::string& srKey)
{
int nL = mcMemory.size();
Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx Sun Mar 3 21:53:34 2013
@@ -20,6 +20,7 @@
*************************************************************/
#ifndef GL10NMEM_HXX
#define GL10NMEM_HXX
+#include "gLang.hxx"
@@ -38,7 +39,8 @@ class l10nMem_entry
public:
l10nMem_entry(const std::string& srSourceFile, const std::string& srModuleName, const std::string& srKey,
const std::string& srObjectType, const std::string& srLanguage, const std::string& srText,
- const int iIndex);
+ const int iIndex,
+ const std::string srOldKey = "");
~l10nMem_entry();
std::string msSourceFile;
@@ -47,7 +49,10 @@ class l10nMem_entry
std::string msObjectType;
std::string msLanguage;
std::string msText;
+ std::string msOLDKEY;
int miIndex;
+ bool mbDeleted;
+ std::vector<l10nMem_entry> mcLang;
private:
};
@@ -55,11 +60,11 @@ class l10nMem_entry
/******************** C L A S S D E F I N I T I O N ********************/
-class l10nMem
+class l10nMem_impl
{
public:
- l10nMem();
- ~l10nMem();
+ l10nMem_impl();
+ ~l10nMem_impl();
std::string showError (int iLineNo, char *sText, bool bWarning = false);
bool isError ();
@@ -72,6 +77,14 @@ class l10nMem
void setEnUsKey (int iLineNo,const std::string& srKey,
const std::string& srObjectType,
const std::string& srText, int iIndex = 0);
+ void loadEnUsKey (const std::string& srKey,
+ const std::string& srObjectType,
+ const std::string& srText,
+ const std::string& oldKey);
+ void loadLangKey (const std::string& srLang,
+ const std::string& srKey,
+ const std::string& srObjectType,
+ const std::string& srText);
std::vector<l10nMem_entry *>& getLanguagesForKey(const std::string& srKey);
private:
@@ -80,7 +93,9 @@ class l10nMem
std::vector<l10nMem_entry *> mcCurrentSelection;
std::vector<l10nMem_entry> mcMemory;
bool mbInError;
- int miStartInx;
int miLastUniqResort;
+ static l10nMem_impl *mcImpl;
+
+ friend class l10nMem;
};
#endif
Modified: openoffice/branches/l10n/main/l10ntools/source/gLang.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gLang.hxx?rev=1452135&r1=1452134&r2=1452135&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gLang.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gLang.hxx Sun Mar 3 21:53:34 2013
@@ -40,55 +40,32 @@ extern bool gbVerbose;
/******************** C L A S S D E F I N I T I O N ********************/
-class l10nMem_entry
-{
- public:
- l10nMem_entry(const std::string& srSourceFile, const std::string& srModuleName, const std::string& srKey,
- const std::string& srObjectType, const std::string& srLanguage, const std::string& srText,
- const int iIndex);
- ~l10nMem_entry();
-
- std::string msSourceFile;
- std::string msModuleName;
- std::string msKey;
- std::string msObjectType;
- std::string msLanguage;
- std::string msText;
- int miIndex;
-
- private:
-};
-
-
-
-/******************** C L A S S D E F I N I T I O N ********************/
+class l10nMem_impl;
class l10nMem
{
public:
l10nMem();
~l10nMem();
- std::string showError (int iLineNo, char *sText, bool bWarning = false);
- bool isError ();
- bool checkKey (const std::string& sKey,
- const std::string& sObjectType);
- void save (const std::string& srTargetFile);
- void clear();
- void setFileName (const std::string& srSourceFile);
- void setModuleName (const std::string& srModuleName);
- void setEnUsKey (int iLineNo,const std::string& srKey,
- const std::string& srObjectType,
- const std::string& srText, int iIndex = 0);
- std::vector<l10nMem_entry *>& getLanguagesForKey(const std::string& srKey);
-
- private:
- std::string msCurrentModuleName;
- std::string msCurrentSourceFileName;
- std::vector<l10nMem_entry *> mcCurrentSelection;
- std::vector<l10nMem_entry> mcMemory;
- bool mbInError;
- int miStartInx;
- int miLastUniqResort;
+ std::string showError (int iLineNo, char *sText, bool bWarning = false);
+ bool isError ();
+ bool checkKey (const std::string& sKey,
+ const std::string& sObjectType);
+ void setFileName (const std::string& srSourceFile);
+ void setModuleName(const std::string& srModuleName);
+ void setEnUsKey (int iLineNo,
+ const std::string& srKey,
+ const std::string& srObjectType,
+ const std::string& srText,
+ int iIndex = 0);
+ void loadEnUsKey (const std::string& srKey,
+ const std::string& srObjectType,
+ const std::string& srText,
+ const std::string& oldKey);
+ void loadLangKey (const std::string& srLang,
+ const std::string& srKey,
+ const std::string& srObjectType,
+ const std::string& srText);
};
@@ -97,11 +74,11 @@ class l10nMem
class convert_gen
{
public:
- convert_gen(const std::string& srSourceFile, l10nMem& crMemory, const bool bMerge);
+ convert_gen(l10nMem& crMemory, const std::string& srSourceFile);
~convert_gen();
// do extract/merge
- void execute();
+ void execute(const bool bMerge);
};
@@ -117,16 +94,22 @@ class handler
void run();
private:
- enum {DO_EXTRACT, DO_EXTRACTMERGE, DO_GENERATE, DO_INSERT} meWorkMode;
+ enum {DO_CONVERT, DO_EXTRACT, DO_MERGE} meWorkMode;
l10nMem mcMemory;
std::string msModuleName;
+ std::string msPoOutDir;
+ std::string msPoDir;
std::string msSourceDir;
std::string msTargetDir;
- std::vector<std::string> msSourceFiles;
- bool mbVerbose;
+ std::vector<std::string> mvSourceFiles;
+ std::vector<std::string> mvLanguages;
+ bool mbVerbose;
+ void runConvert();
void runExtractMerge(bool bMerge);
- void runGenerate();
- void runInsert();
+
+ void showUsage(std::string& sErr);
+ void showManual();
+ void loadL10MEM();
};
#endif