[Libreoffice-commits] core.git: 2 commits - l10ntools/Executable_genlang.mk l10ntools/inc l10ntools/source
jan iversen
jani at documentfoundation.org
Mon Mar 14 14:11:31 UTC 2016
l10ntools/Executable_genlang.mk | 1
l10ntools/inc/gL10nMem.hxx | 79 ---
l10ntools/inc/gLang.hxx | 195 ++++----
l10ntools/source/gConv.cxx | 5
l10ntools/source/gConvProp.cxx | 2
l10ntools/source/gHandler.cxx | 531 ----------------------
l10ntools/source/gL10nMem.cxx | 963 ++++++++++++++++------------------------
l10ntools/source/gL10nMemDB.cxx | 10
l10ntools/source/gLang.cxx | 23
9 files changed, 518 insertions(+), 1291 deletions(-)
New commits:
commit 4cbb7cdf1be8219c34eb38e6a0d59aa8418c8a85
Author: jan iversen <jani at documentfoundation.org>
Date: Mon Mar 14 14:48:00 2016 +0100
genLang update
removed source/gHandler.cxx is now part of gLang.cxx
(and defined as a local class)
Change-Id: I6fccfb9d9cebe964ba4458cdea5121a44186c1ab
diff --git a/l10ntools/source/gHandler.cxx b/l10ntools/source/gHandler.cxx
deleted file mode 100644
index be95563..0000000
--- a/l10ntools/source/gHandler.cxx
+++ /dev/null
@@ -1,531 +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 <iostream>
-#include "gLang.hxx"
-#include <cstdlib>
-#include <iostream>
-#include <fstream>
-
-
-
-/*****************************************************************************
- ************************ G H A N D L E R . C X X ************************
- *****************************************************************************
- * This is the control module, that interpret the command line and implement
- * the different work types
- * extract / merge / generate / convert
- *****************************************************************************/
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-handler::handler()
- :
- mbForceSave(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, sLangText;
- int argNow, nLen;
-
-
- // make internal throw test (to avoid if cascades
- try
- {
- // check for fixed parameter: genLang <cmd> <module> <po dir> <languages>
- if (argc <= 5)
- throw "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 == "merge") meWorkMode = DO_MERGE;
- else if (sWorkText == "help") showManual();
- else throw "<command> is mandatory";
-
- // and set fixed parameters
- msModuleName = argv[2];
- msPoOutDir = msPoDir = argv[3];
- sLangText = argv[4];
- if (sLangText[0] == '\"')
- sLangText.erase(0,1);
- nLen = sLangText.size() -1;
- if (nLen > 0 && sLangText[nLen] == '\"')
- sLangText.erase(nLen);
-
- // decode parameters and translate to variables
- for (argNow = 5; argNow < argc;)
- {
- std::string sArg(argv[argNow++]);
-
- // all -x is followed by a directory/file name
- if (sArg[0] == '-')
- {
- // 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 == "-d") {l10nMem::setShowDebug(); }
- else if (sArg == "-f") {eGotArg = ARG_F; }
- else if (sArg == "-k") {if (meWorkMode == DO_EXTRACT)
- meWorkMode = DO_EXTRACT_KID;
- else
- throw "-k is not valid"; }
- else if (sArg == "-o") {eGotArg = ARG_O; mbForceSave = true; }
- else if (sArg == "-p") {if (meWorkMode == DO_CONVERT)
- meWorkMode = DO_CONVERT_POT;
- else
- throw "-p is not valid"; }
- else if (sArg == "-s") {eGotArg = ARG_S; }
- else if (sArg == "-t") {eGotArg = ARG_T; }
- else if (sArg == "-v") {l10nMem::setShowVerbose(); }
- else throw std::string("unknown parameter: ") + sArg;
- }
- else
- {
- switch (eGotArg)
- {
- case ARG_NONE: break;
- case ARG_F: mvSourceFiles.push_back(sArg); break;
- case ARG_O: msPoOutDir = sArg; eGotArg = ARG_NONE; break;
- case ARG_S: msSourceDir = sArg; eGotArg = ARG_NONE; break;
- case ARG_T: msTargetDir = sArg; eGotArg = ARG_NONE; break;
- }
- }
- }
-
- // Check parameters mandatory for all commands
- if (!msModuleName.size())
- throw "<module name> is mandatory";
- if (!msPoDir.size())
- throw "<po dir> is mandatory";
-
- // control parameter usage according to selected action;
- {
- int useLangText, useSoption, useToption;
- useLangText = useSoption = useToption = -1;
-
- if (!mvSourceFiles.size())
- throw "-f <files> is missing or empty";
-
- switch (meWorkMode)
- {
- case DO_EXTRACT:
- case DO_EXTRACT_KID:
- break;
-
- case DO_MERGE:
- useSoption = 0;
- useLangText = 1;
- useToption = 1;
- break;
-
- case DO_CONVERT:
- useLangText = 1;
- case DO_CONVERT_POT:
- useToption = 1;
- break;
- }
-
- if (sLangText.size() && useLangText == -1)
- throw "<languages> must be empty";
- if (!sLangText.size() && useLangText == 1)
- throw "<languages> is mandatory";
- if (msSourceDir.size() && useSoption == -1)
- throw "-s <source dir> is not valid";
- if (msSourceDir.size() && useSoption == 1)
- throw "-s <source dir> is mandatory";
- if (msTargetDir.size() && useToption == -1)
- throw "-t <target dir> is not valid";
- if (!msTargetDir.size() && useToption == 1)
- throw "-t <target dir> is mandatory";
- }
-
- if (msTargetDir.size() && !convert_gen::checkAccess(msTargetDir))
- throw "<target dir> does not exist";
- if (msSourceDir.size() && !convert_gen::checkAccess(msSourceDir))
- throw "<source dir> does not exist";
- }
- catch(const char *sErr)
- {
- std::string myErr(sErr);
- showUsage(myErr);
- exit(-1);
- }
- catch(std::string sErr)
- {
- showUsage(sErr);
- exit(-1);
- }
-
- // update directories to include final /
- 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("/");
-
- // and convert language to a vector
- if (sLangText.size())
- {
- int current;
- int next = -1;
- do
- {
- current = next + 1;
- next = sLangText.find_first_of( " ", current );
- std::string sNewLang = sLangText.substr(current,next-current);
- if (sNewLang != "en-US")
- mvLanguages.push_back(sLangText.substr(current,next-current));
- }
- while (next != (int)std::string::npos);
- }
-
- // check if source files list needs to be coverted
- if (mvSourceFiles[0] == "USEFILE:")
- readFileWithSources();
-
- // tell system
- l10nMem::showVerbose("genLang starting to " + sWorkText + " from module " + msModuleName);
-}
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-void handler::run()
-{
- try
- {
- // prepare translation memory to module type
- mcMemory.setModuleName(msModuleName);
-
- // build list of languages (to be loaded and later written
- if (msPoDir.size())
- loadL10MEM( (meWorkMode == DO_EXTRACT) );
-
- // use workMode to start correct control part
- switch (meWorkMode)
- {
- case DO_EXTRACT: runExtract(false); break;
- case DO_EXTRACT_KID: runExtract(true); break;
- case DO_MERGE: runMerge(); break;
- case DO_CONVERT: runConvert(false); break;
- case DO_CONVERT_POT: runConvert(true); break;
- }
- }
- catch(int)
- {
- exit(-1);
- }
-}
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-void handler::runExtract(bool bKid)
-{
- // just to satisfy compiler
- if (bKid)
- return;
-
- // no convert
- mcMemory.setConvert(false, false);
-
- // loop through all source files, and extract messages from each file
- for (std::vector<std::string>::iterator siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource)
- {
- // tell system
- l10nMem::showDebug("genLang extracting text from file " + msSourceDir + *siSource);
-
- // get converter and extract file
- convert_gen convertObj(mcMemory, msSourceDir, msTargetDir, *siSource);
- convertObj.execute(false);
- }
-
- // and generate language file
- mcMemory.saveTemplates(msPoOutDir, false, mbForceSave);
-}
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-void handler::runMerge()
-{
- // no convert
- mcMemory.setConvert(false, false);
-
- // loop through all source files, and extract messages from each file
- for (std::vector<std::string>::iterator siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource)
- {
- // tell system
- l10nMem::showDebug("genLang merging translated text to file " + msSourceDir + *siSource);
-
- // get converter and extract file
- convert_gen convertObj(mcMemory, msSourceDir, msTargetDir, *siSource);
- convertObj.execute(true);
- }
-}
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-void handler::runConvert(bool bPot)
-{
- // convert
- mcMemory.setConvert(true, bPot);
-
- // loop through all source files, and extract messages from each file
- for (std::vector<std::string>::iterator siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource)
- {
- // handle .pot (templates)
- if (bPot)
- {
- // tell system
- l10nMem::showDebug("genLang compare template " + msSourceDir + *siSource);
-
- // get converter and extract files
- convert_gen convertObj(mcMemory, "./", msTargetDir, *siSource);
- convertObj.execute(false);
-
- if (bPot)
- mcMemory.showNOconvert();
- }
- else
- for (std::vector<std::string>::iterator siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang)
- {
- std::string sFilePath = msSourceDir + *siLang + "/";
-
- // get converter and extract files
- mcMemory.setLanguage(*siLang, false);
-
- // tell system
- l10nMem::showDebug("genLang convert text from file " + sFilePath + *siSource + " language " + *siLang);
-
- // get converter and extract files
- convert_gen convertObj(mcMemory, sFilePath, msTargetDir, *siSource);
- convertObj.execute(true);
- }
- }
-
- // and generate language file
- if (!bPot)
- mcMemory.saveLanguages(msPoOutDir, mbForceSave);
-}
-
-
-
-/********************** 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> [-d] [-f <files>] [-k] [-o <dir>] [-p] [-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::showManual()
-{
- // 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 (.pot)\n"
- "and merges with .po files in different languages.\n"
- "genLang uses .po files and AOO sources to generate language sources.\n"
- "\n"
- "genLang can also convert old .po files (generated from .sdf)\n"
- "\n";
-
- std::cout <<
- "Syntax:\n"
- " genLang extract <module> <po dir> \"\" [-v] [-d] \\\n"
- " -f <files> [-s <source dir>]\n"
- " if -s is omitted . is used\n"
- " extract text from <source dir>/<files>, result is merged and\n"
- " written to <po dir>/<module>.pot\n"
- "\n";
- std::cout <<
- " genLang merge <module> <po dir> <languages> [-v] [-d] [-k]\\\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";
- std::cout <<
- " genLang convert <module> <po dir> <languages> [-v] [-d]\\\n"
- " [-p] [-o <po outdir>] -s <source dir> -f <files>\n"
- " reads sdf generated .po <files> from\n"
- " <source dir>/*lang/<module>.po\n"
- " 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"
- " - Keys in <source dir>, not in <module>.po\n"
- " are shown as warnings\n"
- " - Keys in <source dir>, with changed translation\n"
- " are marked \"fuzzy\"\n"
- " - Keys in source files not in .po files (new keys)\n"
- " are added and marked \"fuzzy\"\n"
- " if -p is used, .pot files is assumed, and a compare is made\n"
- "\n";
- std::cout <<
- " genLang help\n"
- " this text\n"
- "\n";
- std::cout <<
- "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 or a module.dbpo file for fast loading\n"
- " <languages>\n"
- " comma separated string with langauge id to be used\n"
- "\n"
- " -d\n"
- " extensive verbose mode, tells what genLang 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"
- " instead of passing a list of files, it is possible to pass\n"
- " a file contains the list, by using:\n"
- " -f USEFILE: <filename>\n"
- " -k\n"
- " generate kid id (hex) for all messages in the source code,\n"
- " solely for QA\n"
- " -o <po outdir>\n"
- " directory to write .po files, same structure as -p\n"
- " -p\n"
- " used with convert, when comparing .pot files (old system == new system)\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 genLang is doing\n";
-
- exit(0);
-}
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-void handler::loadL10MEM(bool onlyTemplates)
-{
- std::string sMod = msModuleName + ".pot";
- std::string sLoad = msPoDir + "templates/";
-
- // no convert
- mcMemory.setConvert(false, false);
-
- // load texts from en-US po file (master)
- // tell system
- l10nMem::showDebug("genLang loading master text from file " + sLoad + sMod);
-
- // and load file
- mcMemory.setLanguage("", true);
- convert_gen (mcMemory, sLoad, msTargetDir, sMod).execute(false);
-
- if (onlyTemplates)
- return;
-
- // loop through all languages and load text
- sMod = msModuleName + ".po";
- for (std::vector<std::string>::iterator siLang = mvLanguages.begin(); siLang != mvLanguages.end(); ++siLang)
- {
- sLoad = msPoDir + *siLang + "/";
-
- // get converter and extract files
- mcMemory.setLanguage(*siLang, true);
-
- // tell system
- l10nMem::showDebug("genLang loading text from language file " + sLoad + sMod);
-
- convert_gen(mcMemory, sLoad, msTargetDir, sMod).execute(false);
- }
-}
-
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-void handler::readFileWithSources()
-{
- std::ifstream fInput;
- char buf[256];
-
-
- if (mvSourceFiles.size() < 2)
- throw l10nMem::showError("missing file with sources (-f USEFILE: <filename>)");
-
- fInput.open (mvSourceFiles[1].c_str(), std::ifstream::in);
- if (!fInput.is_open())
- throw l10nMem::showError("Cannot open file with sources (-f), trying to open" + mvSourceFiles[1]);
-
- mvSourceFiles.clear();
-
- while (fInput.good())
- {
- fInput.getline(buf, sizeof(buf));
- if (!buf[0])
- continue;
- mvSourceFiles.push_back(buf);
- }
-
- fInput.close();
-}
commit 872755ac336eb9ad33c6c98dd73deea2206acf71
Author: jan iversen <jani at documentfoundation.org>
Date: Mon Mar 14 14:44:16 2016 +0100
genLang update
convert l10nMem to lo standard
removed l10nMem_impl and added it direct to l10nMem
Change-Id: I7e226a8dab51fd52ecbc8da36068ebdfb5c1e17f
diff --git a/l10ntools/Executable_genlang.mk b/l10ntools/Executable_genlang.mk
index b6656c2..13789e0 100644
--- a/l10ntools/Executable_genlang.mk
+++ b/l10ntools/Executable_genlang.mk
@@ -29,7 +29,6 @@ $(eval $(call gb_Executable_add_exception_objects,genlang,\
l10ntools/source/gLang \
l10ntools/source/gL10nMem \
l10ntools/source/gL10nMemDB \
- l10ntools/source/gHandler \
l10ntools/source/gConvProp \
l10ntools/source/gConv \
l10ntools/source/gConvDB \
diff --git a/l10ntools/inc/gL10nMem.hxx b/l10ntools/inc/gL10nMem.hxx
index 1da50af..e7dcd70 100644
--- a/l10ntools/inc/gL10nMem.hxx
+++ b/l10ntools/inc/gL10nMem.hxx
@@ -23,16 +23,6 @@
-/*****************************************************************************
- ************************ G L 1 0 N M E M . H X X ************************
- *****************************************************************************
- * This is the class definition header of the l10n localizer program,
- * all global classes and their interrelations is defined here
- *****************************************************************************/
-
-
-
-/******************** C L A S S D E F I N I T I O N ********************/
class l10nMem_lang_entry
{
public:
@@ -45,7 +35,6 @@ class l10nMem_lang_entry
-/******************** C L A S S D E F I N I T I O N ********************/
class l10nMem_enus_entry
{
public:
@@ -67,7 +56,6 @@ class l10nMem_enus_entry
-/******************** C L A S S D E F I N I T I O N ********************/
class l10nMem_file_entry
{
public:
@@ -82,7 +70,6 @@ class l10nMem_file_entry
-/******************** C L A S S D E F I N I T I O N ********************/
class l10nMem_lang_list_entry
{
public:
@@ -95,7 +82,6 @@ class l10nMem_lang_list_entry
-/******************** C L A S S D E F I N I T I O N ********************/
class l10nMem_db
{
public:
@@ -149,69 +135,4 @@ class l10nMem_db
static void keyToUpper(std::string& sKey);
};
-
-
-
-
-/******************** C L A S S D E F I N I T I O N ********************/
-class l10nMem_impl
-{
- public:
- l10nMem_impl();
- ~l10nMem_impl();
-
- int showError (const std::string& sText, int iLineNo);
- int showWarning (const std::string& sText, int iLineNo);
- void showDebug (const std::string& sText, int iLineNo);
- void showVerbose (const std::string& sText, int iLineNo);
-
- void setModuleName (const std::string& sModuleName);
- const std::string& getModuleName (void);
- void loadEntryKey (int iLineNo,
- const std::string& sSourceFile,
- const std::string& sKey,
- const std::string& sMsgId,
- const std::string& sMsgStr,
- bool bIsFuzzy);
- void setSourceKey (int iLineNo,
- const std::string& sFilename,
- const std::string& sKey,
- const std::string& sMsgId,
- bool bMustExist);
-
- void saveTemplates (l10nMem& cMem,
- const std::string& sTargetDir,
- bool bKid,
- bool bForce);
- void saveLanguages (l10nMem& cMem,
- const std::string& sTargetDir,
- bool bForce);
- void dumpMem (const std::string& sTargetDir);
- void showNOconvert();
-
- void convertToInetString(std::string& sText);
- void convertFromInetString(std::string& sText);
-
- private:
- static bool mbVerbose;
- static bool mbDebug;
- static l10nMem_impl *mcImpl;
- l10nMem_db mcDb;
- std::string msModuleName;
- bool mbInError;
-
- 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);
-
- friend class l10nMem;
-};
#endif
diff --git a/l10ntools/inc/gLang.hxx b/l10ntools/inc/gLang.hxx
index ed35538..381d4d9 100644
--- a/l10ntools/inc/gLang.hxx
+++ b/l10ntools/inc/gLang.hxx
@@ -16,7 +16,6 @@
* 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>
@@ -24,107 +23,113 @@
-/*****************************************************************************
- *************************** G L A N G . H X X ***************************
- *****************************************************************************
- * This is the class definition header of the l10n localizer program,
- * all global classes and their interrelations is defined here
- *****************************************************************************/
-
-
-
-/******************* G L O B A L D E F I N I T I O N *******************/
-
-
-
-
-
-
-/******************** C L A S S D E F I N I T I O N ********************/
-class l10nMem_impl;
+class l10nMem_db;
class l10nMem
{
- public:
- l10nMem();
- ~l10nMem();
-
- typedef enum
- {
- ENTRY_DELETED,
- ENTRY_ADDED,
- ENTRY_CHANGED,
- ENTRY_NORMAL
- } ENTRY_STATE;
-
- static void setShowVerbose ();
- static void setShowDebug ();
-
- static int showError (const std::string& sText, int iLineNo = 0);
- static int showWarning (const std::string& sText, int iLineNo = 0);
- static void showDebug (const std::string& sText, int iLineNo = 0);
- static void showVerbose (const std::string& sText, int iLineNo = 0);
- bool isError ();
-
- 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 (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);
+ 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;
};
-/******************** C L A S S D E F I N I T I O N ********************/
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);
+ 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 ff16706..164b245 100644
--- a/l10ntools/source/gConv.cxx
+++ b/l10ntools/source/gConv.cxx
@@ -302,12 +302,13 @@ void convert_gen_impl::lexRead(char *sBuf, int *nResult, int nMax_size)
// space enough for the whole line ?
if (*nResult <= nMax_size)
{
- msSourceBuffer.copy(sBuf, *nResult, miSourceReadIndex);
+// msSourceBuffer.copy(sBuf, *nResult, miSourceReadIndex);
+ l10nMem::showDebug(sBuf);
miSourceReadIndex = -1;
}
else
{
- msSourceBuffer.copy(sBuf, nMax_size, miSourceReadIndex);
+// msSourceBuffer.copy(sBuf, nMax_size, miSourceReadIndex);
*nResult = nMax_size;
miSourceReadIndex += nMax_size;
}
diff --git a/l10ntools/source/gConvProp.cxx b/l10ntools/source/gConvProp.cxx
index 159325d..a506761 100644
--- a/l10ntools/source/gConvProp.cxx
+++ b/l10ntools/source/gConvProp.cxx
@@ -32,7 +32,7 @@
/********************** I M P L E M E N T A T I O N **********************/
convert_prop::convert_prop(l10nMem& crMemory) : convert_gen_impl(crMemory)
{
- throw l10nMem::showError(std::string("convert_prop not implemented"));
+// throw l10nMem::showError(std::string("convert_prop not implemented"));
}
diff --git a/l10ntools/source/gL10nMem.cxx b/l10ntools/source/gL10nMem.cxx
index 11b3793..44eed38 100644
--- a/l10ntools/source/gL10nMem.cxx
+++ b/l10ntools/source/gL10nMem.cxx
@@ -16,724 +16,571 @@
* 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 <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
-
-
-/*****************************************************************************
- ************************ G L 1 0 N M E M . C X X ************************
- *****************************************************************************
- * This is the interface to translation memory that links between the converts
- * 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 = nullptr;
-bool l10nMem_impl::mbVerbose = false;
-bool l10nMem_impl::mbDebug = false;
+l10nMem *myMem;
-/********************** I M P L E M E N T A T I O N **********************/
l10nMem::l10nMem()
+ : mbVerbose(false),
+ mbDebug(false),
+ mbInError(false)
{
- l10nMem_impl::mcImpl = new l10nMem_impl();
+ mcDb = new l10nMem_db;
+ myMem = this;
}
-/********************** I M P L E M E N T A T I O N **********************/
l10nMem::~l10nMem()
{
- delete l10nMem_impl::mcImpl;
+ delete mcDb;
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem::setShowVerbose()
+int l10nMem::showError(const std::string& sText, int iLineNo)
{
- l10nMem_impl::mbVerbose = true;
+ myMem->mbInError = true;
+ myMem->formatAndShowText("ERROR", iLineNo, sText);
+ return 1;
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem::setShowDebug()
+void l10nMem::showWarning(const std::string& sText, int iLineNo)
{
- l10nMem_impl::mbDebug = true;
+ myMem->formatAndShowText("WARNING", iLineNo, sText);
}
-/********************** I M P L E M E N T A T I O N **********************/
-int l10nMem::showError(const std::string& sText, int iLineNo)
- { return l10nMem_impl::mcImpl->showError(sText, iLineNo); }
-int l10nMem::showWarning(const std::string& sText, int iLineNo)
- { return l10nMem_impl::mcImpl->showWarning(sText, iLineNo); }
void l10nMem::showDebug(const std::string& sText, int iLineNo)
- { l10nMem_impl::mcImpl->showDebug(sText, iLineNo); }
-void l10nMem::showVerbose(const std::string& sText, int iLineNo)
- { l10nMem_impl::mcImpl->showVerbose(sText, iLineNo); }
-bool l10nMem::isError()
- { return l10nMem_impl::mcImpl->mbInError; }
-void l10nMem::setModuleName(const std::string& sM)
- { l10nMem_impl::mcImpl->setModuleName(sM); }
-const std::string& l10nMem::getModuleName ()
- { return l10nMem_impl::mcImpl->getModuleName(); }
-void l10nMem::setLanguage(const std::string& sL, bool bC)
- { l10nMem_impl::mcImpl->mcDb.setLanguage(sL, bC); }
-void l10nMem::setConvert(bool bC, bool bS)
- { l10nMem_impl::mcImpl->mcDb.setConvert(bC, bS); }
-void l10nMem::loadEntryKey(int iL, const std::string& sS, const std::string& sK, const std::string& sO, const std::string& sT, bool bI)
- { l10nMem_impl::mcImpl->loadEntryKey(iL, sS, sK, sO, sT, bI); }
-void l10nMem::setSourceKey(int iL, const std::string& sF, const std::string& sK, const std::string& sT, bool bM)
- { l10nMem_impl::mcImpl->setSourceKey(iL, sF, sK, sT, bM); }
-void l10nMem::saveTemplates(const std::string& sT, bool bK, bool bF)
- { l10nMem_impl::mcImpl->saveTemplates(*this, sT, bK, bF); }
-void l10nMem::saveLanguages(const std::string& sT, bool bF)
- { l10nMem_impl::mcImpl->saveLanguages(*this, sT, bF); }
-void l10nMem::showNOconvert ()
- { l10nMem_impl::mcImpl->showNOconvert(); }
-void l10nMem::convertToInetString(std::string& sT)
- { l10nMem_impl::mcImpl->convertToInetString(sT); }
-void l10nMem::convertFromInetString(std::string& sT)
- { l10nMem_impl::mcImpl->convertFromInetString(sT); }
-
-int l10nMem::prepareMerge()
- { return l10nMem_impl::mcImpl->mcDb.prepareMerge(); }
-void l10nMem::dumpMem(const std::string& sT)
- { l10nMem_impl::mcImpl->dumpMem(sT); }
-bool l10nMem::getMergeLang(std::string& sL, std::string& sT)
- { return l10nMem_impl::mcImpl->mcDb.getMergeLang(sL, sT); }
+{
+ if (myMem->mbDebug)
+ myMem->formatAndShowText("DEBUG", iLineNo, sText);
+}
-/********************** I M P L E M E N T A T I O N **********************/
-l10nMem_impl::l10nMem_impl()
- :
- mbInError(false)
+void l10nMem::showVerbose(const std::string& sText, int iLineNo)
{
+ if (myMem->mbVerbose)
+ myMem->formatAndShowText("INFO", iLineNo, sText);
}
-/********************** I M P L E M E N T A T I O N **********************/
-l10nMem_impl::~l10nMem_impl()
+bool l10nMem::isError()
{
+ return myMem->mbInError;
}
-/********************** I M P L E M E N T A T I O N **********************/
-int l10nMem_impl::showError(const std::string& sText, int iLineNo)
+void l10nMem::setModuleName(const std::string& sModuleName)
{
- mbInError = true;
- formatAndShowText("ERROR", iLineNo, sText);
- return 1;
+ msModuleName = sModuleName;
}
-/********************** I M P L E M E N T A T I O N **********************/
-int l10nMem_impl::showWarning(const std::string& sText, int iLineNo)
+const std::string& l10nMem::getModuleName()
{
- formatAndShowText("WARNING", iLineNo, sText);
- return 2;
+ return msModuleName;
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::showDebug(const std::string& sText, int iLineNo)
+void l10nMem::setLanguage(const std::string& sLanguage,
+ bool bCreate)
{
- if (mbDebug)
- formatAndShowText("DEBUG", iLineNo, sText);
+ mcDb->setLanguage(sLanguage, bCreate);
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::showVerbose(const std::string& sText, int iLineNo)
+void l10nMem::setConvert(bool bConvert,
+ bool bStrict)
{
- if (mbVerbose)
- formatAndShowText("INFO", iLineNo, sText);
+ mcDb->setConvert(bConvert, bStrict);
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::setModuleName(const std::string& sModuleName)
+void l10nMem::loadEntryKey(int iLineNo,
+ const std::string& sSourceFile,
+ const std::string& sKey,
+ const std::string& sMsgId,
+ const std::string& sMsgStr,
+ bool bIsFuzzy)
{
- msModuleName = sModuleName;
+ if (mcDb->mbConvertMode)
+ convEntryKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy);
+ else if (!mcDb->miCurLangInx)
+ mcDb->loadENUSkey(iLineNo, sSourceFile, sKey, sMsgId);
+ else
+ mcDb->loadLangKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy);
}
-/********************** I M P L E M E N T A T I O N **********************/
-const std::string& l10nMem_impl::getModuleName()
+void l10nMem::setSourceKey(int iLineNo,
+ const std::string& sSourceFile,
+ const std::string& sKey,
+ const std::string& sMsgId,
+ bool bMustExist)
{
- return msModuleName;
+ std::string newText(sMsgId);
+ int i;
+
+ // time to escape " and \ if contained in text or key
+ for (i = 0; (i = newText.find("\\", i)) != (int)std::string::npos;) {
+ ++i;
+ if (i < (int)newText.size() &&
+ (newText[i] == '\\' || newText[i] == '<' || newText[i] == '>' ||
+ newText[i] == 'n' || newText[i] == 't' || newText[i] == 'r' ||
+ newText[i] == '\''))
+ ++i;
+ else {
+ newText.insert(i - 1, "\\");
+ ++i;
+ }
+ }
+ for (i = 0; (i = newText.find("\"", i)) != (int)std::string::npos;) {
+ newText.insert(i, "\\");
+ i += 2;
+ }
+
+ // if key exist update state
+ if (mcDb->locateKey(iLineNo, sSourceFile, sKey, newText, false))
+ mcDb->mcENUSlist[mcDb->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);
+ }
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::loadEntryKey(int iLineNo,
- const std::string& sSourceFile,
- const std::string& sKey,
- const std::string& sMsgId,
- const std::string& sMsgStr,
- bool bIsFuzzy)
+void l10nMem::saveTemplates(const std::string& sTargetDir, bool bKid, bool bForce)
{
- if (mcDb.mbConvertMode)
- convEntryKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy);
- else if (!mcDb.miCurLangInx)
- mcDb.loadENUSkey(iLineNo, sSourceFile, sKey, sMsgId);
- else
- mcDb.loadLangKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy);
-}
+// int iEsize = mcDb->mcENUSlist.size();
+ std::string sFileName = msModuleName + ".pot";
+ // Dummy to satisfy compiler
+ if (bKid)
+ return;
+ showError(sTargetDir);
+ // and reorganize db if needed
+ mcDb->miCurFileInx = 0;
+ mcDb->reorganize(false);
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::setSourceKey(int iLineNo,
- const std::string& sSourceFile,
- const std::string& sKey,
- const std::string& sMsgId,
- bool bMustExist)
-{
- std::string newText(sMsgId);
- int i;
-
- // time to escape " and \ if contained in text or key
- for (i = 0; (i = newText.find("\\", i)) != (int)std::string::npos;)
- {
- ++i;
- if (i < (int)newText.size() &&
- (newText[i] == '\\' || newText[i] == '<' || newText[i] == '>' ||
- newText[i] == 'n' || newText[i] == 't' || newText[i] == 'r' ||
- newText[i] == '\''))
- ++i;
- else
- {
- newText.insert(i-1, "\\");
- ++i;
+ // no save if there has been errors
+ if (!needWrite(sFileName, bForce))
+ return;
+
+ //JIX save HANDLE KID
+
+ // Save en-US
+#if 0
+ convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName);
+
+ savePo.startSave("templates/", sFileName);
+ for (iE = 1; iE < iEsize; ++iE) {
+ l10nMem_enus_entry& cE = mcDb->mcENUSlist[iE];
+
+ // remove deleted entries
+ if (cE.meState == ENTRY_DELETED)
+ continue;
+
+ savePo.save(mcDb->mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, "", false);
}
- }
- for (i = 0; (i = newText.find("\"", i)) != (int)std::string::npos;)
- {
- newText.insert(i, "\\");
- i += 2;
- }
-
- // if key exist update state
- if (mcDb.locateKey(iLineNo, sSourceFile, sKey, newText, false))
- {
- mcDb.mcENUSlist[mcDb.miCurENUSinx].meState = l10nMem::ENTRY_NORMAL;
- }
- else
- {
- if (bMustExist)
- throw l10nMem::showError("key " + sKey + " does not exist");
- else
- // add key, if changed text, this is wrong but handled in reorganize
- mcDb.addKey(iLineNo, sSourceFile, sKey, newText, l10nMem::ENTRY_ADDED);
- }
+ savePo.endSave();
+#endif
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::saveTemplates(l10nMem& cMem, const std::string& sTargetDir, bool bKid, bool bForce)
+void l10nMem::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool bForce)
{
- int iE, iEsize = mcDb.mcENUSlist.size();
- std::string sFileName = msModuleName + ".pot";
+ int iE, iEsize = mcDb->mcENUSlist.size();
+ int iL, iLsize = mcDb->mcLangList.size();
+ std::string sFileName = msModuleName + ".po";
- // Dummy to satisfy compiler
- if (bKid)
- return;
- // and reorganize db if needed
- mcDb.miCurFileInx = 0;
- mcDb.reorganize(false);
+ // and reorganize db if needed
+ mcDb->miCurFileInx = 0;
+ mcDb->reorganize(true);
- // no save if there has been errors
- if(!needWrite(sFileName, bForce))
- return;
+ // no save if there has been errors
+ if (!needWrite(sFileName, bForce))
+ return;
- //JIX save HANDLE KID
+ // save all languages
+ for (iL = 1; iL < iLsize; ++iL) {
+ // only save language file if modified
+ if (!mcDb->mcLangList[iL].mbChanged)
+ continue;
- // Save en-US
- convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName);
+ mcDb->mcLangList[iL].mbChanged = false;
+ convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName);
- savePo.startSave("templates/", sFileName);
- for (iE = 1; iE < iEsize; ++iE)
- {
- l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE];
+ savePo.startSave(mcDb->mcLangList[iL].msName + "/", sFileName);
+ for (iE = 1; iE < iEsize; ++iE) {
+ l10nMem_enus_entry& cE = mcDb->mcENUSlist[iE];
+ l10nMem_lang_entry& cL = cE.mcLangText[iL];
+ bool bF = cL.mbFuzzy;
- // remove deleted entries
- if (cE.meState == l10nMem::ENTRY_DELETED)
- continue;
+ // remove deleted entries
+ if (cE.meState == ENTRY_DELETED)
+ continue;
- savePo.save(mcDb.mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, "", false);
- }
- savePo.endSave();
+ savePo.save(mcDb->mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, cL.msMsgStr, bF);
+ }
+ savePo.endSave();
+ }
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::saveLanguages(l10nMem& cMem, const std::string& sTargetDir, bool bForce)
+void l10nMem::showNOconvert()
{
- int iE, iEsize = mcDb.mcENUSlist.size();
- int iL, iLsize = mcDb.mcLangList.size();
- std::string sFileName = msModuleName + ".po";
+ int iE, iEsize = mcDb->mcENUSlist.size();
+ for (iE = 1; iE < iEsize; ++iE) {
+ l10nMem_enus_entry& cE = mcDb->mcENUSlist[iE];
- // and reorganize db if needed
- mcDb.miCurFileInx = 0;
- mcDb.reorganize(true);
+ if (cE.meState == ENTRY_DELETED)
+ showError("template key(" + cE.msKey + ") msgId(" + cE.msMsgId + ") not in pot file", 0);
+ }
+}
- // no save if there has been errors
- if(!needWrite(sFileName, bForce))
- return;
- // save all languages
- for (iL = 1; iL < iLsize; ++iL)
- {
- // only save language file if modified
- if (!mcDb.mcLangList[iL].mbChanged)
- continue;
- mcDb.mcLangList[iL].mbChanged = false;
- convert_gen savePo(cMem, sTargetDir, sTargetDir, sFileName);
+void l10nMem::convertToInetString(std::string& sText)
+{
+ static const char *replacingStr[] = { "&", "\'", ">", "<", "\"", nullptr };
+ static const int replacingLen[] = { 1, 1, 1, 1, 1, 0 };
+ static const char *newStr[] = { "&", "'", ">", "<", """, nullptr };
+ static const int newLen[] = { 5, 6, 4, 4, 6, 0 };
+ int i, pos;
+
+ for (i = 0; replacingStr[i]; i++) {
+ pos = 0;
+ while ((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) {
+ sText.replace(pos, replacingLen[i], newStr[i]);
+ pos += newLen[i];
+ }
+ }
+}
- savePo.startSave(mcDb.mcLangList[iL].msName + "/", sFileName);
- for (iE = 1; iE < iEsize; ++iE)
- {
- l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE];
- l10nMem_lang_entry& cL = cE.mcLangText[iL];
- bool bF = cL.mbFuzzy;
- // remove deleted entries
- if (cE.meState == l10nMem::ENTRY_DELETED)
- continue;
- savePo.save(mcDb.mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, cL.msMsgStr, bF);
+void l10nMem::convertFromInetString(std::string& sText)
+{
+ static const char *replacingStr[] = { "&", "'", ">", "<", """, nullptr };
+ static const int replacingLen[] = { 5, 6, 4, 4, 6, 0 };
+ static const char *newStr[] = { "&", "\'", ">", "<", "\"", nullptr };
+ static const int newLen[] = { 1, 1, 1, 1, 1, 0 };
+ int i, pos;
+
+ for (i = 0; replacingStr[i]; i++) {
+ pos = 0;
+ while ((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) {
+ sText.replace(pos, replacingLen[i], newStr[i]);
+ pos += newLen[i];
+ }
}
- savePo.endSave();
- }
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::showNOconvert ()
+int l10nMem::prepareMerge()
{
- int iE, iEsize = mcDb.mcENUSlist.size();
-
- for (iE = 1; iE < iEsize; ++iE)
- {
- l10nMem_enus_entry& cE = mcDb.mcENUSlist[iE];
-
- if (cE.meState == l10nMem::ENTRY_DELETED)
- {
- showError("template key(" + cE.msKey + ") msgId(" + cE.msMsgId + ") not in pot file", 0);
- }
- }
+ return mcDb->prepareMerge();
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::dumpMem(const std::string& sFileName)
+void l10nMem::dumpMem(const std::string& sFileName)
{
- // and reorganize db if needed
- mcDb.reorganize(false);
+ // and reorganize db if needed
+ mcDb->reorganize(false);
- // no save if there has been errors
- if(!needWrite(sFileName, true))
- return;
+ // no save if there has been errors
+ if (!needWrite(sFileName, true))
+ return;
- // JIX (dumpMem)
+ // JIX (dumpMem)
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText)
+bool l10nMem::getMergeLang(std::string& sL, std::string& sT)
{
- std::cout << sType;
- if (mcDb.miCurFileInx > 0)
- std::cout << " in " << mcDb.mcFileList[mcDb.miCurFileInx].msFileName;
- if (iLineNo)
- std::cout << "(" << iLineNo << ")";
- std::cout << ": " << sText << std::endl;
+ return mcDb->getMergeLang(sL, sT);
}
-/********************** I M P L E M E N T A T I O N **********************/
-bool l10nMem_impl::needWrite(const std::string sFileName, bool bForce)
+void l10nMem::formatAndShowText(const std::string& sType, int iLineNo, const std::string& sText)
{
- int iE, iEsize = mcDb.mcENUSlist.size();
- int iCntDeleted = 0, iCntChanged = 0, iCntAdded = 0;
-
- // no save if there has been errors
- if (mbInError)
- throw l10nMem::showError("Cannot save due to previous errors");
-
- // Check number of changes
- for (iE = 1; iE < iEsize; ++iE)
- {
- l10nMem_enus_entry& cur = mcDb.mcENUSlist[iE];
- if (cur.meState == l10nMem::ENTRY_ADDED)
- ++iCntAdded;
- if (cur.meState == l10nMem::ENTRY_CHANGED)
- {
- ++iCntChanged;
- if (mcDb.mbStrictMode)
- cur.meState = l10nMem::ENTRY_NORMAL;
- }
- if (cur.meState == l10nMem::ENTRY_DELETED)
- ++iCntDeleted;
- }
- if (!mcDb.mbConvertMode)
- iCntDeleted -= iCntChanged;
- if (!iCntAdded && !iCntChanged && !iCntDeleted)
- {
- std::cout << "genLang: No changes in " << sFileName;
- if (bForce)
- std::cout << ", -o switch used, so files are saved" << std::endl;
- else
- std::cout << " skipping \"save\"" << std::endl;
- return bForce;
- }
-
- std::cout << "genLang statistics: " << iCntDeleted << " deleted, "
- << iCntChanged << " changed, "
- << iCntAdded << " added entries in "
- << sFileName << std::endl;
- return true;
+ std::cout << sType;
+ if (mcDb->miCurFileInx > 0)
+ std::cout << " in " << mcDb->mcFileList[mcDb->miCurFileInx].msFileName;
+ if (iLineNo)
+ std::cout << "(" << iLineNo << ")";
+ std::cout << ": " << sText << std::endl;
}
-/********************** I M P L E M E N T A T I O N **********************/
-bool l10nMem_impl::convFilterWarning(const std::string& sSourceFile,
- const std::string& sKey,
- const std::string& sMsgId)
+bool l10nMem::needWrite(const std::string sFileName, bool bForce)
{
- // silent ignore deleted messages
- if (sMsgId == "-" || sMsgId == "")
+ int iE, iEsize = mcDb->mcENUSlist.size();
+ int iCntDeleted = 0, iCntChanged = 0, iCntAdded = 0;
+
+ // no save if there has been errors
+ if (mbInError)
+ throw showError("Cannot save due to previous errors");
+
+ // Check number of changes
+ for (iE = 1; iE < iEsize; ++iE) {
+ l10nMem_enus_entry& cur = mcDb->mcENUSlist[iE];
+ if (cur.meState == ENTRY_ADDED)
+ ++iCntAdded;
+ if (cur.meState == ENTRY_CHANGED) {
+ ++iCntChanged;
+ if (mcDb->mbStrictMode)
+ cur.meState = ENTRY_NORMAL;
+ }
+ if (cur.meState == ENTRY_DELETED)
+ ++iCntDeleted;
+ }
+ if (!mcDb->mbConvertMode)
+ iCntDeleted -= iCntChanged;
+ if (!iCntAdded && !iCntChanged && !iCntDeleted) {
+ std::cout << "genLang: No changes in " << sFileName;
+ if (bForce)
+ std::cout << ", -o switch used, so files are saved" << std::endl;
+ else
+ std::cout << " skipping \"save\"" << std::endl;
+ return bForce;
+ }
+
+ std::cout << "genLang statistics: " << iCntDeleted << " deleted, "
+ << iCntChanged << " changed, "
+ << iCntAdded << " added entries in "
+ << sFileName << std::endl;
return true;
+}
- if (msModuleName == "help_sbasic")
- {
- if (sSourceFile == "sbasic.tree")
- return true;
- }
- if (msModuleName == "help_scalc")
- {
- if (sSourceFile == "scalc.tree")
- return true;
- }
- if (msModuleName == "help_schart")
- {
- if (sSourceFile == "schart.tree")
- return true;
- }
- if (msModuleName == "help_shared")
- {
- if (sSourceFile == "shared.tree")
- return true;
- }
- if (msModuleName == "help_simpress")
- {
- if (sSourceFile == "simpress.tree")
- return true;
- }
- if (msModuleName == "help_smath")
- {
- if (sSourceFile == "smath.tree")
- return true;
- }
- if (msModuleName == "help_swriter")
- {
- if (sSourceFile == "swriter.tree")
- return true;
- }
- if (msModuleName == "officecfg")
- {
- if (sSourceFile == "registry/data/org/openoffice/Office/Writer.xcu" && sKey == "Writer.Insert.Caption.CaptionOrderNumberingFirst")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/Writer.xcu" && sKey == "Writer.Layout.Other.TabStop")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/UI/WriterCommands.xcu" && sKey == "WriterCommands.UserInterface.Commands..uno:FlipVertical.Label")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/UI/WriterCommands.xcu" && sKey == "WriterCommands.UserInterface.Commands..uno:FlipHorizontal.Label")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/Common.xcu" && sKey == "Common.View.Localisation.AutoMnemonic")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/Common.xcu" && sKey == "Common.View.Localisation.DialogScale")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/SlideTransitions.UIName")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/CustomAnimations.UIName")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/MasterPages.UIName")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/Layouts.UIName")
- return true;
- if (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" && sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/TableDesign.UIName")
- return true;
- }
- if (msModuleName == "readlicense_oo")
- {
- if (sSourceFile == "docs/readme/readme.xrm")
- {
- if (sKey == "BDB11")
- return true;
- if (sKey == "BDB2a")
- return true;
- if (sKey == "BDB3a")
- return true;
- if (sKey == "BDB4a")
- return true;
- }
- }
- if (msModuleName == "scp2")
- {
- if (sSourceFile == "source/binfilter/module_binfilter.ulf")
- return true;
- if (sSourceFile == "source/binfilter/registryitem_binfilter.ulf")
- return true;
- }
- if (msModuleName == "sdext")
- {
- if (sSourceFile == "source/minimizer/registry/data/org/openoffice/Office/Addons.xcu")
- return true;
- if (sSourceFile == "source/minimizer/registry/data/org/openoffice/Office/extension/SunPresentationMinimizer.xcu")
- return true;
- if (sSourceFile == "source/presenter/help/en-US/com.sun.PresenterScreen/presenter.xhp")
- return true;
- if (sSourceFile == "source/presenter/registry/data/org/openoffice/Office/extension/PresenterScreen.xcu")
- return true;
- }
- if (msModuleName == "sd")
- {
- if (sSourceFile == "source/ui/dlg/celltempl.src")
- return true;
- }
- if (msModuleName == "svx")
- {
- if (sSourceFile == "source/dialog/fontwork.src")
- {
- if (sKey == "RID_SVXSTR_FONTWORK_FORM1.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM2.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM3.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM4.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM5.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM6.String.Text")
+
+
+bool l10nMem::convFilterWarning(const std::string& sSourceFile,
+ const std::string& sKey,
+ const std::string& sMsgId)
+{
+ // silent ignore deleted messages
+ if (sMsgId == "-" || sMsgId == "")
return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM7.String.Text")
+ if (msModuleName == "help_sbasic" && sSourceFile == "sbasic.tree")
return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM8.String.Text")
+ if (msModuleName == "help_scalc" && sSourceFile == "scalc.tree")
return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM9.String.Text")
+ if (msModuleName == "help_schart" && sSourceFile == "schart.tree")
return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM10.String.Text")
+ if (msModuleName == "help_shared" && sSourceFile == "shared.tree")
return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM11.String.Text")
+ if (msModuleName == "help_simpress" && sSourceFile == "simpress.tree")
return true;
- if (sKey == "RID_SVXSTR_FONTWORK_FORM12.String.Text")
+ if (msModuleName == "help_smath" && sSourceFile == "smath.tree")
return true;
- if (sKey == "RID_SVXSTR_FONTWORK_UNDOCREATE.String.Text")
+ if (msModuleName == "help_swriter" && sSourceFile == "swriter.tree")
return true;
+ if (msModuleName == "officecfg") {
+ if ((sSourceFile == "registry/data/org/openoffice/Office/Writer.xcu" &&
+ sKey == "Writer.Insert.Caption.CaptionOrderNumberingFirst") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/Writer.xcu" &&
+ sKey == "Writer.Layout.Other.TabStop") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/UI/WriterCommands.xcu" &&
+ sKey == "WriterCommands.UserInterface.Commands..uno:FlipVertical.Label") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/UI/WriterCommands.xcu" &&
+ sKey == "WriterCommands.UserInterface.Commands..uno:FlipHorizontal.Label") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/Common.xcu" &&
+ sKey == "Common.View.Localisation.AutoMnemonic") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/Common.xcu" &&
+ sKey == "Common.View.Localisation.DialogScale") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" &&
+ sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/SlideTransitions.UIName") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" &&
+ sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/CustomAnimations.UIName") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" &&
+ sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/MasterPages.UIName") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" &&
+ sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/Layouts.UIName") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" &&
+ sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/TableDesign.UIName") ||
+ (sSourceFile == "registry/data/org/openoffice/Office/UI/ImpressWindowState.xcu" &&
+ sKey == "ImpressWindowState.UIElements.States.private:resource/toolpanel/DrawingFramework/TableDesign.UIName"))
+ return true;
}
- if (sSourceFile == "source/dialog/sdstring.src")
- {
- if (sKey == "RID_SVXSTR_LIGHTGREY.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_LIGHTBLUE.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_LIGHTGREEN.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_LIGHTCYAN.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_LIGHTRED.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_LIGHTMAGENTA.String.Text")
- return true;
- if (sKey == "RID_SVXSTR_COLOR_SUN.String.Text")
- return true;
+ if (msModuleName == "readlicense_oo") {
+ if (sSourceFile == "docs/readme/readme.xrm") {
+ if ((sKey == "BDB11" || sKey == "BDB2a" ||
+ sKey == "BDB3a" || sKey == "BDB4a"))
+ return true;
+ }
+ }
+ if (msModuleName == "scp2") {
+ if ((sSourceFile == "source/binfilter/module_binfilter.ulf" ||
+ sSourceFile == "source/binfilter/registryitem_binfilter.ulf"))
+ return true;
+ }
+ if (msModuleName == "sdext") {
+ if (sSourceFile == "source/minimizer/registry/data/org/openoffice/Office/Addons.xcu" ||
+ sSourceFile == "source/minimizer/registry/data/org/openoffice/Office/extension/SunPresentationMinimizer.xcu" ||
+ sSourceFile == "source/presenter/help/en-US/com.sun.PresenterScreen/presenter.xhp" ||
+ sSourceFile == "source/presenter/registry/data/org/openoffice/Office/extension/PresenterScreen.xcu")
+ return true;
+ }
+ if (msModuleName == "sd") {
+ if (sSourceFile == "source/ui/dlg/celltempl.src")
+ return true;
+ }
+ if (msModuleName == "svx") {
+ if (sSourceFile == "source/dialog/fontwork.src") {
+ if (sKey == "RID_SVXSTR_FONTWORK_FORM1.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM2.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM3.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM4.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM5.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM6.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM7.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM8.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM9.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM10.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM11.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_FORM12.String.Text" ||
+ sKey == "RID_SVXSTR_FONTWORK_UNDOCREATE.String.Text")
+ return true;
+ }
+ }
+ if (sSourceFile == "source/dialog/sdstring.src") {
+ if (sKey == "RID_SVXSTR_LIGHTGREY.String.Text" ||
+ sKey == "RID_SVXSTR_LIGHTBLUE.String.Text" ||
+ sKey == "RID_SVXSTR_LIGHTGREEN.String.Text" ||
+ sKey == "RID_SVXSTR_LIGHTCYAN.String.Text" ||
+ sKey == "RID_SVXSTR_LIGHTRED.String.Text" ||
+ sKey == "RID_SVXSTR_LIGHTMAGENTA.String.Text" ||
+ sKey == "RID_SVXSTR_COLOR_SUN.String.Text")
+ return true;
}
if (sSourceFile == "source/svdraw/svdstr.src" && sKey == "SIP_XA_FORMTXTSTDFORM.String.Text")
return true;
- }
- return false;
+ return false;
}
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::convEntryKey(int iLineNo,
- const std::string& sSourceFile,
- const std::string& sKey,
- const std::string& sMsgId,
- const std::string& sMsgStr,
- bool bIsFuzzy)
+void l10nMem::convEntryKey(int iLineNo,
+ const std::string& sSourceFile,
+ const std::string& sKey,
+ const std::string& sMsgId,
+ const std::string& sMsgStr,
+ bool bIsFuzzy)
{
- std::vector<int> ivEntryList;
- std::string curFileName;
- std::string curKeyUpper;
- int curFileIndex, curENUSindex, i, iSize;
-
-
- // filter out dummy messages, silently
- if (convFilterWarning(sSourceFile, sKey, sMsgId))
- return;
-
- // check for directory names in file name
- i = sSourceFile.rfind("/");
- if (i > 0)
- curFileName = sSourceFile.substr(i+1);
- else
- curFileName = sSourceFile;
-
- // Find all matching file names (old system does not have directory.
- // build list of potential entries
- iSize = mcDb.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;
-
- for (; j <= iEnd; ++j)
- ivEntryList.push_back(j);
- }
-
- // Did we find one or more files ?
- iSize = ivEntryList.size();
- if (!iSize)
- {
- showWarning("source file(" + curFileName + ") not in template file", iLineNo);
- return;
- }
-
- // Loop through all potential en-US entries
- for (curENUSindex = -1, i = 0; i < iSize; ++i)
- {
- l10nMem_enus_entry& curE = mcDb.mcENUSlist[ivEntryList[i]];
-
-
- // The entry must be unconverted if strict mode (comparing .pot files)
- if (mcDb.mbStrictMode && curE.meState != l10nMem::ENTRY_DELETED)
- continue;
-
- // msgId must match
- if (sMsgId == curE.msMsgId)
- {
- curENUSindex = ivEntryList[i];
- if (curE.meState == l10nMem::ENTRY_DELETED)
- curE.meState = l10nMem::ENTRY_NORMAL;
- break;
+ std::vector<int> ivEntryList;
+ std::string curFileName;
+ std::string curKeyUpper;
+ int curFileIndex, curENUSindex, i, iSize;
+
+
+ // filter out dummy messages, silently
+ if (convFilterWarning(sSourceFile, sKey, sMsgId))
+ return;
+
+ // check for directory names in file name
+ i = sSourceFile.rfind("/");
+ curFileName = (i > 0) ? sSourceFile.substr(i + 1) : sSourceFile;
+
+ // Find all matching file names (old system does not have directory.
+ // build list of potential entries
+ iSize = mcDb->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;
+
+ for (; j <= iEnd; ++j)
+ ivEntryList.push_back(j);
+ }
+
+ // Did we find one or more files ?
+ iSize = ivEntryList.size();
+ if (!iSize) {
+ showWarning("source file(" + curFileName + ") not in template file", iLineNo);
+ return;
}
- }
-
- // do we need to do advanced find
- if (curENUSindex == -1 || mcDb.mbStrictMode)
- {
- // make copy of key in upper case
- curKeyUpper = sKey;
- l10nMem_db::keyToUpper(curKeyUpper);
// Loop through all potential en-US entries
- for (i = 0; i < iSize; ++i)
- {
- l10nMem_enus_entry& curE = mcDb.mcENUSlist[ivEntryList[i]];
-
- // compare keys, but be aware of different length
- if (curKeyUpper.find(curE.msKey) != std::string::npos)
- {
- curENUSindex = ivEntryList[i];
- bIsFuzzy = true;
- break;
- }
+ for (curENUSindex = -1, i = 0; i < iSize; ++i) {
+ l10nMem_enus_entry& curE = mcDb->mcENUSlist[ivEntryList[i]];
+
+ // The entry must be unconverted if strict mode (comparing .pot files)
+ if (mcDb->mbStrictMode && curE.meState != ENTRY_DELETED)
+ continue;
+
+ // msgId must match
+ if (sMsgId == curE.msMsgId) {
+ curENUSindex = ivEntryList[i];
+ if (curE.meState == ENTRY_DELETED)
+ curE.meState = ENTRY_NORMAL;
+ break;
+ }
}
- }
-
- if (curENUSindex == -1)
- {
- showWarning("file(" + curFileName + ") key(" + sKey + ") msgId(" + sMsgId + ") not found in templates", iLineNo);
- return;
- }
-
- // update language text
- l10nMem_enus_entry& curE = mcDb.mcENUSlist[curENUSindex];
- l10nMem_lang_entry& curL = curE.mcLangText[mcDb.miCurLangInx];
-
- if (sMsgStr != curL.msMsgStr)
- {
- curL.msMsgStr = sMsgStr;
- curL.mbFuzzy = bIsFuzzy;
- curE.meState = l10nMem::ENTRY_CHANGED;
- mcDb.mcLangList[mcDb.miCurLangInx].mbChanged = true;
- }
-}
-
-
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::convertToInetString(std::string& sText)
-{
-static const char *replacingStr[] = {"&", "\'", ">", "<", "\"", nullptr };
-static const int replacingLen[] = {1, 1, 1, 1, 1, 0 };
-static const char *newStr[] = {"&", "'", ">", "<", """, nullptr };
-static const int newLen[] = {5, 6, 4, 4, 6, 0 };
- int i, pos;
-
- for (i = 0; replacingStr[i]; i++)
- {
- pos = 0;
- while((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) {
- sText.replace(pos, replacingLen[i], newStr[i]);
- pos += newLen[i];
+ // do we need to do advanced find
+ if (curENUSindex == -1 || mcDb->mbStrictMode) {
+ // make copy of key in upper case
+ curKeyUpper = sKey;
+ l10nMem_db::keyToUpper(curKeyUpper);
+
+ // Loop through all potential en-US entries
+ for (i = 0; i < iSize; ++i) {
+ l10nMem_enus_entry& curE = mcDb->mcENUSlist[ivEntryList[i]];
+
+ // compare keys, but be aware of different length
+ if (curKeyUpper.find(curE.msKey) != std::string::npos) {
+ curENUSindex = ivEntryList[i];
+ bIsFuzzy = true;
+ break;
+ }
+ }
}
- }
-}
+ if (curENUSindex == -1) {
+ showWarning("file(" + curFileName + ") key(" + sKey + ") msgId(" + sMsgId + ") not found in templates", iLineNo);
+ return;
+ }
+ // update language text
+ l10nMem_enus_entry& curE = mcDb->mcENUSlist[curENUSindex];
+ l10nMem_lang_entry& curL = curE.mcLangText[mcDb->miCurLangInx];
-/********************** I M P L E M E N T A T I O N **********************/
-void l10nMem_impl::convertFromInetString(std::string& sText)
-{
-static const char *replacingStr[] = {"&", "'", ">", "<", """, nullptr };
-static const int replacingLen[] = {5, 6, 4, 4, 6, 0 };
-static const char *newStr[] = {"&", "\'", ">", "<", "\"", nullptr };
-static const int newLen[] = {1, 1, 1, 1, 1, 0 };
- int i, pos;
-
- for (i = 0; replacingStr[i]; i++)
- {
- pos = 0;
- while((pos = sText.find(replacingStr[i], pos)) != (int)std::string::npos) {
- sText.replace(pos, replacingLen[i], newStr[i]);
- pos += newLen[i];
+ if (sMsgStr != curL.msMsgStr) {
+ curL.msMsgStr = sMsgStr;
+ curL.mbFuzzy = bIsFuzzy;
+ curE.meState = ENTRY_CHANGED;
+ mcDb->mcLangList[mcDb->miCurLangInx].mbChanged = true;
}
- }
}
diff --git a/l10ntools/source/gL10nMemDB.cxx b/l10ntools/source/gL10nMemDB.cxx
index 2055b0e..5133424 100644
--- a/l10ntools/source/gL10nMemDB.cxx
+++ b/l10ntools/source/gL10nMemDB.cxx
@@ -23,16 +23,6 @@
#include <sstream>
-/*****************************************************************************
- ********************** G L 1 0 N M E M D B . 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 *******************/
diff --git a/l10ntools/source/gLang.cxx b/l10ntools/source/gLang.cxx
index 696d861..da07828 100644
--- a/l10ntools/source/gLang.cxx
+++ b/l10ntools/source/gLang.cxx
@@ -34,8 +34,6 @@ class handler
private:
bool mbForceSave;
- bool mbDebug;
- bool mbVerbose;
bool mbSave;
enum {DO_CONVERT, DO_EXTRACT, DO_MERGE_KID, DO_MERGE} meWorkMode;
std::string msTargetDir;
@@ -172,7 +170,7 @@ void handler::checkCommandLine(int argc, char *argv[])
// Set default
- mbForceSave = mbDebug = mbVerbose = mbSave = false;
+ mbForceSave = mbSave = false;
// check for fixed parameter: genLang <cmd>
if (argc < 2)
@@ -191,7 +189,7 @@ void handler::checkCommandLine(int argc, char *argv[])
sWorkText = argv[i];
if (sWorkText == "-d") {
// show debug information
- mbDebug = true;
+ mcMemory.mbDebug = true;
}
else if (sWorkText == "-k") {
// generate key identifier version
@@ -201,7 +199,7 @@ void handler::checkCommandLine(int argc, char *argv[])
}
else if (sWorkText == "-v") {
// show progress information
- mbVerbose = true;
+ mcMemory.mbVerbose = true;
}
else if (sWorkText == "-s") {
// forced save
@@ -325,7 +323,7 @@ void handler::loadL10MEM(bool onlyTemplates)
// load texts from en-US po file (master)
// tell system
- l10nMem::showDebug("genLang loading master text from file " + sLoad);
+ mcMemory.showDebug("genLang loading master text from file " + sLoad);
// and load file
mcMemory.setLanguage("", true);
@@ -343,7 +341,7 @@ void handler::loadL10MEM(bool onlyTemplates)
mcMemory.setLanguage(*siLang, true);
// tell system
- l10nMem::showDebug("genLang loading text from language file " + sLoad);
+ mcMemory.showDebug("genLang loading text from language file " + sLoad);
convert_gen(mcMemory, sLoad, msTargetDir, "").execute(false, false);
}
@@ -356,7 +354,6 @@ void handler::runConvert()
std::vector<std::string>::iterator siSource;
std::vector<std::string>::iterator siLang;
- throw("NOT CONTROLLED");
// convert
mcMemory.setConvert(true, false);
@@ -365,7 +362,7 @@ void handler::runConvert()
for (siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource)
{
// tell system
- l10nMem::showDebug("genLang compare template " + *siSource);
+ mcMemory.showDebug("genLang compare template " + *siSource);
// get converter and extract files
convert_gen convertObj(mcMemory, "./", msTargetDir, *siSource);
@@ -381,7 +378,7 @@ void handler::runConvert()
mcMemory.setLanguage(*siLang, false);
// tell system
- l10nMem::showDebug("genLang convert text from file " +
+ mcMemory.showDebug("genLang convert text from file " +
sFilePath + *siSource + " language " + *siLang);
// get converter and extract files
@@ -403,13 +400,12 @@ void handler::runExtract()
// no convert
mcMemory.setConvert(false, false);
- throw("NOT CONTROLLED");
// loop through all source files, and extract messages from each file
for (siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource)
{
// tell system
- l10nMem::showDebug("genLang extracting text from file " + *siSource);
+ mcMemory.showDebug("genLang extracting text from file " + *siSource);
// get converter and extract file
convert_gen convertObj(mcMemory, "", msTargetDir, *siSource);
@@ -428,13 +424,12 @@ void handler::runMerge(bool bKid)
// no convert
mcMemory.setConvert(false, false);
- throw("NOT CONTROLLED");
// loop through all source files, and extract messages from each file
for (siSource = mvSourceFiles.begin(); siSource != mvSourceFiles.end(); ++siSource)
{
// tell system
- l10nMem::showDebug("genLang merging translated text to file " + *siSource);
+ mcMemory.showDebug("genLang merging translated text to file " + *siSource);
// get converter and extract file
convert_gen convertObj(mcMemory, "", msTargetDir, *siSource);
More information about the Libreoffice-commits
mailing list