diff options
author | jan iversen <jani@documentfoundation.org> | 2016-03-14 22:10:23 +0100 |
---|---|---|
committer | jan iversen <jani@documentfoundation.org> | 2016-03-14 23:31:44 +0100 |
commit | 48c2e04bdb60429823cb8b12a14d954af544a2bf (patch) | |
tree | a4c5065547a6ab275ef646ee8416447f64f02cde | |
parent | 575b1efb193ac5e921b83ead157c1c639aec0e92 (diff) |
genLang update
removed gL10nMemDB (combined with gL10nMemDB) to avoid CLANG problem.
removed (temporary) gL10nMem dependency on convPO (circular dep).
Change-Id: I17646be2ccc0feaaa8850a9b753f86c8c62e9f24
27 files changed, 664 insertions, 783 deletions
diff --git a/l10ntools/Executable_genlang.mk b/l10ntools/Executable_genlang.mk index 13789e016d44..0badea207b2b 100644 --- a/l10ntools/Executable_genlang.mk +++ b/l10ntools/Executable_genlang.mk @@ -28,7 +28,6 @@ $(eval $(call gb_Executable_add_scanners,genlang,\ $(eval $(call gb_Executable_add_exception_objects,genlang,\ l10ntools/source/gLang \ l10ntools/source/gL10nMem \ - l10ntools/source/gL10nMemDB \ l10ntools/source/gConvProp \ l10ntools/source/gConv \ l10ntools/source/gConvDB \ diff --git a/l10ntools/inc/gConv.hxx b/l10ntools/inc/gConv.hxx index 7287a499ca10..604e5ed5671c 100644 --- a/l10ntools/inc/gConv.hxx +++ b/l10ntools/inc/gConv.hxx @@ -19,11 +19,33 @@ #ifndef GCON_HXX #define GCON_HXX -#include "gLang.hxx" - #include <iostream> #include <fstream> +class convert_gen +{ +public: + convert_gen(l10nMem& cMemory, + const std::string& sSourceDir, + const std::string& sTargetDir, + const std::string& sSourceFile); + ~convert_gen(); + + // do extract/merge + bool execute(const bool bMerge, const bool bKid); + + // ONLY po should implement these functions + void startSave(const std::string& sLanguage, + const std::string& sFile); + void save(const std::string& sFileName, + const std::string& sKey, + const std::string& sENUStext, + const std::string& sText, + bool bFuzzy); + void endSave(); + static bool checkAccess(std::string& sFile); + static bool createDir(std::string& sDir, std::string& sFile); +}; /***************************************************************************** diff --git a/l10ntools/inc/gL10nMem.hxx b/l10ntools/inc/gL10nMem.hxx index e7dcd705bab9..94e76c9c8d0f 100644 --- a/l10ntools/inc/gL10nMem.hxx +++ b/l10ntools/inc/gL10nMem.hxx @@ -16,78 +16,77 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #ifndef GL10NMEM_HXX #define GL10NMEM_HXX -#include "gLang.hxx" - - - -class l10nMem_lang_entry -{ - public: - l10nMem_lang_entry(const std::string& sMsgStr, bool bFuzzy); - ~l10nMem_lang_entry(); - - std::string msMsgStr; // translated text from po file - bool mbFuzzy; // fuzzy flag -}; - - -class l10nMem_enus_entry +class l10nMem_enus_entry; +class l10nMem_file_entry; +class l10nMem_lang_list_entry; +class l10nMem { - public: - l10nMem_enus_entry(const std::string& sKey, - const std::string& sMsgId, - int iLineNo, - int iFileInx, - int iLangSize, - l10nMem::ENTRY_STATE eState); - ~l10nMem_enus_entry(); - - std::string msKey; // key in po file and source file - std::string msMsgId; // en-US text from source file - l10nMem::ENTRY_STATE meState; // status information - int miFileInx; // index of file name - int miLineNo; // line number - std::vector<l10nMem_lang_entry> mcLangText; // language texts (index is languageId) -}; - - - -class l10nMem_file_entry -{ - public: - l10nMem_file_entry(const std::string& sFileName, int iStart); - ~l10nMem_file_entry(); - - std::string msFileName; // file Name with relative path - std::string msPureName; // just filename - int miStart; // start index of entries in mcMasterEntries (l10Mem_db::mcENUS) - int miEnd; // last index of entries in mcMasterEntries (l10Mem_db::mcENUS) -}; - - - -class l10nMem_lang_list_entry -{ - public: - l10nMem_lang_list_entry(const std::string& sName); - ~l10nMem_lang_list_entry(); - - std::string msName; // language Name - bool mbChanged; // used for "convert", true if language is modified -}; - - - -class l10nMem_db -{ - public: - l10nMem_db(); - ~l10nMem_db(); - +public: + l10nMem(); + ~l10nMem(); + + typedef enum + { + ENTRY_DELETED, + ENTRY_ADDED, + ENTRY_CHANGED, + ENTRY_NORMAL + } ENTRY_STATE; + + static int showError(const std::string& sText, int iLineNo = 0); + static void 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); + static void keyToUpper(std::string& sKey); + + void setModuleName(const std::string& sModuleName); + const std::string& getModuleName(void); + void setLanguage(const std::string& sLanguage, + bool bCreate); + void setConvert(bool bConvert, + bool bStrict); + void setVerbose(const bool doVerbose); + void setDebug(const bool doDebug); + + + void loadEntryKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sOrgText, + const std::string& sText, + bool bIsFuzzy); + + void setSourceKey(int iLineNo, + const std::string& sFilename, + const std::string& sKey, + const std::string& sText, + bool bMustExist); + + void saveTemplates(const std::string& sTargetDir, + bool bKid, + bool bForce); + void saveLanguages(l10nMem& cMem, + const std::string& sTargetDir, + bool bForce); + void dumpMem(const std::string& sTargetDir); + + int prepareMerge(); + bool getMergeLang(std::string& sLang, + std::string& sText); + void showNOconvert(); + bool isError(); + + void convertToInetString(std::string& sText); + void convertFromInetString(std::string& sText); + +private: + bool mbVerbose; + bool mbDebug; + bool mbInError; + std::string msModuleName; int miCurFileInx; int miCurLangInx; int miCurENUSinx; @@ -98,41 +97,43 @@ class l10nMem_db std::vector<l10nMem_file_entry> mcFileList; std::vector<l10nMem_lang_list_entry> mcLangList; - - void loadENUSkey (int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId); - void setLanguage (const std::string& sLanguage, - bool bCreate); - void setConvert (bool bConvert, - bool bStrict); - bool findFileName (const std::string& sSourceFile); - void loadLangKey (int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - const std::string& sMsgStr, - bool bFuzzy); - - - bool locateKey (int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - bool bThrow); - void reorganize (bool bConvert); - void addKey (int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - l10nMem::ENTRY_STATE eStat); - - int prepareMerge (); - bool getMergeLang (std::string& sLang, - std::string& sText); - bool getLangList (std::string& sLang); - -static void keyToUpper(std::string& sKey); + void formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText); + bool needWrite(const std::string sFileName, bool bForce); + bool convFilterWarning(const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId); + void convEntryKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bIsFuzzy); + void saveTemplates(l10nMem& cMem, + const std::string& sTargetDir, + bool bKid, + bool bForce); + + void loadENUSkey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId); + void loadLangKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bFuzzy); + void reorganize(bool bConvert); + bool locateKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + bool bThrow); + void addKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + l10nMem::ENTRY_STATE eStat); + bool findFileName(const std::string& sSourceFile); }; #endif diff --git a/l10ntools/inc/gLang.hxx b/l10ntools/inc/gLang.hxx deleted file mode 100644 index 381d4d9df669..000000000000 --- a/l10ntools/inc/gLang.hxx +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * 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 . - */ -#ifndef GLANG_HXX -#define GLANG_HXX -#include <string> -#include <vector> - - - -class l10nMem_db; -class l10nMem -{ - public: - l10nMem(); - ~l10nMem(); - - static int showError(const std::string& sText, int iLineNo = 0); - static void 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); - static bool isError(); - - void setModuleName (const std::string& sModuleName); - const std::string& getModuleName (void); - void setLanguage (const std::string& sLanguage, - bool bCreate); - void setConvert (bool bConvert, - bool bStrict); - void loadEntryKey (int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sOrgText, - const std::string& sText, - bool bIsFuzzy); - - void setSourceKey (int iLineNo, - const std::string& sFilename, - const std::string& sKey, - const std::string& sText, - bool bMustExist); - - void saveTemplates (const std::string& sTargetDir, - bool bKid, - bool bForce); - void saveLanguages(l10nMem& cMem, - const std::string& sTargetDir, - bool bForce); - void dumpMem (const std::string& sTargetDir); - - int prepareMerge (); - bool getMergeLang (std::string& sLang, - std::string& sText); - void showNOconvert (); - - void convertToInetString(std::string& sText); - void convertFromInetString(std::string& sText); - - private: - l10nMem_db *mcDb; - bool mbVerbose; - bool mbDebug; - bool mbInError; - typedef enum - { - ENTRY_DELETED, - ENTRY_ADDED, - ENTRY_CHANGED, - ENTRY_NORMAL - } ENTRY_STATE; - std::string msModuleName; - - void formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText); - bool needWrite(const std::string sFileName, bool bForce); - bool convFilterWarning(const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId); - void convEntryKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - const std::string& sMsgStr, - bool bIsFuzzy); - void saveTemplates(l10nMem& cMem, - const std::string& sTargetDir, - bool bKid, - bool bForce); - - friend class handler; - friend class l10nMem_enus_entry; - friend class l10nMem_db; -}; - - - -class convert_gen -{ - public: - convert_gen(l10nMem& cMemory, - const std::string& sSourceDir, - const std::string& sTargetDir, - const std::string& sSourceFile); - ~convert_gen(); - - // do extract/merge - bool execute(const bool bMerge, const bool bKid); - - // ONLY po should implement these functions - void startSave(const std::string& sLanguage, - const std::string& sFile); - void save(const std::string& sFileName, - const std::string& sKey, - const std::string& sENUStext, - const std::string& sText, - bool bFuzzy); - void endSave(); - static bool checkAccess(std::string& sFile); - static bool createDir(std::string& sDir, std::string& sFile); -}; -#endif diff --git a/l10ntools/source/gConv.cxx b/l10ntools/source/gConv.cxx index 164b245addcf..eb8102485d61 100644 --- a/l10ntools/source/gConv.cxx +++ b/l10ntools/source/gConv.cxx @@ -16,7 +16,10 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConv.hxx" #include "gConvDB.hxx" #include "gConvPo.hxx" diff --git a/l10ntools/source/gConvDB.cxx b/l10ntools/source/gConvDB.cxx index a6d01a7ef907..36689c8581b8 100644 --- a/l10ntools/source/gConvDB.cxx +++ b/l10ntools/source/gConvDB.cxx @@ -16,7 +16,10 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvDB.hxx" diff --git a/l10ntools/source/gConvPo.cxx b/l10ntools/source/gConvPo.cxx index 8bbedc71f405..82dcf44a9493 100644 --- a/l10ntools/source/gConvPo.cxx +++ b/l10ntools/source/gConvPo.cxx @@ -16,7 +16,10 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvPo.hxx" #include <iostream> #include <fstream> diff --git a/l10ntools/source/gConvProp.cxx b/l10ntools/source/gConvProp.cxx index a5067614b4ff..b9e5755feb0f 100644 --- a/l10ntools/source/gConvProp.cxx +++ b/l10ntools/source/gConvProp.cxx @@ -16,7 +16,10 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvProp.hxx" diff --git a/l10ntools/source/gConvSrc.cxx b/l10ntools/source/gConvSrc.cxx index f579d471f9f3..08b4aa1aeb7e 100644 --- a/l10ntools/source/gConvSrc.cxx +++ b/l10ntools/source/gConvSrc.cxx @@ -16,13 +16,16 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvSrc.hxx" #include <iostream> #include <fstream> #include <cstdlib> #include <sstream> -#include <string.h> /***************************************************************************** diff --git a/l10ntools/source/gConvTree.cxx b/l10ntools/source/gConvTree.cxx index d7fca8119c92..45ff1bdb212b 100644 --- a/l10ntools/source/gConvTree.cxx +++ b/l10ntools/source/gConvTree.cxx @@ -16,7 +16,10 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvTree.hxx" diff --git a/l10ntools/source/gConvUlf.cxx b/l10ntools/source/gConvUlf.cxx index c766d531b1d7..361065ab228f 100644 --- a/l10ntools/source/gConvUlf.cxx +++ b/l10ntools/source/gConvUlf.cxx @@ -16,11 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvUlf.hxx" -#include <iostream> -#include <fstream> -#include <cstdlib> diff --git a/l10ntools/source/gConvXcs.cxx b/l10ntools/source/gConvXcs.cxx index ec010d4fe371..31cbaee774a2 100644 --- a/l10ntools/source/gConvXcs.cxx +++ b/l10ntools/source/gConvXcs.cxx @@ -16,11 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvXcs.hxx" -#include <iostream> -#include <fstream> -#include <cstdlib> diff --git a/l10ntools/source/gConvXcu.cxx b/l10ntools/source/gConvXcu.cxx index 8cf309b81c2e..e8070bc73b27 100644 --- a/l10ntools/source/gConvXcu.cxx +++ b/l10ntools/source/gConvXcu.cxx @@ -16,11 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvXcu.hxx" -#include <iostream> -#include <fstream> -#include <cstdlib> /***************************************************************************** diff --git a/l10ntools/source/gConvXhp.cxx b/l10ntools/source/gConvXhp.cxx index 0cb925fb4feb..b2c58ac9de7e 100644 --- a/l10ntools/source/gConvXhp.cxx +++ b/l10ntools/source/gConvXhp.cxx @@ -16,7 +16,10 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvXhp.hxx" diff --git a/l10ntools/source/gConvXrm.cxx b/l10ntools/source/gConvXrm.cxx index b86c57931bee..0c2274487348 100644 --- a/l10ntools/source/gConvXrm.cxx +++ b/l10ntools/source/gConvXrm.cxx @@ -16,7 +16,10 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <string> +#include <vector> +#include "gL10nMem.hxx" #include "gConvXrm.hxx" diff --git a/l10ntools/source/gL10nMem.cxx b/l10ntools/source/gL10nMem.cxx index 44eed385290e..604a6d6b08ec 100644 --- a/l10ntools/source/gL10nMem.cxx +++ b/l10ntools/source/gL10nMem.cxx @@ -16,29 +16,132 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "gL10nMem.hxx" +#include <string> +#include <vector> #include <iostream> #include <fstream> #include <sstream> +#include "gL10nMem.hxx" + l10nMem *myMem; +class l10nMem_lang_list_entry +{ +public: + l10nMem_lang_list_entry(const std::string& sName) : + msName(sName), + mbChanged(false) + {} + + ~l10nMem_lang_list_entry() {}; + + std::string msName; // language Name + bool mbChanged; // used for "convert", true if language is modified +}; + + +class l10nMem_file_entry +{ +public: + l10nMem_file_entry(const std::string& sFileName, int iStart) + : + msFileName(sFileName), + miStart(iStart), + miEnd(iStart) + { + // Store fileName without relative path + int i = msFileName.rfind("/"); + if (i == (int)std::string::npos) + msPureName = msFileName; + else + msPureName = msFileName.substr(i + 1); + } + ~l10nMem_file_entry() {}; + + std::string msFileName; // file Name with relative path + std::string msPureName; // just filename + int miStart; // start index of entries in mcMasterEntries (l10Mem_db::mcENUS) + int miEnd; // last index of entries in mcMasterEntries (l10Mem_db::mcENUS) +}; + + + +class l10nMem_lang_entry +{ +public: + l10nMem_lang_entry(const std::string& sMsgStr, bool bFuzzy) + : + msMsgStr(sMsgStr), + mbFuzzy(bFuzzy) + {} + ~l10nMem_lang_entry() {}; + + std::string msMsgStr; // translated text from po file + bool mbFuzzy; // fuzzy flag +}; + + + +class l10nMem_enus_entry +{ +public: + l10nMem_enus_entry(const std::string& sKey, + const std::string& sMsgId, + int iLineNo, + int iFileInx, + int iLangSize, + l10nMem::ENTRY_STATE eState) + : + msMsgId(sMsgId), + meState(eState), + miFileInx(iFileInx), + miLineNo(iLineNo) + { + int i; + + // add dummy language entries + for (i = 0; i < iLangSize; ++i) + mcLangText.push_back(l10nMem_lang_entry("", false)); + + // convert key to upper case + msKey = sKey; + l10nMem::keyToUpper(msKey); + } + + ~l10nMem_enus_entry() {}; + + std::string msKey; // key in po file and source file + std::string msMsgId; // en-US text from source file + l10nMem::ENTRY_STATE meState; // status information + int miFileInx; // index of file name + int miLineNo; // line number + std::vector<l10nMem_lang_entry> mcLangText; // language texts (index is languageId) +}; + l10nMem::l10nMem() : mbVerbose(false), mbDebug(false), - mbInError(false) + mbInError(false), + miCurFileInx(0), + miCurLangInx(0), + miCurENUSinx(0), + mbNeedWrite(false), + mbConvertMode(false), + mbStrictMode(false) { - mcDb = new l10nMem_db; myMem = this; + mcFileList.push_back(l10nMem_file_entry("-genLang-", 0)); + mcLangList.push_back(l10nMem_lang_list_entry("-genLang-")); + mcENUSlist.push_back(l10nMem_enus_entry("-genLang-", "-genLang-", 0, 0, 0, l10nMem::ENTRY_DELETED)); } l10nMem::~l10nMem() { - delete mcDb; } @@ -97,17 +200,69 @@ const std::string& l10nMem::getModuleName() void l10nMem::setLanguage(const std::string& sLanguage, - bool bCreate) + bool bCreate) { - mcDb->setLanguage(sLanguage, bCreate); + int i, iSize; + + // regular load or convert of old po files + miCurFileInx = 0; + + // With no languages selected only en-US is generated + if (!sLanguage.size()) + { + miCurLangInx = 0; + return; + } + + // en-US is loaded as master and cannot be loaded again + if (sLanguage == "en-US") + throw l10nMem::showError("en-US is loaded automatically"); + + // check if language is already loaded + iSize = mcLangList.size(); + for (miCurLangInx = 0; miCurLangInx < iSize && mcLangList[miCurLangInx].msName != sLanguage; ++miCurLangInx); + if (miCurLangInx < iSize) + { + if (bCreate) + throw showError("loading " + sLanguage + " twice"); + return; + } + + // language does not exist in db + if (!bCreate) + throw showError("language " + sLanguage + " not loaded"); + + // create language + mcLangList.push_back(sLanguage); + + // add language to all ENUS entries + iSize = mcENUSlist.size(); + for (i = 0; i < iSize; ++i) + mcENUSlist[i].mcLangText.push_back(l10nMem_lang_entry("", false)); } void l10nMem::setConvert(bool bConvert, - bool bStrict) + bool bStrict) +{ + // regular load or convert of old po files + mbConvertMode = bConvert; + mbStrictMode = bStrict; +} + + + +void l10nMem::setVerbose(bool doVerbose) { - mcDb->setConvert(bConvert, bStrict); + mbVerbose = doVerbose; +} + + + +void l10nMem::setDebug(bool doDebug) +{ + mbDebug = doDebug; } @@ -119,12 +274,12 @@ void l10nMem::loadEntryKey(int iLineNo, const std::string& sMsgStr, bool bIsFuzzy) { - if (mcDb->mbConvertMode) + if (mbConvertMode) convEntryKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy); - else if (!mcDb->miCurLangInx) - mcDb->loadENUSkey(iLineNo, sSourceFile, sKey, sMsgId); + else if (!miCurLangInx) + loadENUSkey(iLineNo, sSourceFile, sKey, sMsgId); else - mcDb->loadLangKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy); + loadLangKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy); } @@ -157,14 +312,14 @@ void l10nMem::setSourceKey(int iLineNo, } // if key exist update state - if (mcDb->locateKey(iLineNo, sSourceFile, sKey, newText, false)) - mcDb->mcENUSlist[mcDb->miCurENUSinx].meState = ENTRY_NORMAL; + if (locateKey(iLineNo, sSourceFile, sKey, newText, false)) + mcENUSlist[miCurENUSinx].meState = ENTRY_NORMAL; else { if (bMustExist) throw showError("key " + sKey + " does not exist"); // add key, if changed text, this is wrong but handled in reorganize - mcDb->addKey(iLineNo, sSourceFile, sKey, newText, ENTRY_ADDED); + addKey(iLineNo, sSourceFile, sKey, newText, ENTRY_ADDED); } } @@ -172,7 +327,7 @@ void l10nMem::setSourceKey(int iLineNo, void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForce) { -// int iEsize = mcDb->mcENUSlist.size(); +// int iEsize = mcENUSlist.size(); std::string sFileName = msModuleName + ".pot"; // Dummy to satisfy compiler @@ -181,8 +336,8 @@ void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForc showError(sTargetDir); // and reorganize db if needed - mcDb->miCurFileInx = 0; - mcDb->reorganize(false); + miCurFileInx = 0; + reorganize(false); // no save if there has been errors if (!needWrite(sFileName, bForce)) @@ -196,13 +351,13 @@ void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForc savePo.startSave("templates/", sFileName); for (iE = 1; iE < iEsize; ++iE) { - l10nMem_enus_entry& cE = mcDb->mcENUSlist[iE]; + l10nMem_enus_entry& cE = mcENUSlist[iE]; // remove deleted entries if (cE.meState == ENTRY_DELETED) continue; - savePo.save(mcDb->mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, "", false); + savePo.save(mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, "", false); } savePo.endSave(); #endif @@ -212,14 +367,19 @@ void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForc void l10nMem::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool bForce) { - int iE, iEsize = mcDb->mcENUSlist.size(); - int iL, iLsize = mcDb->mcLangList.size(); +// int iE, iEsize = mcENUSlist.size(); +// int iEsize = mcENUSlist.size(); + int iL, iLsize = mcLangList.size(); std::string sFileName = msModuleName + ".po"; + cMem.dumpMem("jan"); + showDebug(sTargetDir); + if (bForce) + showDebug("debug"); // and reorganize db if needed - mcDb->miCurFileInx = 0; - mcDb->reorganize(true); + miCurFileInx = 0; + reorganize(true); // no save if there has been errors if (!needWrite(sFileName, bForce)) @@ -228,15 +388,16 @@ void l10nMem::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool b // save all languages for (iL = 1; iL < iLsize; ++iL) { // only save language file if modified - if (!mcDb->mcLangList[iL].mbChanged) + if (!mcLangList[iL].mbChanged) continue; - mcDb->mcLangList[iL].mbChanged = false; + mcLangList[iL].mbChanged = false; +#if 0 convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName); - savePo.startSave(mcDb->mcLangList[iL].msName + "/", sFileName); + savePo.startSave(mcLangList[iL].msName + "/", sFileName); for (iE = 1; iE < iEsize; ++iE) { - l10nMem_enus_entry& cE = mcDb->mcENUSlist[iE]; + l10nMem_enus_entry& cE = mcENUSlist[iE]; l10nMem_lang_entry& cL = cE.mcLangText[iL]; bool bF = cL.mbFuzzy; @@ -244,9 +405,10 @@ void l10nMem::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool b if (cE.meState == ENTRY_DELETED) continue; - savePo.save(mcDb->mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, cL.msMsgStr, bF); + savePo.save(mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, cL.msMsgStr, bF); } savePo.endSave(); +#endif } } @@ -254,10 +416,10 @@ void l10nMem::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool b void l10nMem::showNOconvert() { - int iE, iEsize = mcDb->mcENUSlist.size(); + int iE, iEsize = mcENUSlist.size(); for (iE = 1; iE < iEsize; ++iE) { - l10nMem_enus_entry& cE = mcDb->mcENUSlist[iE]; + l10nMem_enus_entry& cE = mcENUSlist[iE]; if (cE.meState == ENTRY_DELETED) showError("template key(" + cE.msKey + ") msgId(" + cE.msMsgId + ") not in pot file", 0); @@ -306,7 +468,8 @@ void l10nMem::convertFromInetString(std::string& sText) int l10nMem::prepareMerge() { - return mcDb->prepareMerge(); + miCurLangInx = 0; + return mcLangList.size(); } @@ -314,7 +477,7 @@ int l10nMem::prepareMerge() void l10nMem::dumpMem(const std::string& sFileName) { // and reorganize db if needed - mcDb->reorganize(false); + reorganize(false); // no save if there has been errors if (!needWrite(sFileName, true)) @@ -325,9 +488,19 @@ void l10nMem::dumpMem(const std::string& sFileName) -bool l10nMem::getMergeLang(std::string& sL, std::string& sT) +bool l10nMem::getMergeLang(std::string& sLang, std::string& sMsgStr) { - return mcDb->getMergeLang(sL, sT); + miCurLangInx++; + if (miCurLangInx >= (int)mcLangList.size()) + return false; + + // update pointers + sLang = mcLangList[miCurLangInx].msName; + if (!sMsgStr.size()) + sMsgStr = "NOT TRANSLATED"; + else + sMsgStr = mcENUSlist[miCurENUSinx].mcLangText[miCurLangInx].msMsgStr; + return true; } @@ -335,8 +508,8 @@ bool l10nMem::getMergeLang(std::string& sL, std::string& sT) void l10nMem::formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText) { std::cout << sType; - if (mcDb->miCurFileInx > 0) - std::cout << " in " << mcDb->mcFileList[mcDb->miCurFileInx].msFileName; + if (miCurFileInx > 0) + std::cout << " in " << mcFileList[miCurFileInx].msFileName; if (iLineNo) std::cout << "(" << iLineNo << ")"; std::cout << ": " << sText << std::endl; @@ -346,7 +519,7 @@ void l10nMem::formatAndShowText(const std::string& sType, int iLineNo, const std bool l10nMem::needWrite(const std::string sFileName, bool bForce) { - int iE, iEsize = mcDb->mcENUSlist.size(); + int iE, iEsize = mcENUSlist.size(); int iCntDeleted = 0, iCntChanged = 0, iCntAdded = 0; // no save if there has been errors @@ -355,18 +528,18 @@ bool l10nMem::needWrite(const std::string sFileName, bool bForce) // Check number of changes for (iE = 1; iE < iEsize; ++iE) { - l10nMem_enus_entry& cur = mcDb->mcENUSlist[iE]; + l10nMem_enus_entry& cur = mcENUSlist[iE]; if (cur.meState == ENTRY_ADDED) ++iCntAdded; if (cur.meState == ENTRY_CHANGED) { ++iCntChanged; - if (mcDb->mbStrictMode) + if (mbStrictMode) cur.meState = ENTRY_NORMAL; } if (cur.meState == ENTRY_DELETED) ++iCntDeleted; } - if (!mcDb->mbConvertMode) + if (!mbConvertMode) iCntDeleted -= iCntChanged; if (!iCntAdded && !iCntChanged && !iCntDeleted) { std::cout << "genLang: No changes in " << sFileName; @@ -515,11 +688,11 @@ void l10nMem::convEntryKey(int iLineNo, // Find all matching file names (old system does not have directory. // build list of potential entries - iSize = mcDb->mcFileList.size(); + iSize = mcFileList.size(); for (curFileIndex = 1; curFileIndex < iSize; ++curFileIndex) - if (curFileName == mcDb->mcFileList[curFileIndex].msPureName) { - int j = mcDb->mcFileList[curFileIndex].miStart; - int iEnd = mcDb->mcFileList[curFileIndex].miEnd; + if (curFileName == mcFileList[curFileIndex].msPureName) { + int j = mcFileList[curFileIndex].miStart; + int iEnd = mcFileList[curFileIndex].miEnd; for (; j <= iEnd; ++j) ivEntryList.push_back(j); @@ -534,10 +707,10 @@ void l10nMem::convEntryKey(int iLineNo, // Loop through all potential en-US entries for (curENUSindex = -1, i = 0; i < iSize; ++i) { - l10nMem_enus_entry& curE = mcDb->mcENUSlist[ivEntryList[i]]; + l10nMem_enus_entry& curE = mcENUSlist[ivEntryList[i]]; // The entry must be unconverted if strict mode (comparing .pot files) - if (mcDb->mbStrictMode && curE.meState != ENTRY_DELETED) + if (mbStrictMode && curE.meState != ENTRY_DELETED) continue; // msgId must match @@ -550,14 +723,14 @@ void l10nMem::convEntryKey(int iLineNo, } // do we need to do advanced find - if (curENUSindex == -1 || mcDb->mbStrictMode) { + if (curENUSindex == -1 || mbStrictMode) { // make copy of key in upper case curKeyUpper = sKey; - l10nMem_db::keyToUpper(curKeyUpper); + keyToUpper(curKeyUpper); // Loop through all potential en-US entries for (i = 0; i < iSize; ++i) { - l10nMem_enus_entry& curE = mcDb->mcENUSlist[ivEntryList[i]]; + l10nMem_enus_entry& curE = mcENUSlist[ivEntryList[i]]; // compare keys, but be aware of different length if (curKeyUpper.find(curE.msKey) != std::string::npos) { @@ -574,13 +747,237 @@ void l10nMem::convEntryKey(int iLineNo, } // update language text - l10nMem_enus_entry& curE = mcDb->mcENUSlist[curENUSindex]; - l10nMem_lang_entry& curL = curE.mcLangText[mcDb->miCurLangInx]; + l10nMem_enus_entry& curE = mcENUSlist[curENUSindex]; + l10nMem_lang_entry& curL = curE.mcLangText[miCurLangInx]; if (sMsgStr != curL.msMsgStr) { curL.msMsgStr = sMsgStr; curL.mbFuzzy = bIsFuzzy; curE.meState = ENTRY_CHANGED; - mcDb->mcLangList[mcDb->miCurLangInx].mbChanged = true; + mcLangList[miCurLangInx].mbChanged = true; + } +} + + + +void l10nMem::loadENUSkey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId) +{ + // add it to vector and update file pointer + addKey(iLineNo, sSourceFile, sKey, sMsgId, ENTRY_DELETED); +} + +void l10nMem::loadLangKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + const std::string& sMsgStr, + bool bFuzzy) +{ + if (!locateKey(iLineNo, sSourceFile, sKey, sMsgId, true)) + throw l10nMem::showError(".po file contains unknown filename: " + sSourceFile + " or key: " + sKey); + + l10nMem_lang_entry& xCur = mcENUSlist[miCurENUSinx].mcLangText[miCurLangInx]; + xCur.msMsgStr = sMsgStr; + xCur.mbFuzzy = bFuzzy; +} + + + +void l10nMem::reorganize(bool bConvert) +{ + int iE, iEsize = mcENUSlist.size(); + int iD, iDsize; + std::vector<int> listDel, listAdd; + + + // Check number of changes + for (iE = 1; iE < iEsize; ++iE) + { + l10nMem_enus_entry& cur = mcENUSlist[iE]; + if (cur.meState == l10nMem::ENTRY_ADDED) + listAdd.push_back(iE); + if (cur.meState == l10nMem::ENTRY_DELETED) + { + if (bConvert) + cur.meState = l10nMem::ENTRY_NORMAL; + else + listDel.push_back(iE); + } + } + + if (!listDel.size() || !listAdd.size()) + return; + + // loop through added text and see if key match deleted text + iEsize = listAdd.size(); + iDsize = listDel.size(); + for (iE = 0; iE < iEsize; ++iE) + { + l10nMem_enus_entry& curAdd = mcENUSlist[listAdd[iE]]; + for (iD = 0; iD < iDsize; ++iD) + { + l10nMem_enus_entry& curE = mcENUSlist[listDel[iD]]; + + if (curE.miFileInx != curAdd.miFileInx) + continue; + if (curE.msKey == curAdd.msKey) + break; + if (curE.msMsgId == curAdd.msMsgId) + break; + } + if (iD == iDsize) + continue; + + // Update deleted entry (original), because lang is connected here + l10nMem_enus_entry& curDel = mcENUSlist[listDel[iD]]; + curDel.msMsgId = curAdd.msMsgId; + curDel.msKey = curAdd.msKey; + curDel.meState = l10nMem::ENTRY_CHANGED; + curAdd.meState = l10nMem::ENTRY_DELETED; + } +} + + + +bool l10nMem::locateKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + bool bThrow) +{ + std::string sUpperKey(sKey); + int i, iSize = sUpperKey.size(); + char ch; + + // Position file pointer + if (!findFileName(sSourceFile)) + return false; + + // convert key to upper case + for (i = 0; i < iSize; ++i) + { + ch = sUpperKey[i]; + if (ch == ' ' || ch == '*' || ch == '+' || ch == '%') + sUpperKey[i] = '_'; + else + sUpperKey[i] = toupper(sUpperKey[i]); + } + + // Fast check, to see if next key is the one (normal with load and source without change) + if (++miCurENUSinx < (int)mcENUSlist.size()) + { + l10nMem_enus_entry& nowEntry = mcENUSlist[miCurENUSinx]; + if (nowEntry.msMsgId == sMsgId && nowEntry.msKey == sUpperKey) + return true; + } + + // Start from beginning of file and to end + l10nMem_file_entry& cCur = mcFileList[miCurFileInx]; + + // Find match with key and text + for (miCurENUSinx = cCur.miStart; miCurENUSinx <= cCur.miEnd; ++miCurENUSinx) + { + l10nMem_enus_entry& cEntry = mcENUSlist[miCurENUSinx]; + if (cEntry.msMsgId == sMsgId && cEntry.msKey == sUpperKey) + return true; } + + if (bThrow) + throw l10nMem::showError("cannot find key(" + sUpperKey + ") with text(" + sMsgId + ")", iLineNo); + return false; } + + + +void l10nMem::addKey(int iLineNo, + const std::string& sSourceFile, + const std::string& sKey, + const std::string& sMsgId, + l10nMem::ENTRY_STATE eStat) +{ + // check file + if (!findFileName(sSourceFile)) + { + // prepare for new entry + miCurENUSinx = mcENUSlist.size(); + miCurFileInx = mcFileList.size(); + + // Create file + mcFileList.push_back(l10nMem_file_entry(sSourceFile, miCurENUSinx)); + + // and add entry at the back (no problem since it is a new file) + mcENUSlist.push_back(l10nMem_enus_entry(sKey, sMsgId, iLineNo, miCurFileInx, + mcLangList.size(), eStat)); + mcFileList[miCurFileInx].miEnd = miCurENUSinx; + } + else + { + int iFsize = mcFileList.size(); + l10nMem_file_entry& curF = mcFileList[miCurFileInx]; + std::vector<l10nMem_enus_entry>::iterator it = mcENUSlist.begin(); + + // file is registred, so we need to add the entry at the end of the file range + curF.miEnd++; + miCurENUSinx = curF.miEnd; + mcENUSlist.insert(it + curF.miEnd, + l10nMem_enus_entry(sKey, sMsgId, iLineNo, miCurFileInx, + mcLangList.size(), eStat)); + for (int i = miCurFileInx + 1; i < iFsize; ++i) + { + l10nMem_file_entry& curF2 = mcFileList[i]; + if (curF2.miStart >= curF.miEnd) + curF2.miStart++; + if (curF2.miEnd >= curF.miEnd) + curF2.miEnd++; + } + } +} + + +bool l10nMem::findFileName(const std::string& sSourceFile) +{ + int iSize = mcFileList.size(); + + // Check this or next file + if (mcFileList[miCurFileInx].msFileName == sSourceFile || mcFileList[miCurFileInx].msPureName == sSourceFile) + return true; + if (++miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName == sSourceFile) + return true; + + for (miCurFileInx = 1; + miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName != sSourceFile && + mcFileList[miCurFileInx].msPureName != sSourceFile; + ++miCurFileInx); + if (miCurFileInx == iSize) + { + miCurFileInx = 0; + return false; + } + else + return true; +} + + + + +void l10nMem::keyToUpper(std::string& sKey) +{ + int i, iSize; + + iSize = sKey.size(); + for (i = 0; i < iSize; ++i) + { + char ch = sKey[i]; + if (ch == ' ' || ch == '*' || ch == '+' || ch == '%') + sKey[i] = '_'; + else + sKey[i] = toupper(ch); + } +} + + + + diff --git a/l10ntools/source/gL10nMemDB.cxx b/l10ntools/source/gL10nMemDB.cxx deleted file mode 100644 index 513342431528..000000000000 --- a/l10ntools/source/gL10nMemDB.cxx +++ /dev/null @@ -1,453 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * 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 . - */ - -#include "gL10nMem.hxx" -#include <iostream> -#include <fstream> -#include <sstream> - - - - - -/********************** I M P L E M E N T A T I O N **********************/ -l10nMem_lang_entry::l10nMem_lang_entry(const std::string& sMsgStr, bool bFuzzy) - : - msMsgStr(sMsgStr), - mbFuzzy(bFuzzy) -{ -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -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& sMsgId, - int iLineNo, - int iFileInx, - int iLangSize, - l10nMem::ENTRY_STATE eState) - : - msMsgId(sMsgId), - meState(eState), - miFileInx(iFileInx), - miLineNo(iLineNo) -{ - int i; - - // add dummy language entries - for (i = 0; i < iLangSize; ++i) - mcLangText.push_back(l10nMem_lang_entry("", false)); - - // convert key to upper case - msKey = sKey; - l10nMem_db::keyToUpper(msKey); -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -l10nMem_enus_entry::~l10nMem_enus_entry() -{ -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -l10nMem_file_entry::l10nMem_file_entry(const std::string& sFileName, int iStart) - : - msFileName(sFileName), - miStart(iStart), - miEnd(iStart) -{ - // Store fileName without relative path - int i = msFileName.rfind("/"); - if (i == (int)std::string::npos) - msPureName = msFileName; - else - msPureName = msFileName.substr(i+1); -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -l10nMem_file_entry::~l10nMem_file_entry() -{ -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -l10nMem_lang_list_entry::l10nMem_lang_list_entry(const std::string& sName) - : - msName(sName), - mbChanged(false) -{ -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -l10nMem_lang_list_entry::~l10nMem_lang_list_entry() -{ -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -l10nMem_db::l10nMem_db() - : - miCurFileInx(0), - miCurLangInx(0), - miCurENUSinx(0), - mbNeedWrite(false), - mbConvertMode(false), - mbStrictMode(false) -{ - mcFileList.push_back(l10nMem_file_entry("-genLang-", 0)); - mcLangList.push_back(l10nMem_lang_list_entry("-genLang-")); - mcENUSlist.push_back(l10nMem_enus_entry("-genLang-", "-genLang-", 0, 0, 0, l10nMem::ENTRY_DELETED)); -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -l10nMem_db::~l10nMem_db() -{ -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::loadENUSkey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId) -{ - // add it to vector and update file pointer - addKey(iLineNo, sSourceFile, sKey, sMsgId, l10nMem::ENTRY_DELETED); -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::setLanguage(const std::string& sLanguage, - bool bCreate) -{ - int i, iSize; - - // regular load or convert of old po files - miCurFileInx = 0; - - // With no languages selected only en-US is generated - if (!sLanguage.size()) - { - miCurLangInx = 0; - return; - } - - // en-US is loaded as master and cannot be loaded again - if (sLanguage == "en-US") - throw l10nMem::showError("en-US is loaded automatically"); - - // check if language is already loaded - iSize = mcLangList.size(); - for (miCurLangInx = 0; miCurLangInx < iSize && mcLangList[miCurLangInx].msName != sLanguage; ++miCurLangInx) ; - if (miCurLangInx < iSize) - { - if (bCreate) - throw l10nMem::showError("loading " + sLanguage + " twice"); - return; - } - - // 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 (i = 0; i < iSize; ++i) - mcENUSlist[i].mcLangText.push_back(l10nMem_lang_entry("", false)); -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::setConvert(bool bConvert, - bool bStrict) -{ - // regular load or convert of old po files - mbConvertMode = bConvert; - mbStrictMode = bStrict; -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -bool l10nMem_db::findFileName(const std::string& sSourceFile) -{ - int iSize = mcFileList.size(); - - // Check this or next file - if (mcFileList[miCurFileInx].msFileName == sSourceFile || mcFileList[miCurFileInx].msPureName == sSourceFile) - return true; - if (++miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName == sSourceFile) - return true; - - for (miCurFileInx = 1; - miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName != sSourceFile && - mcFileList[miCurFileInx].msPureName != sSourceFile; - ++miCurFileInx) ; - if (miCurFileInx == iSize) - { - miCurFileInx = 0; - return false; - } - else - return true; -} - - - -/********************** 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& sMsgId, - const std::string& sMsgStr, - bool bFuzzy) -{ - if (!locateKey(iLineNo, sSourceFile, sKey, sMsgId, true)) - throw l10nMem::showError(".po file contains unknown filename: " + sSourceFile + " or key: " + sKey); - - l10nMem_lang_entry& xCur = mcENUSlist[miCurENUSinx].mcLangText[miCurLangInx]; - xCur.msMsgStr = sMsgStr; - xCur.mbFuzzy = bFuzzy; -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::reorganize(bool bConvert) -{ - int iE, iEsize = mcENUSlist.size(); - int iD, iDsize; - std::vector<int> listDel, listAdd; - - - // Check number of changes - for (iE = 1; iE < iEsize; ++iE) - { - l10nMem_enus_entry& cur = mcENUSlist[iE]; - if (cur.meState == l10nMem::ENTRY_ADDED) - listAdd.push_back(iE); - if (cur.meState == l10nMem::ENTRY_DELETED) - { - if (bConvert) - cur.meState = l10nMem::ENTRY_NORMAL; - else - listDel.push_back(iE); - } - } - - if (!listDel.size() || !listAdd.size()) - return; - - // loop through added text and see if key match deleted text - iEsize = listAdd.size(); - iDsize = listDel.size(); - for (iE = 0; iE < iEsize; ++iE) - { - l10nMem_enus_entry& curAdd = mcENUSlist[listAdd[iE]]; - for (iD = 0; iD < iDsize; ++iD) - { - l10nMem_enus_entry& curE = mcENUSlist[listDel[iD]]; - - if (curE.miFileInx != curAdd.miFileInx) - continue; - if (curE.msKey == curAdd.msKey) - break; - if (curE.msMsgId == curAdd.msMsgId) - break; - } - if (iD == iDsize) - continue; - - // Update deleted entry (original), because lang is connected here - l10nMem_enus_entry& curDel = mcENUSlist[listDel[iD]]; - curDel.msMsgId = curAdd.msMsgId; - curDel.msKey = curAdd.msKey; - curDel.meState = l10nMem::ENTRY_CHANGED; - curAdd.meState = l10nMem::ENTRY_DELETED; - } -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -bool l10nMem_db::locateKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - bool bThrow) -{ - std::string sUpperKey(sKey); - int i, iSize = sUpperKey.size(); - char ch; - - // Position file pointer - if (!findFileName(sSourceFile)) - return false; - - // convert key to upper case - for (i = 0; i < iSize; ++i) - { - ch = sUpperKey[i]; - if (ch == ' ' || ch == '*' || ch == '+' || ch == '%') - sUpperKey[i] = '_'; - else - sUpperKey[i] = toupper(sUpperKey[i]); - } - - // Fast check, to see if next key is the one (normal with load and source without change) - if (++miCurENUSinx < (int)mcENUSlist.size()) - { - l10nMem_enus_entry& nowEntry = mcENUSlist[miCurENUSinx]; - if (nowEntry.msMsgId == sMsgId && nowEntry.msKey == sUpperKey) - return true; - } - - // Start from beginning of file and to end - l10nMem_file_entry& cCur = mcFileList[miCurFileInx]; - - // Find match with key and text - for (miCurENUSinx = cCur.miStart; miCurENUSinx <= cCur.miEnd; ++miCurENUSinx) - { - l10nMem_enus_entry& cEntry = mcENUSlist[miCurENUSinx]; - if (cEntry.msMsgId == sMsgId && cEntry.msKey == sUpperKey) - return true; - } - - if (bThrow) - throw l10nMem::showError("cannot find key(" + sUpperKey +") with text(" + sMsgId + ")", iLineNo); - return false; -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::addKey(int iLineNo, - const std::string& sSourceFile, - const std::string& sKey, - const std::string& sMsgId, - l10nMem::ENTRY_STATE eStat) -{ - // check file - if (!findFileName(sSourceFile)) - { - // prepare for new entry - miCurENUSinx = mcENUSlist.size(); - miCurFileInx = mcFileList.size(); - - // Create file - mcFileList.push_back(l10nMem_file_entry(sSourceFile, miCurENUSinx)); - - // and add entry at the back (no problem since it is a new file) - mcENUSlist.push_back(l10nMem_enus_entry(sKey, sMsgId, iLineNo, miCurFileInx, - mcLangList.size(), eStat)); - mcFileList[miCurFileInx].miEnd = miCurENUSinx; - } - else - { - int iFsize = mcFileList.size(); - l10nMem_file_entry& curF = mcFileList[miCurFileInx]; - std::vector<l10nMem_enus_entry>::iterator it = mcENUSlist.begin(); - - // file is registred, so we need to add the entry at the end of the file range - curF.miEnd++; - miCurENUSinx = curF.miEnd; - mcENUSlist.insert(it + curF.miEnd, - l10nMem_enus_entry(sKey, sMsgId, iLineNo, miCurFileInx, - mcLangList.size(), eStat)); - for (int i = miCurFileInx+1; i < iFsize; ++i) - { - l10nMem_file_entry& curF2 = mcFileList[i]; - if (curF2.miStart >= curF.miEnd) - curF2.miStart++; - if (curF2.miEnd >= curF.miEnd) - curF2.miEnd++; - } - } -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -int l10nMem_db::prepareMerge() -{ - miCurLangInx = 0; - return mcLangList.size(); -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -bool l10nMem_db::getMergeLang(std::string& sLang, - std::string& sMsgStr) -{ - miCurLangInx++; - if (miCurLangInx >= (int)mcLangList.size()) - return false; - - // update pointers - sLang = mcLangList[miCurLangInx].msName; - if (!sMsgStr.size()) - sMsgStr = "NOT TRANSLATED"; - else - sMsgStr = mcENUSlist[miCurENUSinx].mcLangText[miCurLangInx].msMsgStr; - return true; -} - - - -/********************** I M P L E M E N T A T I O N **********************/ -void l10nMem_db::keyToUpper(std::string& sKey) -{ - int i, iSize; - - iSize = sKey.size(); - for (i = 0; i < iSize; ++i) - { - char ch = sKey[i]; - if (ch == ' ' || ch == '*' || ch == '+' || ch == '%') - sKey[i] = '_'; - else - sKey[i] = toupper(ch); - } -} diff --git a/l10ntools/source/gLang.cxx b/l10ntools/source/gLang.cxx index da078285e285..757e9ebcddcb 100644 --- a/l10ntools/source/gLang.cxx +++ b/l10ntools/source/gLang.cxx @@ -16,8 +16,12 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "gLang.hxx" #include <iostream> +#include <string> +#include <vector> + +#include "gL10nMem.hxx" +#include "gConv.hxx" @@ -34,7 +38,6 @@ class handler private: bool mbForceSave; - bool mbSave; enum {DO_CONVERT, DO_EXTRACT, DO_MERGE_KID, DO_MERGE} meWorkMode; std::string msTargetDir; std::string msPoDir; @@ -170,7 +173,7 @@ void handler::checkCommandLine(int argc, char *argv[]) // Set default - mbForceSave = mbSave = false; + mbForceSave = false; // check for fixed parameter: genLang <cmd> if (argc < 2) @@ -189,7 +192,7 @@ void handler::checkCommandLine(int argc, char *argv[]) sWorkText = argv[i]; if (sWorkText == "-d") { // show debug information - mcMemory.mbDebug = true; + mcMemory.setDebug(true); } else if (sWorkText == "-k") { // generate key identifier version @@ -199,11 +202,11 @@ void handler::checkCommandLine(int argc, char *argv[]) } else if (sWorkText == "-v") { // show progress information - mcMemory.mbVerbose = true; + mcMemory.setVerbose(true); } else if (sWorkText == "-s") { // forced save - mbSave = true; + mbForceSave = true; } else if (sWorkText == "--files") { // list of input files @@ -323,7 +326,7 @@ void handler::loadL10MEM(bool onlyTemplates) // load texts from en-US po file (master) // tell system - mcMemory.showDebug("genLang loading master text from file " + sLoad); + l10nMem::showDebug("genLang loading master text from file " + sLoad); // and load file mcMemory.setLanguage("", true); @@ -341,7 +344,7 @@ void handler::loadL10MEM(bool onlyTemplates) mcMemory.setLanguage(*siLang, true); // tell system - mcMemory.showDebug("genLang loading text from language file " + sLoad); + l10nMem::showDebug("genLang loading text from language file " + sLoad); convert_gen(mcMemory, sLoad, msTargetDir, "").execute(false, false); } @@ -362,7 +365,7 @@ void handler::runConvert() for (siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource) { // tell system - mcMemory.showDebug("genLang compare template " + *siSource); + l10nMem::showDebug("genLang compare template " + *siSource); // get converter and extract files convert_gen convertObj(mcMemory, "./", msTargetDir, *siSource); @@ -378,7 +381,7 @@ void handler::runConvert() mcMemory.setLanguage(*siLang, false); // tell system - mcMemory.showDebug("genLang convert text from file " + + l10nMem::showDebug("genLang convert text from file " + sFilePath + *siSource + " language " + *siLang); // get converter and extract files @@ -405,7 +408,7 @@ void handler::runExtract() for (siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource) { // tell system - mcMemory.showDebug("genLang extracting text from file " + *siSource); + l10nMem::showDebug("genLang extracting text from file " + *siSource); // get converter and extract file convert_gen convertObj(mcMemory, "", msTargetDir, *siSource); @@ -429,7 +432,7 @@ void handler::runMerge(bool bKid) for (siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource) { // tell system - mcMemory.showDebug("genLang merging translated text to file " + *siSource); + l10nMem::showDebug("genLang merging translated text to file " + *siSource); // get converter and extract file convert_gen convertObj(mcMemory, "", msTargetDir, *siSource); diff --git a/l10ntools/source/gLexPo.l b/l10ntools/source/gLexPo.l index bc4507c6172c..3d6bfc33e150 100644 --- a/l10ntools/source/gLexPo.l +++ b/l10ntools/source/gLexPo.l @@ -35,6 +35,10 @@ /*************** O V E R W R I T I N G F U N C T I O N S ***************/ %top{ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvPo.hxx" #define IMPLptr convert_gen_impl::mcImpl diff --git a/l10ntools/source/gLexSrc.l b/l10ntools/source/gLexSrc.l index 3d5b0007e75a..d298d0feb007 100644 --- a/l10ntools/source/gLexSrc.l +++ b/l10ntools/source/gLexSrc.l @@ -20,6 +20,10 @@ /*************** O V E R W R I T I N G F U N C T I O N S ***************/ %top{ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvSrc.hxx" #define IMPLptr convert_gen_impl::mcImpl diff --git a/l10ntools/source/gLexTree.l b/l10ntools/source/gLexTree.l index c9f25f5b706b..4b8aa2c93c69 100644 --- a/l10ntools/source/gLexTree.l +++ b/l10ntools/source/gLexTree.l @@ -20,6 +20,10 @@ /*************** O V E R W R I T I N G F U N C T I O N S ***************/ %top{ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvTree.hxx" #define IMPLptr convert_gen_impl::mcImpl diff --git a/l10ntools/source/gLexUlf.l b/l10ntools/source/gLexUlf.l index ccac793235a4..bb204f2154d8 100644 --- a/l10ntools/source/gLexUlf.l +++ b/l10ntools/source/gLexUlf.l @@ -20,6 +20,10 @@ /*************** O V E R W R I T I N G F U N C T I O N S ***************/ %top{ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvUlf.hxx" #define IMPLptr convert_gen_impl::mcImpl diff --git a/l10ntools/source/gLexXcs.l b/l10ntools/source/gLexXcs.l index d099f9fb88e7..cfd11dafe62e 100644 --- a/l10ntools/source/gLexXcs.l +++ b/l10ntools/source/gLexXcs.l @@ -20,6 +20,10 @@ /*************** O V E R W R I T I N G F U N C T I O N S ***************/ %top{ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvXcs.hxx" #define IMPLptr convert_gen_impl::mcImpl diff --git a/l10ntools/source/gLexXcu.l b/l10ntools/source/gLexXcu.l index 3d956aa2da18..b3095efe9e32 100644 --- a/l10ntools/source/gLexXcu.l +++ b/l10ntools/source/gLexXcu.l @@ -20,6 +20,10 @@ /*************** O V E R W R I T I N G F U N C T I O N S ***************/ %top{ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvXcu.hxx" #define IMPLptr convert_gen_impl::mcImpl diff --git a/l10ntools/source/gLexXhp.l b/l10ntools/source/gLexXhp.l index f99e93fa7ca8..a2c23fd18362 100644 --- a/l10ntools/source/gLexXhp.l +++ b/l10ntools/source/gLexXhp.l @@ -20,6 +20,10 @@ /*************** O V E R W R I T I N G F U N C T I O N S ***************/ %top{ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvXhp.hxx" #define IMPLptr convert_gen_impl::mcImpl diff --git a/l10ntools/source/gLexXrm.l b/l10ntools/source/gLexXrm.l index 292a666b9ccf..aadab8ea9f28 100644 --- a/l10ntools/source/gLexXrm.l +++ b/l10ntools/source/gLexXrm.l @@ -20,6 +20,10 @@ /*************** O V E R W R I T I N G F U N C T I O N S ***************/ %top{ +#include <string> +#include <vector> + +#include "gL10nMem.hxx" #include "gConvXrm.hxx" #define IMPLptr convert_gen_impl::mcImpl diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index 7789e3bad730..3922e89f0b9d 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -121,22 +121,13 @@ bool MergeEntrys::GetText( OString &rReturn, return bReturn; } -namespace -{ - OString GetDoubleBars() - { - //DOUBLE VERTICAL LINE instead of || because the translations make their - //way into action_names under gtk3 where || is illegal - return OUStringToOString(OUString(static_cast<sal_Unicode>(0x2016)), RTL_TEXTENCODING_UTF8); - } -} OString MergeEntrys::GetQTZText(const ResData& rResData, const OString& rOrigText) { const OString sFilename = rResData.sFilename.copy(rResData.sFilename.lastIndexOf('/')+1); const OString sKey = PoEntry::genKeyId(sFilename + rResData.sGId + rResData.sId + rResData.sResTyp + rOrigText); - return sKey + GetDoubleBars() + rOrigText; + return sKey + "||" + rOrigText; } @@ -420,9 +411,9 @@ void MergeDataFile::InsertEntry( const OString sTemp = rInFilename + rGID + rLID + rTYP; pMergeEntrys->InsertEntry( nLANG, - rTEXT.isEmpty()? rTEXT : PoEntry::genKeyId(sTemp + rTEXT) + GetDoubleBars() + rTEXT, - rQHTEXT.isEmpty()? rQHTEXT : PoEntry::genKeyId(sTemp + rQHTEXT) + GetDoubleBars() + rQHTEXT, - rTITLE.isEmpty()? rTITLE : PoEntry::genKeyId(sTemp + rTITLE) + GetDoubleBars() + rTITLE ); + rTEXT.isEmpty()? rTEXT : PoEntry::genKeyId(sTemp + rTEXT) + "||" + rTEXT, + rQHTEXT.isEmpty()? rQHTEXT : PoEntry::genKeyId(sTemp + rQHTEXT) + "||" + rQHTEXT, + rTITLE.isEmpty()? rTITLE : PoEntry::genKeyId(sTemp + rTITLE) + "||" + rTITLE ); } else { |