Kaydet (Commit) fe150b57 authored tarafından jan iversen's avatar jan iversen

genlang, generating .pot files for .xrm files

Solved new pot directory structure

only tested .xrm files, but should be able to extract
all .pot files.

The LO tools generated the KID as part of the msg, this
is not implemented.

msgctxt is used as comments, this requires a slight change
of the lex programs.

Change-Id: Id9aadbd419fb44b73b633410f7dddd90d310ee8d
üst 40a218ba
......@@ -36,10 +36,10 @@ class convert_gen
const std::string& sSourceFile);
// do extract/merge
bool execute(const bool bMerge, const bool bKid);
bool execute(const bool bMerge);
// all converters MUST implement this function
virtual void execute() = 0;
virtual void doExecute() = 0;
// utility functions for converters
void lexRead(char *sBuf, int *nResult, int nMax_size);
......@@ -62,9 +62,9 @@ class convert_gen
// utility functions for converters
void writeSourceFile(const std::string& line);
static bool checkAccess(std::string& sFile);
static bool createDir(std::string& sDir, std::string& sFile);
bool createDir(const std::string& sDir, const std::string& sFile);
private:
std::ofstream mcOutputFile;
bool checkAccess(std::string& sFile);
};
#endif
......@@ -42,7 +42,8 @@ class convert_po : public convert_gen
void handleNL ();
// Used to save .pot files
void startSave(const std::string& sLanguage,
void startSave(const std::string& sName,
const std::string& sTargetDir,
const std::string& sFile);
void save(const std::string& sFileName,
const std::string& sKey,
......@@ -58,6 +59,6 @@ class convert_po : public convert_gen
bool mbFuzzy;
std::filebuf outBuffer;
void execute() override;
void doExecute() override;
};
#endif
......@@ -29,6 +29,6 @@ class convert_prop : public convert_gen
~convert_prop();
private:
void execute() override;
void doExecute() override;
};
#endif
......@@ -58,7 +58,7 @@ class convert_src : public convert_gen
bool mbInListItem;
int miListCount;
int miMacroLevel;
void execute() override;
void doExecute() override;
void trim(std::string& sText);
void buildKey(std::string& sKey);
void insertLanguagePart(std::string& sKey, std::string& sTextType);
......
......@@ -57,6 +57,6 @@ class convert_tree : public convert_gen
STATE_VAL meStateVal;
int miCntLanguages;
void execute() override;
void doExecute() override;
};
#endif
......@@ -35,7 +35,7 @@ class convert_ulf : public convert_gen
private:
std::string msKey;
void execute() override;
void doExecute() override;
void handleLines();
};
#endif
......@@ -37,6 +37,6 @@ class convert_xcs : public convert_gen
std::string msKey;
bool mbCollectingData;
void execute() override;
void doExecute() override;
};
#endif
......@@ -45,6 +45,6 @@ class convert_xcu : public convert_gen
int miLevel;
bool mbNoTranslate;
void execute() override;
void doExecute() override;
};
#endif
......@@ -60,6 +60,6 @@ class convert_xhp : public convert_gen
std::string *msLangText;
std::ofstream *mcOutputFiles;
int miCntLanguages;
void execute() override;
void doExecute() override;
};
#endif
......@@ -41,6 +41,6 @@ class convert_xrm : public convert_gen
bool mbIsLang;
std::string msTag;
void execute() override;
void doExecute() override;
};
#endif
......@@ -18,6 +18,7 @@
*/
#include <string>
#include <vector>
using namespace std;
#include "gL10nMem.hxx"
#include "gConv.hxx"
......@@ -60,17 +61,17 @@ convert_gen::~convert_gen()
convert_gen& convert_gen::createInstance(l10nMem& cMemory,
const std::string& sSourceDir,
const std::string& sTargetDir,
const std::string& sSourceFile)
const string& sSourceDir,
const string& sTargetDir,
const string& sSourceFile)
{
// did the user give a .xxx with the source file ?
int nInx = sSourceFile.rfind(".");
if (nInx == (int)std::string::npos)
if (nInx == (int)string::npos)
throw l10nMem::showError("source file: "+sSourceFile+" missing extension");
// find correct conversion class and create correct object
std::string sExtension = sSourceFile.substr(nInx+1);
string sExtension = sSourceFile.substr(nInx+1);
convert_gen *x;
if (sExtension == "hrc") x = new convert_src(cMemory);
else if (sExtension == "src") x = new convert_src(cMemory);
......@@ -93,40 +94,37 @@ convert_gen& convert_gen::createInstance(l10nMem& cMemory,
bool convert_gen::execute(const bool bMerge, const bool bKid)
bool convert_gen::execute(const bool bMerge)
{
mbMergeMode = bMerge;
if (bKid)
throw l10nMem::showError("not implemented");
// and load file
if (!prepareFile())
return false;
// and execute conversion
execute();
doExecute();
return true;
}
bool convert_gen::checkAccess(std::string& sFile)
bool convert_gen::checkAccess(string& sFile)
{
return (OS_ACCESS(sFile.c_str(), 0) == 0);
}
bool convert_gen::createDir(std::string& sDir, std::string& sFile)
bool convert_gen::createDir(const string& sDir, const string& sFile)
{
std::string sNewDir(sDir);
string sNewDir(sDir);
int newPos, oldPos;
for (oldPos = 0;; oldPos = newPos +1) {
newPos = sFile.find_first_of("/\\", oldPos);
if (newPos == (int)std::string::npos)
if (newPos == (int)string::npos)
break;
sNewDir += sFile.substr(oldPos, newPos-oldPos) + "/";
......@@ -142,7 +140,7 @@ bool convert_gen::createDir(std::string& sDir, std::string& sFile)
bool convert_gen::prepareFile()
{
std::ifstream inputFile(msSourcePath.c_str(), std::ios::binary);
ifstream inputFile(msSourcePath.c_str(), ios::binary);
if (!inputFile.is_open()) {
......@@ -156,11 +154,11 @@ bool convert_gen::prepareFile()
// get length of file:
miSourceReadIndex = 0;
inputFile.seekg (0, std::ios::end);
inputFile.seekg (0, ios::end);
msSourceBuffer.resize((unsigned int)inputFile.tellg());
inputFile.seekg (0, std::ios::beg);
inputFile.seekg (0, ios::beg);
// get size, prepare std::string and read whole file
// get size, prepare string and read whole file
inputFile.read(const_cast<char *>(msSourceBuffer.c_str()), msSourceBuffer.size());
if ((unsigned int)inputFile.gcount() != msSourceBuffer.size())
throw l10nMem::showError("cannot read whole file");
......@@ -172,12 +170,12 @@ bool convert_gen::prepareFile()
mcOutputFile.close();
// open output file
mcOutputFile.open((msTargetPath+msSourceFile).c_str(), std::ios::binary);
mcOutputFile.open((msTargetPath+msSourceFile).c_str(), ios::binary);
if (mcOutputFile.is_open())
return true;
if (convert_gen::createDir(msTargetPath, msSourceFile)) {
mcOutputFile.open((msTargetPath+msSourceFile).c_str(), std::ios::binary);
mcOutputFile.open((msTargetPath+msSourceFile).c_str(), ios::binary);
if (mcOutputFile.is_open())
return true;
}
......@@ -216,7 +214,7 @@ void convert_gen::lexRead(char *sBuf, int *nResult, int nMax_size)
void convert_gen::writeSourceFile(const std::string& line)
void convert_gen::writeSourceFile(const string& line)
{
if (!line.size())
return;
......@@ -227,7 +225,7 @@ void convert_gen::writeSourceFile(const std::string& line)
std::string& convert_gen::copySource(char const *yyText, bool bDoClear)
string& convert_gen::copySource(char const *yyText, bool bDoClear)
{
int nL;
......
......@@ -18,6 +18,7 @@
*/
#include <string>
#include <vector>
using namespace std;
#include "gL10nMem.hxx"
#include "gConvPo.hxx"
......@@ -47,7 +48,7 @@ convert_po::~convert_po()
void convert_po::startLook()
{
std::string sFileName, sNewKey;
string sFileName, sNewKey;
int i;
......@@ -132,7 +133,7 @@ void convert_po::handleNL()
extern int polex(void);
void convert_po::execute()
void convert_po::doExecute()
{
if (mbMergeMode)
throw l10nMem::showError("Merge not implemented");
......@@ -143,71 +144,67 @@ void convert_po::execute()
void convert_po::startSave(const std::string& sLanguage,
const std::string& sFile)
void convert_po::startSave(const string& sName,
const string& sTargetDir,
const string& sFile)
{
std::string sFilePath = msTargetPath + sLanguage + sFile;
outBuffer.open(sFilePath.c_str(), std::ios::out);
string sFilePath = sTargetDir + "/" + sFile;
// create directories as needed
createDir(string(""), sFilePath);
outBuffer.open(sFilePath.c_str(), ios::out + ios::binary);
if (!outBuffer.is_open())
throw l10nMem::showError("Cannot open " + sFilePath + " for writing");
l10nMem::showDebug("writing file (" + sFilePath + ")");
std::ostream outFile(&outBuffer);
ostream outFile(&outBuffer);
// Set license header
outFile << "#*************************************************************" << std::endl
<< "#*" << std::endl
<< "#* This file is part of the LibreOffice project. " << std::endl
<< "#*" << std::endl
<< "#* This Source Code Form is subject to the terms of the " << std::endl
<< "#* Mozilla Public License, v. 2.0. If a copy of the MPL was " << std::endl
<< "#* not distributed with this file, You can obtain one at " << std::endl
<< "#* http://mozilla.org/MPL/2.0/." << std::endl
<< "#*" << std::endl
<< "#* This file incorporates work covered by the following " << std::endl
<< "#* license notice :" << std::endl
<< "#*" << std::endl
<< "#* Licensed to the Apache Software Foundation (ASF) under one " << std::endl
<< "#* or more contributor license agreements. See the NOTICE file" << std::endl
<< "#* distributed with this work for additional information " << std::endl
<< "#* regarding copyright ownership. The ASF licenses this file " << std::endl
<< "#* to you under the Apache License, Version 2.0 " << std::endl
<< "#* (the \"License\"); you may not use this file except in " << std::endl
<< "#* compliance with the License.You may obtain a copy of the " << std::endl
<< "#* License at http ://www.apache.org/licenses/LICENSE-2.0 . " << std::endl
<< "#*" << std::endl
<< "#************************************************************" << std::endl
<< "msgid \"\"" << std::endl
<< "msgstr \"\"" << std::endl
<< "\"Project-Id-Version: AOO-4-xx\\n\"" << std::endl
<< "\"POT-Creation-Date: \\n\"" << std::endl
<< "\"PO-Revision-Date: \\n\"" << std::endl
<< "\"Last-Translator: genLang (build process)\\n\"" << std::endl
<< "\"Language-Team: \\n\"" << std::endl
<< "\"MIME-Version: 1.0\\n\"" << std::endl
<< "\"Content-Type: text/plain; charset=UTF-8\\n\"" << std::endl
<< "\"Content-Transfer-Encoding: 8bit\\n\"" << std::endl
<< "\"X-Generator: genLang\\n\"" << std::endl
<< std::endl;
outFile << "#. extracted from " << sName << endl
<< "msgid \"\"" << endl
<< "msgstr \"\"" << endl
<< "\"Project-Id-Version: PACKAGE VERSION\\n\"" << endl
<< "\"Report-Msgid-Bugs-To: "
<< "https://bugs.libreoffice.org/enter_bug.cgi?"
<< "product=LibreOffice&bug_status=UNCONFIRMED"
<< "&component=UI\\n\"" << endl
<< "\"POT-Creation-Date: \\n\"" << endl
<< "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"" << endl
<< "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"" << endl
<< "\"Language-Team: LANGUAGE <LL@li.org>\\n\"" << endl
<< "\"MIME-Version: 1.0\\n\"" << endl
<< "\"Content-Type: text/plain; charset=UTF-8\\n\"" << endl
<< "\"Content-Transfer-Encoding: 8bit\\n\"" << endl
<< "\"X-Generator: LibreOffice\\n\"" << endl
<< "\"X-Accelerator-Marker: ~\\n\"" << endl;
}
void convert_po::save(const std::string& sFileName,
const std::string& sKey,
const std::string& sENUStext,
const std::string& sText,
void convert_po::save(const string& sFileName,
const string& sKey,
const string& sENUStext,
const string& sText,
bool bFuzzy)
{
std::ostream outFile(&outBuffer);
outFile << std::endl << "#: " << sFileName << "#" << sKey << std::endl;
string sName;
ostream outFile(&outBuffer);
int newPos;
// isolate filename
newPos = sFileName.find_last_of("/\\", sFileName.length());
sName = sFileName.substr(newPos + 1, sFileName.length());
outFile << "#. xxxxx" << endl
<< "#: " << sName << endl
<< "msgctxt \"\"" << endl
<< "\"" << sName << "\\n\"" << endl;
if (bFuzzy)
outFile << "#, fuzzy" << std::endl;
outFile << "msgid \"" << sENUStext << "\"" << std::endl
<< "msgstr \"" << sText << "\"" << std::endl;
outFile << "#, fuzzy" << endl;
outFile << "msgid \"" << sENUStext << "\"" << endl
<< "msgstr \"" << sText << "\"" << endl;
}
......
......@@ -37,7 +37,7 @@ convert_prop::~convert_prop()
void convert_prop::execute()
void convert_prop::doExecute()
{
throw l10nMem::showError(std::string("convert_prop::execute not implemented"));
}
......@@ -44,7 +44,7 @@ convert_src::~convert_src()
extern int srclex(void);
void convert_src::execute()
void convert_src::doExecute()
{
srclex();
}
......
......@@ -49,7 +49,7 @@ convert_tree::~convert_tree()
extern int treelex(void);
void convert_tree::execute()
void convert_tree::doExecute()
{
std::string sLang;
std::string sFile, sFile2;
......
......@@ -29,7 +29,7 @@ convert_ulf::~convert_ulf() {}
extern int ulflex(void);
void convert_ulf::execute()
void convert_ulf::doExecute()
{
ulflex();
}
......
......@@ -39,7 +39,7 @@ convert_xcs::~convert_xcs()
extern int xcslex(void);
void convert_xcs::execute()
void convert_xcs::doExecute()
{
if (mbMergeMode)
throw l10nMem::showError("Merge not implemented");
......
......@@ -38,7 +38,7 @@ convert_xcu::~convert_xcu()
extern int xculex(void);
void convert_xcu::execute()
void convert_xcu::doExecute()
{
xculex();
}
......
......@@ -48,7 +48,7 @@ convert_xhp::~convert_xhp()
extern int xhplex(void);
void convert_xhp::execute()
void convert_xhp::doExecute()
{
std::string sLang;
std::string sFile, sFile2;
......
......@@ -41,7 +41,7 @@ convert_xrm::~convert_xrm()
extern int xrmlex(void);
void convert_xrm::execute()
void convert_xrm::doExecute()
{
xrmlex();
......
This diff is collapsed.
......@@ -39,7 +39,7 @@ class handler
private:
bool mbForceSave;
enum {DO_CONVERT, DO_EXTRACT, DO_MERGE_KID, DO_MERGE} meWorkMode;
enum {DO_CONVERT, DO_EXTRACT, DO_MERGE} meWorkMode;
string msTargetDir;
string msPoDir;
vector<string> mvSourceFiles;
......@@ -49,7 +49,7 @@ class handler
void loadL10MEM(bool onlyTemplates);
void runConvert();
void runExtract();
void runMerge(bool bKid);
void runMerge();
};
......@@ -78,7 +78,6 @@ void handler::showUsage(string sErr)
" merge merge po files back to sources\n"
" <options> is a combination of\n"
" -d show debug information\n"
" -k generate key identifier version\n"
" -s save unconditionally\n"
" -v show progress information\n"
"\n"
......@@ -122,7 +121,7 @@ void handler::showManual()
"\n\n";
cout <<
" genLang merge [-v] [-d] [-s] [-k]\n"
" genLang merge [-v] [-d] [-s]\n"
" --files <files>\n"
" --target <directory>\n"
" --po <directory>\n"
......@@ -177,13 +176,6 @@ void handler::checkCommandLine(int argc, char *argv[])
if (sWorkText == "-d") {
// show debug information
mcMemory.setDebug(true);
mcMemory.setVerbose(true);
}
else if (sWorkText == "-k") {
// generate key identifier version
if (meWorkMode != DO_MERGE)
throw "-k requires \"merge\"";
meWorkMode = DO_MERGE_KID;
}
else if (sWorkText == "-v") {
// show progress information
......@@ -222,7 +214,6 @@ void handler::checkCommandLine(int argc, char *argv[])
case DO_EXTRACT:
bSourceFiles = bTargetDir = true;
break;
case DO_MERGE_KID:
case DO_MERGE:
bPoDir = bTargetDir = true;
break;
......@@ -241,10 +232,9 @@ void handler::run()
// use workMode to start correct control part
switch (meWorkMode)
{
case DO_EXTRACT: runExtract(); break;
case DO_MERGE: runMerge(false); break;
case DO_MERGE_KID: runMerge(true); break;
case DO_CONVERT: runConvert(); break;
case DO_EXTRACT: runExtract(); break;
case DO_MERGE: runMerge(); break;
case DO_CONVERT: runConvert(); break;
}
}
......@@ -264,7 +254,7 @@ void handler::loadL10MEM(bool onlyTemplates)
// and load file
mcMemory.setLanguage("", true);
convert_gen::createInstance(mcMemory, sLoad, msTargetDir, "").execute(false, false);
convert_gen::createInstance(mcMemory, sLoad, msTargetDir, "").execute(false);
if (onlyTemplates)
return;
......@@ -302,7 +292,7 @@ void handler::runConvert()
// get converter and extract files
convert_gen& convertObj = convert_gen::createInstance(mcMemory, "./", msTargetDir, *siSource);
convertObj.execute(false, false);
convertObj.execute(false);
mcMemory.showNOconvert();
......@@ -331,6 +321,7 @@ void handler::runConvert()
void handler::runExtract()
{
vector<string>::iterator siSource;
int newPos;
// no convert
mcMemory.setConvert(false, false);
......@@ -340,9 +331,13 @@ void handler::runExtract()
// tell system
l10nMem::showDebug("genLang extracting text from file " + *siSource);
// set module name
newPos = (*siSource).find_last_of("/\\", (*siSource).length());
mcMemory.setModuleName((*siSource).substr(0, newPos));
// get converter and extract file
convert_gen& convertObj = convert_gen::createInstance(mcMemory, "", msTargetDir, *siSource);
convertObj.execute(false, false);
convertObj.execute(false);
}
// and generate language file
......@@ -351,7 +346,7 @@ void handler::runExtract()
void handler::runMerge(bool bKid)
void handler::runMerge()
{
vector<string>::iterator siSource;
......@@ -365,7 +360,7 @@ void handler::runMerge(bool bKid)
// get converter and extract file
convert_gen& convertObj = convert_gen::createInstance(mcMemory, "", msTargetDir, *siSource);
convertObj.execute(true, bKid);
convertObj.execute(true);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment