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/06 08:58:01 UTC
svn commit: r1453186 - in /openoffice/branches/l10n/main/l10ntools/source:
gCon.cxx gCon.hxx gConDB.cxx gConPoWrap.cxx gHandler.cxx gL10nMem.cxx
gL10nMem.hxx gL10nMemDB.cxx gLang.hxx makefile.mk
Author: jani
Date: Wed Mar 6 07:58:01 2013
New Revision: 1453186
URL: http://svn.apache.org/r1453186
Log:
new translation mem structure, to speed up load time
Added:
openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx (with props)
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/gConPoWrap.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
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=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gCon.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gCon.cxx Wed Mar 6 07:58:01 2013
@@ -90,15 +90,18 @@ convert_gen::~convert_gen()
/********************** I M P L E M E N T A T I O N **********************/
-void convert_gen::execute(const bool bMerge)
+bool convert_gen::execute(const bool bMerge, const bool bAllowNoFile)
{
convert_gen_impl::mcImpl->mbMergeMode = bMerge;
// and load file
- convert_gen_impl::mcImpl->prepareFile();
+ if (!convert_gen_impl::mcImpl->prepareFile(bAllowNoFile))
+ return false;
// and execute conversion
convert_gen_impl::mcImpl->execute();
+
+ return true;
}
@@ -121,13 +124,18 @@ convert_gen_impl::~convert_gen_impl()
/********************** I M P L E M E N T A T I O N **********************/
-void convert_gen_impl::prepareFile()
+bool convert_gen_impl::prepareFile(bool bAllowNoFile)
{
std::ifstream inputFile(msSourceFile.c_str(), std::ios::binary);
if (!inputFile.is_open())
- throw showError((char *)"Cannot open file");
+ {
+ if (bAllowNoFile)
+ return false;
+ else
+ throw mcMemory.showError("Cannot open file");
+ }
// get length of file:
miSourceReadIndex = 0;
@@ -138,8 +146,9 @@ void convert_gen_impl::prepareFile()
// get size, prepare std::string and read whole file
inputFile.read((char *)msSourceBuffer.c_str(), msSourceBuffer.size());
if ((unsigned int)inputFile.gcount() != msSourceBuffer.size())
- throw showError((char *)"cannot read whole file");
+ throw mcMemory.showError("cannot read whole file");
inputFile.close();
+ return true;
}
@@ -218,11 +227,3 @@ std::string& convert_gen_impl::copySourc
return msCopyText;
}
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-std::string convert_gen_impl::showError(char *sText)
-{
- return mcMemory.showError(miLineNo, sText);
-}
\ No newline at end 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=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gCon.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gCon.hxx Wed Mar 6 07:58:01 2013
@@ -61,14 +61,13 @@ 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);
std::string& copySource(char *yyText, bool bDoClear = true);
protected:
std::string msSourceBuffer, msCopyText;
int miSourceReadIndex;
- void prepareFile();
+ bool prepareFile(bool bAllowNoFile);
friend class convert_gen;
Modified: openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx?rev=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConDB.cxx Wed Mar 6 07:58:01 2013
@@ -45,22 +45,23 @@ void convert_db::execute()
msSourceBuffer += '\n';
miSize = msSourceBuffer.size() -1;
+ miLineNo = 0;
while (collectLine())
{
- mcMemory.setFileName(msFields[0]);
+ mcMemory.setFileName(msFields[1]);
if (mbMergeMode)
{
iB = msFields[15].find("/");
if (iB == (int)std::string::npos)
- showError("missing / in en_US");
+ showError((char*)"missing / in en_US");
iE = msFields[15].find("/", iB+1);
if (iE == (int)std::string::npos)
- showError("missing / in en_US");
+ showError((char*)"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");
+ showError((char*)"missing / in en_US");
if (iB != iE+1)
oldKey += "." + msFields[15].substr(iE+1, iB - iE -1);
@@ -84,9 +85,14 @@ bool convert_db::collectLine()
int i, iStart;
bool bLineEnd;
+ ++miLineNo;
+
for (i = 0; i < NUMFIELD; ++i)
msFields[i].clear();
+ if (miSourceReadIndex >= miSize)
+ return false;
+
for (i = 0, bLineEnd = false, iStart = miSourceReadIndex; !bLineEnd; ++miSourceReadIndex)
{
if (msSourceBuffer[miSourceReadIndex] == '\r' ||
@@ -97,12 +103,11 @@ bool convert_db::collectLine()
{
if (i >= NUMFIELD)
{
- showError("TOO many fields");
- exit(-1);
+ showError((char*)"TOO many fields");
}
msFields[i++] = msSourceBuffer.substr(iStart, miSourceReadIndex - iStart);
iStart = miSourceReadIndex +1;
}
}
- return (miSourceReadIndex < miSize);
+ return true;
}
Modified: openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx?rev=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx Wed Mar 6 07:58:01 2013
@@ -47,8 +47,22 @@ namespace PoWrap
#include "gConPo_yy.c"
}
-
-
+#if 0
+ white-space
+ # translator-comments
+ #. extracted-comments
+ #: reference...
+ #, flag...
+ #| msgid previous-untranslated-string
+ msgid untranslated-string
+ msgstr translated-string
+
+ fuzzy
+
+ #: lib/error.c:116
+ msgid "Unknown system error"
+ msgstr "Error desconegut del sistema"
+#endif
/********************** I M P L E M E N T A T I O N **********************/
void convert_po::execute()
{
Modified: openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx?rev=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx Wed Mar 6 07:58:01 2013
@@ -29,14 +29,13 @@
*****************************************************************************
* This is the control module, that interpret the command line and implement
* the different work types
- * extract / merge / generate / insert
+ * extract / merge / generate / convert
*****************************************************************************/
/********************** I M P L E M E N T A T I O N **********************/
handler::handler()
- : mbVerbose(false)
{
}
@@ -53,7 +52,7 @@ handler::~handler()
void handler::checkCommandLine(int argc, char *argv[])
{
enum {ARG_NONE, ARG_F, ARG_O, ARG_S, ARG_T} eGotArg = ARG_NONE;
- std::string sWorkText;
+ std::string sWorkText, sLangText;
int argNow, nLen;
@@ -66,22 +65,23 @@ void handler::checkCommandLine(int argc,
// 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");
+ if (sWorkText == "convert") meWorkMode = DO_CONVERT;
+ else if (sWorkText == "extract") meWorkMode = DO_EXTRACT;
+ else if (sWorkText == "merge") meWorkMode = DO_MERGE;
+ else if (sWorkText == "generate") meWorkMode = DO_GENERATE;
+ else if (sWorkText == "help") showManual();
+ 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())
+ sLangText = argv[4];
+ if (sLangText[0] == '\"')
+ sLangText.erase(0,1);
+ nLen = sLangText.size() -1;
+ if (sLangText[nLen] == '\"')
+ sLangText.erase(nLen);
+ if (!sLangText.size())
throw std::string("<languages> is mandatory");
// and convert language to a vector
@@ -91,8 +91,8 @@ void handler::checkCommandLine(int argc,
do
{
current = next + 1;
- next = sWorkText.find_first_of( ",", current );
- mvLanguages.push_back(sWorkText.substr(current,next-current));
+ next = sLangText.find_first_of( ",", current );
+ mvLanguages.push_back(sLangText.substr(current,next-current));
}
while (next != (int)std::string::npos);
}
@@ -114,11 +114,12 @@ void handler::checkCommandLine(int argc,
throw (std::string("missing argument to ") + argv[argNow-1]);
// is it a known parameter
- if (sArg == "-f") eGotArg = ARG_F;
+ if (sArg == "-d") gbDebug = true;
+ else 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 if (sArg == "-v") gbVerbose = true;
else throw std::string("unknown parameter: ")+sArg;
}
else
@@ -164,7 +165,7 @@ void handler::checkCommandLine(int argc,
msPoOutDir.append("/");
// tell system
- if (mbVerbose)
+ if (gbVerbose)
std::cout << "gLang starting to " + sWorkText << " in module " << msModuleName << std::endl;
}
@@ -184,9 +185,10 @@ void handler::run()
// use workMode to start correct control part
switch (meWorkMode)
{
- case DO_EXTRACT: runExtractMerge(false); break;
- case DO_MERGE: runExtractMerge(true); break;
- case DO_CONVERT: runConvert(); break;
+ case DO_EXTRACT: runExtractMerge(false); break;
+ case DO_MERGE: runExtractMerge(true); break;
+ case DO_CONVERT: runConvert(); break;
+ case DO_GENERATE: runGenerate(); break;
}
}
catch(std::string sErr)
@@ -206,7 +208,7 @@ void handler::runExtractMerge(bool bMerg
for (std::vector<std::string>::iterator siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource)
{
// tell system
- if (mbVerbose)
+ if (gbDebug)
std::cout << "gLang extracting text from file " << *siSource << std::endl;
// prepare translation memory
@@ -232,6 +234,14 @@ void handler::runConvert()
/********************** I M P L E M E N T A T I O N **********************/
+void handler::runGenerate()
+{
+ throw std::string("handler::runGenerate 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 ?
@@ -240,8 +250,8 @@ void handler::showUsage(std::string& sEr
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";
+ "genLang <cmd> <module> <po dir> <languages> [-d] [-f <files>] [-o <dir>] [-s <dir>] [-t <dir>] [-v]\n"
+ "<cmd> is one of \"convert\", \"extract\", \"generate\", \"help\", \"merge\",\n";
exit(-1);
}
@@ -264,7 +274,7 @@ void handler::showManual()
"genLang can also convert old .po files (generated from .sdf)\n"
"\n"
"Syntax:\n"
- " genLang extract <module> <po dir> <languages> [-v] \\\n"
+ " genLang extract <module> <po dir> <languages> [-v] [-d]\\\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"
@@ -278,7 +288,7 @@ void handler::showManual()
" - 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"
+ " genLang merge <module> <po dir> <languages> [-v] [-d]\\\n"
" [-o <po outdir>] -f <files> -s <source dir> \\\n"
" -t <target dir>\n"
" works as \"extract\" and additionally merges\n"
@@ -286,19 +296,22 @@ void handler::showManual()
" 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"
+ " genLang convert <module> <po dir> <languages> [-v] [-d]\\\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"
+ " 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 generate <module> <po dir> <languages> [-v] [-d]\\\n"
+ " [-o <po outdir>]\n"
+ " reads .po <files> and generates a \"bin\" file for fast loading\n"
+ " Result is written to <po outdir>/<module>.dbpo\n"
"\n"
" genLang help\n"
" this text\n"
@@ -312,6 +325,8 @@ void handler::showManual()
" <languages>\n"
" comma separated string with langauge id to be used\n"
"\n"
+ " -d\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"
@@ -333,7 +348,7 @@ void handler::showManual()
void handler::loadL10MEM()
{
std::string sMod = "/" + msModuleName + ".pot";
- std::string sLoad = msPoDir + "en-US" + sMod;
+ std::string sLoad = msPoDir + "../en-US" + sMod;
// load texts from en-US po file (master)
@@ -342,7 +357,7 @@ void handler::loadL10MEM()
mcMemory.setFileName(sLoad);
// tell system
- if (mbVerbose)
+ if (gbDebug)
std::cout << "gLang loading master text from file " << sLoad << std::endl;
// and load file
@@ -358,10 +373,10 @@ void handler::loadL10MEM()
mcMemory.setFileName(sLoad);
// tell system
- if (mbVerbose)
+ if (gbDebug)
std::cout << "gLang loading text from language file " << sLoad << std::endl;
// get converter and extract files
- convert_gen(mcMemory, sLoad).execute(false);
+ convert_gen(mcMemory, sLoad).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=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx Wed Mar 6 07:58:01 2013
@@ -311,6 +311,8 @@ void l10nMem_impl::loadLangKey(const std
{
if (mcMemory[i].msSourceFile != msCurrentSourceFileName)
continue;
+ if (mcMemory[i].msObjectType != "text" && mcMemory[i].msObjectType != srObjectType)
+ continue;
if (mcMemory[i].msKey == srKey || mcMemory[i].msOLDKEY == srKey)
break;
}
@@ -321,7 +323,7 @@ void l10nMem_impl::loadLangKey(const std
return;
}
- showError(0, (char *)(("cannot find key: " + srKey + " for lang " + srLang).c_str()));
+// showError(0, (char *)(("cannot find key: " + srKey + " for lang " + srLang).c_str()));
}
Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx?rev=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx Wed Mar 6 07:58:01 2013
@@ -34,58 +34,95 @@
/******************** C L A S S D E F I N I T I O N ********************/
-class l10nMem_entry
+class l10Mem_lang_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 std::string srOldKey = "");
- ~l10nMem_entry();
-
- std::string msSourceFile;
- std::string msModuleName;
- std::string msKey;
- std::string msObjectType;
- std::string msLanguage;
- std::string msText;
- std::string msOLDKEY;
- int miIndex;
- bool mbDeleted;
- std::vector<l10nMem_entry> mcLang;
+ l10Mem_lang_entry(const std::string& sKey,
+ const std::string& sText);
+ ~l10Mem_lang_entry();
private:
+ std::string msKey; // only used in master: key in po file and source file
+ std::string msText; // in master en-US text otherwise translated text
+ ENTRY_STATE meState; // status information
+ int miFileInx; // index of file name
};
/******************** C L A S S D E F I N I T I O N ********************/
+class l10Men_lang_container
+{
+ public:
+ l10Men_lang_container();
+ ~l10Men_lang_container();
+
+ private:
+ std::string msLanguage; // language code
+ std::vector<l10Mem_lang_entry> mcEntries; // key/text entries
+};
+
+
+
+/******************** C L A S S D E F I N I T I O N ********************/
+class l10Mem_file_entry
+{
+ public:
+ l10Mem_file_entry();
+ ~l10Mem_file_entry();
+
+ private:
+ std::string msFile; // file Name
+ int miStart; // start index of entries in mcEntries (l10Men_lang_container)
+ int miEnd; // last index of entries in mcEntries (l10Men_lang_container)
+};
+
+
+
+/******************** C L A S S D E F I N I T I O N ********************/
+class l10Mem_db
+{
+ public:
+ l10Mem_db();
+ ~l10Mem_db();
+
+ private:
+ l10Men_lang_container mcENUS;
+ std::vector<l10Men_lang_container> mcLang;
+ std::vector<l10Mem_file_entry> mcFile;
+};
+
+
+
+
+/******************** C L A S S D E F I N I T I O N ********************/
class l10nMem_impl
{
public:
l10nMem_impl();
~l10nMem_impl();
- 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);
- 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,
+ std::string showError (const std::string& sText, int iLineNo = 0);
+ std::string showWarning (const std::string& sText, int iLineNo = 0);
+ bool isError ();
+
+ bool checkKey (const std::string& sKey);
+ void setFileName (const std::string& sSourceFile);
+ void setModuleName(const std::string& sModuleName);
+ void setLanguage (const std::string& sLanguage, bool bMaster = false);
+
+ void loadEnUsKey (const std::string& sKey,
+ const std::string& sText);
+ void loadLangKey (ENTRY_STATE eFlag,
+ const std::string& sKey,
+ const std::string& sOrgText,
+ const std::string& sText);
+ void save();
+
+ void setEnUsKey (int iLineNo,
+ const std::string& sKey,
const std::string& srText);
- std::vector<l10nMem_entry *>& getLanguagesForKey(const std::string& srKey);
+
private:
std::string msCurrentModuleName;
Added: openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx?rev=1453186&view=auto
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx (added)
+++ openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx Wed Mar 6 07:58:01 2013
@@ -0,0 +1,343 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+#include "gL10nMem.hxx"
+#include <algorithm>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+
+
+/*****************************************************************************
+ ************************ G L 1 0 N M E M . C X X ************************
+ *****************************************************************************
+ * This is the translation memory that links between the converts (from source
+ * files) and to the language files. The memory contains the actual text info
+ ***********************d******************************************************/
+
+
+
+/******************* 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 srOldKey)
+ : msSourceFile(srSourceFile),
+ msModuleName(srModuleName),
+ msKey(srKey),
+ msObjectType(srObjectType),
+ msLanguage(srLanguage),
+ msText(srText),
+ miIndex(iIndex),
+ msOLDKEY(srOldKey),
+ mbDeleted(true)
+{
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+l10nMem_entry::~l10nMem_entry()
+{}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+l10nMem_impl::l10nMem_impl()
+ : mbInError(false),
+ miLastUniqResort(0)
+{
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+l10nMem_impl::~l10nMem_impl()
+{
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+std::string l10nMem_impl::showError(int iLineNo, char *sText, bool bWarning)
+{
+ if (!bWarning)
+ mbInError = true;
+
+ std::cerr << "ERROR in " << msCurrentSourceFileName << ":" << iLineNo << ": " << sText << std::endl;
+ return "ERROR";
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+bool l10nMem_impl::isError()
+{
+ return mbInError;
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+bool l10nMem_impl::checkKey(const std::string& sKey, const std::string& sObjectType)
+{
+ int i;
+
+ for (i = 0; i < (int)mcMemory.size(); ++i)
+ if (mcMemory[i].msModuleName == msCurrentModuleName &&
+ mcMemory[i].msSourceFile == msCurrentSourceFileName &&
+ mcMemory[i].msObjectType == sObjectType &&
+ mcMemory[i].msKey == sKey )
+ return false;
+ return true;
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem_impl::save(const std::string& srTargetFile)
+{
+ int i;
+ std::string sFile = srTargetFile + ".cnv";
+
+ if (mbInError)
+ {
+ 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 std::string("Could not open ")+srTargetFile;
+
+
+ for (i = 0; i < (int)mcMemory.size(); ++i)
+ {
+ 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;
+ }
+ // JIX
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem_impl::clear()
+{
+ mcMemory.clear();
+ // JIX
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem_impl::setFileName(const std::string& srSourceFile)
+{
+ msCurrentSourceFileName = srSourceFile;
+
+ // modify to please current sdf format
+ std::replace(msCurrentSourceFileName.begin(), msCurrentSourceFileName.end(), '/', '\\' );
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+void l10nMem_impl::setModuleName(const std::string& srModuleName)
+{
+ msCurrentModuleName = srModuleName;
+}
+
+
+
+/********************** I M P L E M E N T A T I O N **********************/
+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;
+
+ iLineNo;
+
+ if (!checkKey(srKey, srObjectType))
+ {
+ std::stringstream ssBuf;
+
+ ++miLastUniqResort;
+ ssBuf << miLastUniqResort;
+ myKey += ".globUniq" + ssBuf.str();
+ }
+ mcMemory.push_back(l10nMem_entry(msCurrentSourceFileName, msCurrentModuleName,
+ myKey, srObjectType, baseLanguage, srText, iIndex));
+}
+
+
+
+
+/********************** 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].msObjectType != "text" && mcMemory[i].msObjectType != srObjectType)
+ 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_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;
+}
Propchange: openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx
------------------------------------------------------------------------------
svn:executable = *
Modified: openoffice/branches/l10n/main/l10ntools/source/gLang.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gLang.hxx?rev=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gLang.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gLang.hxx Wed Mar 6 07:58:01 2013
@@ -35,7 +35,18 @@
/******************* G L O B A L D E F I N I T I O N *******************/
-extern bool gbVerbose;
+extern bool gbVerbose;
+extern bool gbDebug;
+typedef enum
+{
+ ENTRY_DELETED,
+ ENTRY_ADDED,
+ ENTRY_CHANGED,
+ ENTRY_NORMAL
+} ENTRY_STATE;
+
+
+
@@ -47,24 +58,25 @@ class l10nMem
l10nMem();
~l10nMem();
- std::string showError (int iLineNo, char *sText, bool bWarning = false);
+ std::string showError (const std::string& sText, int iLineNo = 0);
+ std::string showWarning (const std::string& sText, int iLineNo = 0);
bool isError ();
- bool checkKey (const std::string& sKey,
- const std::string& sObjectType);
- void setFileName (const std::string& srSourceFile);
- void setModuleName(const std::string& srModuleName);
+
+ bool checkKey (const std::string& sKey);
+ void setFileName (const std::string& sSourceFile);
+ void setModuleName(const std::string& sModuleName);
+ void setLanguage (const std::string& sLanguage, bool bMaster = false);
+
+ void loadEnUsKey (const std::string& sKey,
+ const std::string& sText);
+ void loadLangKey (ENTRY_STATE eFlag,
+ const std::string& sKey,
+ const std::string& sOrgText,
+ const std::string& sText);
+ void save();
+
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& sKey,
const std::string& srText);
};
@@ -78,7 +90,7 @@ class convert_gen
~convert_gen();
// do extract/merge
- void execute(const bool bMerge);
+ bool execute(const bool bMerge, const bool bAllowNoFile = false);
};
@@ -94,7 +106,7 @@ class handler
void run();
private:
- enum {DO_CONVERT, DO_EXTRACT, DO_MERGE} meWorkMode;
+ enum {DO_CONVERT, DO_EXTRACT, DO_MERGE, DO_GENERATE} meWorkMode;
l10nMem mcMemory;
std::string msModuleName;
std::string msPoOutDir;
@@ -103,10 +115,10 @@ class handler
std::string msTargetDir;
std::vector<std::string> mvSourceFiles;
std::vector<std::string> mvLanguages;
- bool mbVerbose;
void runConvert();
void runExtractMerge(bool bMerge);
+ void runGenerate();
void showUsage(std::string& sErr);
void showManual();
Modified: openoffice/branches/l10n/main/l10ntools/source/makefile.mk
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/makefile.mk?rev=1453186&r1=1453185&r2=1453186&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/makefile.mk (original)
+++ openoffice/branches/l10n/main/l10ntools/source/makefile.mk Wed Mar 6 07:58:01 2013
@@ -169,9 +169,9 @@ APP7STDLIBS+= \
# localizer for new l10n framework
APP8TARGET= genLang
APP8OBJS= $(OBJ)$/gLang.obj $(OBJ)$/gL10nMem.obj \
- $(OBJ)$/gHandler.obj $(OBJ)$/gConProp.obj \
- $(OBJ)$/gConTree.obj $(OBJ)$/gCon.obj \
- $(OBJ)$/gConDB.obj \
+ $(OBJ)$/gL10MemDB.obj $(OBJ)$/gHandler.obj \
+ $(OBJ)$/gConProp.obj $(OBJ)$/gConTree.obj \
+ $(OBJ)$/gCon.obj $(OBJ)$/gConDB.obj \
$(OBJ)$/gConPoWrap.obj $(OBJ)$/gConSrcWrap.obj \
$(OBJ)$/gConXcsWrap.obj $(OBJ)$/gConXcuWrap.obj \
$(OBJ)$/gConXrmWrap.obj $(OBJ)$/gConXhpWrap.obj \