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

genlang, PO files contain both comment and resource extra

the .ulf ==> .pot keep the x-comment, therefore the memory
db is expanded with sResource and sComment.

The memory db API is changed to add the 2 new fields, which
causes a change in all callers.

Change-Id: I38527c8d2db9d56ecf9ae42550ed5420371b658e
üst 3ec0b7ed
......@@ -31,7 +31,7 @@ class convert_po : public convert_gen
convert_po(l10nMem& crMemory);
~convert_po();
~convert_po() {};
void startLook ();
void setValue (char *syyText, int iLineCnt);
......@@ -49,6 +49,7 @@ class convert_po : public convert_gen
const string& sKey,
const string& sENUStext,
const string& sText,
const string& sComment,
const string& sResource,
bool bFuzzy);
void endSave();
......
......@@ -25,8 +25,8 @@
class convert_prop : public convert_gen
{
public:
convert_prop(l10nMem& crMemory);
~convert_prop();
convert_prop(l10nMem& crMemory) : convert_gen(crMemory) {};
~convert_prop() {};
private:
void doExecute() override;
......
......@@ -28,7 +28,7 @@ class convert_src : public convert_gen
bool mbExpectValue;
convert_src(l10nMem& crMemory);
~convert_src();
~convert_src() {};
void setValue (char *syyText, char *sbuildValue);
void setLang (char *syyText, bool bEnUs);
......
......@@ -42,20 +42,21 @@ class convert_tree : public convert_gen
convert_tree(l10nMem& crMemory);
~convert_tree();
void setString (char *yytext);
void setState (char *yytext, STATE_TAG eNewStateTag, STATE_VAL eNewStateVAL, char *sModule);
void setValue (char *yytext);
string& copySourceSpecial (char *yytext, int iType);
void writeSourceFile (string& sText, int inx);
void setString(char *yytext);
void setState(char *yytext, STATE_TAG eNewStateTag, STATE_VAL eNewStateVAL, char *sModule);
void setValue(char *yytext);
void writeSourceFile(string& sText, int inx);
string& copySourceSpecial(char *yytext, int iType);
private:
string msLine;
string msId;
string msAppl;
string msLine;
string msModule;
string msId;
string msAppl;
ofstream *mcOutputFiles;
STATE_TAG meStateTag;
STATE_VAL meStateVal;
int miCntLanguages;
STATE_TAG meStateTag;
STATE_VAL meStateVal;
int miCntLanguages;
void doExecute() override;
};
......
......@@ -25,8 +25,8 @@
class convert_ulf : public convert_gen
{
public:
convert_ulf(l10nMem& crMemory);
~convert_ulf();
convert_ulf(l10nMem& crMemory) : convert_gen(crMemory) {};
~convert_ulf() {};
void setKey(char *syyText);
void setText(char *syyText, bool bIsEnUs);
......
......@@ -26,7 +26,7 @@ class convert_xcs : public convert_gen
{
public:
convert_xcs(l10nMem& crMemory);
~convert_xcs();
~convert_xcs() {};
void setKey(char *syyText);
void unsetKey(char *syyText);
......
......@@ -29,7 +29,7 @@ class convert_xcu : public convert_gen
bool mbNoCollectingData;
convert_xcu(l10nMem& crMemory);
~convert_xcu();
~convert_xcu() {};
void pushKey(char *syyText);
void popKey(char *syyText);
......
......@@ -27,7 +27,7 @@ class convert_xrm : public convert_gen
public:
bool mbNoCollectingData;
convert_xrm(l10nMem& crMemory);
~convert_xrm();
~convert_xrm() {};
void setId(char *yytext);
void setLang(char *yytext);
......
......@@ -35,41 +35,42 @@ class l10nMem
ENTRY_NORMAL
} ENTRY_STATE;
static int showError(const string& sText, int iLineNo = 0);
static int showError (const string& sText, int iLineNo = 0);
static void showWarning(const string& sText, int iLineNo = 0);
static void showDebug(const string& sText, int iLineNo = 0);
static void showDebug (const string& sText, int iLineNo = 0);
static void showVerbose(const string& sText, int iLineNo = 0);
static void keyToUpper(string& sKey);
static void keyToUpper (string& sKey);
void setModuleName(const string& sModuleName);
const string& getModuleName(void);
void setResourceName(const string& sResourceName);
const string& getResourceName(void);
void setLanguage(const string& sLanguage,
bool bCreate);
void setConvert(bool bConvert,
bool bStrict);
bool bCreate);
void setConvert(bool bConvert,
bool bStrict);
void setVerbose(const bool doVerbose);
void setDebug(const bool doDebug);
void loadEntryKey(int iLineNo,
void loadEntryKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sOrgText,
const string& sText,
bool bIsFuzzy);
void setSourceKey(int iLineNo,
const string& sComment,
const string& sResource,
bool bIsFuzzy);
void setSourceKey(int iLineNo,
const string& sFilename,
const string& sKey,
const string& sText,
bool bMustExist);
const string& sComment,
const string& sResource,
bool bMustExist);
void saveTemplates(const string& sTargetDir,
bool bKid,
bool bForce);
void saveLanguages(l10nMem& cMem,
bool bForce);
void saveLanguages(l10nMem& cMem,
const string& sTargetDir,
bool bForce);
bool bForce);
void dumpMem(const string& sTargetDir);
int prepareMerge();
bool getMergeLang(string& sLang,
......@@ -80,17 +81,16 @@ class l10nMem
void convertFromInetString(string& sText);
private:
bool mbVerbose;
bool mbDebug;
bool mbInError;
bool mbVerbose;
bool mbDebug;
bool mbInError;
string msModuleName;
string msResourceName;
int miCurFileInx;
int miCurLangInx;
int miCurENUSinx;
bool mbNeedWrite;
bool mbConvertMode;
bool mbStrictMode;
int miCurFileInx;
int miCurLangInx;
int miCurENUSinx;
bool mbNeedWrite;
bool mbConvertMode;
bool mbStrictMode;
vector<l10nMem_enus_entry> mcENUSlist;
vector<l10nMem_file_entry> mcFileList;
vector<l10nMem_lang_list_entry> mcLangList;
......@@ -105,31 +105,31 @@ class l10nMem
const string& sKey,
const string& sMsgId,
const string& sMsgStr,
bool bIsFuzzy);
void saveTemplates(l10nMem& cMem,
const string& sTargetDir,
bool bKid,
bool bForce);
void loadENUSkey(int iLineNo,
bool bIsFuzzy);
void loadENUSkey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId);
void loadLangKey(int iLineNo,
const string& sMsgId,
const string& sComment,
const string& sResource);
void loadLangKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
const string& sMsgStr,
bool bFuzzy);
void reorganize(bool bConvert);
bool locateKey(int iLineNo,
bool bFuzzy);
void reorganize(bool bConvert);
bool locateKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
bool bThrow);
void addKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
bool bThrow);
void addKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
const string& sComment,
const string& sResource,
l10nMem::ENTRY_STATE eStat);
bool findFileName(const string& sSourceFile);
};
......
......@@ -40,12 +40,6 @@ convert_po::convert_po(l10nMem& crMemory)
convert_po::~convert_po()
{
}
void convert_po::startLook()
{
string sFileName, sNewKey;
......@@ -62,7 +56,7 @@ void convert_po::startLook()
// load in db
if (msId.size())
mcMemory.loadEntryKey(miLineNo, sFileName, sNewKey, msId, msStr, mbFuzzy);
mcMemory.loadEntryKey(miLineNo, sFileName, sNewKey, msId, msStr, "", "", mbFuzzy);
// and prepare for new entry
msKey.clear();
......@@ -188,6 +182,7 @@ void convert_po::save(const string& sFileName,
const string& sKey,
const string& sENUStext,
const string& sText,
const string& sComment,
const string& sResource,
bool bFuzzy)
{
......@@ -199,9 +194,10 @@ void convert_po::save(const string& sFileName,
newPos = sFileName.find_last_of("/\\", sFileName.length());
sName = sFileName.substr(newPos + 1, sFileName.length());
outFile << endl
<< "#. xxxxx" << endl
<< "#: " << sName << endl
outFile << endl << "#. xxxxx" << endl;
if (sComment.length())
outFile << "#. " << sComment << endl;
outFile << "#: " << sName << endl
<< "msgctxt \"\"" << endl
<< "\"" << sName << "\\n\"" << endl
<< "\"" << sKey << "\\n\"" << endl
......
......@@ -25,19 +25,6 @@ using namespace std;
convert_prop::convert_prop(l10nMem& crMemory) : convert_gen(crMemory)
{
// throw l10nMem::showError(string("convert_prop not implemented"));
}
convert_prop::~convert_prop()
{
}
void convert_prop::doExecute()
{
throw l10nMem::showError(string("convert_prop::execute not implemented"));
......
......@@ -39,9 +39,9 @@ convert_src::convert_src(l10nMem& crMemory)
mbValuePresent(false),
mbInList(false),
mbInListItem(false)
{}
convert_src::~convert_src()
{}
{
}
extern int srclex(void);
......@@ -176,7 +176,7 @@ void convert_src::setNL(char *syyText, bool bMacro)
sKey += "." + msCmd + "." + msTextName;
if (msValue.size() && msValue != "-") {
mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, msValue, mbMergeMode);
mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, msValue, "", "", mbMergeMode);
if (mbMergeMode)
insertLanguagePart(sKey, msTextName);
}
......
......@@ -106,7 +106,7 @@ void convert_tree::setString(char *yytext)
case STATE_VAL_TITLE:
string sText = copySourceSpecial(yytext, 1);
sText.erase(sText.size()-1);
mcMemory.setSourceKey(miLineNo, msSourceFile, msId, sText, mbMergeMode);
mcMemory.setSourceKey(miLineNo, msSourceFile, msId, sText, "", "", mbMergeMode);
break;
}
meStateVal = STATE_VAL_NONE;
......@@ -121,14 +121,14 @@ void convert_tree::setState(char *yytext, STATE_TAG eNewStateTag, STATE_VAL eNew
meStateTag = eNewStateTag;
meStateVal = eNewStateVAL;
if (sModule)
mcMemory.setResourceName(sModule);
msModule = sModule;
}
void convert_tree::setValue(char *yytext)
{
mcMemory.setSourceKey(miLineNo, msSourceFile, msId, msCollector, mbMergeMode);
mcMemory.setSourceKey(miLineNo, msSourceFile, msId, msCollector, "", msModule, mbMergeMode);
copySourceSpecial(yytext, 2);
meStateTag = STATE_TAG_NONE;
......
......@@ -25,10 +25,6 @@ using namespace std;
convert_ulf::convert_ulf(l10nMem& crMemory) : convert_gen(crMemory) {}
convert_ulf::~convert_ulf() {}
extern int ulflex(void);
void convert_ulf::doExecute()
{
......@@ -49,11 +45,11 @@ void convert_ulf::setKey(char *syyText)
void convert_ulf::setText(char *syyText, bool bIsEnUs)
{
string sText = copySource(syyText) + " is not en-US";
string sText = copySource(syyText);
if (!bIsEnUs)
l10nMem::showError(sText);
if (!bIsEnUs && sText != "x-comment =")
l10nMem::showError(sText + " is not en-US");
}
......@@ -67,7 +63,7 @@ void convert_ulf::setValue(char *syyText)
nL = sText.rfind("\"");
sText.erase(nL);
mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, sText, mbMergeMode);
mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, sText, "", "", mbMergeMode);
if (mbMergeMode) {
// prepare to read all languages
......
......@@ -33,12 +33,6 @@ convert_xcs::convert_xcs(l10nMem& crMemory)
convert_xcs::~convert_xcs()
{
}
extern int xcslex(void);
void convert_xcs::doExecute()
{
......@@ -130,6 +124,6 @@ void convert_xcs::stopCollectData(char *syyText)
#endif
}
mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, sText, mbMergeMode);
mcMemory.setSourceKey(miLineNo, msSourceFile, sKey, sText, "", "", mbMergeMode);
mbCollectingData = false;
}
......@@ -32,12 +32,6 @@ convert_xcu::convert_xcu(l10nMem& crMemory)
convert_xcu::~convert_xcu()
{
}
extern int xculex(void);
void convert_xcu::doExecute()
{
......@@ -129,7 +123,7 @@ void convert_xcu::stopCollectData(char *syyText)
// locate key and extract it
for (nL = 0; nL < (int)mcStack.size(); ++nL)
useKey += (useKey.size() ? "." : "" ) + mcStack[nL];
mcMemory.setSourceKey(miLineNo, msSourceFile, useKey, useText, mbMergeMode);
mcMemory.setSourceKey(miLineNo, msSourceFile, useKey, useText, "", "", mbMergeMode);
}
if (mbMergeMode) {
......
......@@ -54,8 +54,6 @@ void convert_xhp::doExecute()
string sLang;
string sFile, sFile2;
mcMemory.setResourceName("help");
// prepare list with languages
miCntLanguages = mcMemory.prepareMerge();
if (mbMergeMode) {
......@@ -251,7 +249,7 @@ void convert_xhp::closeTransTag(char *yytext)
string newString(msCollector);
if (newString[newString.length() - 1] == ' ')
newString = newString.substr(0, newString.length() - 1);
mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, newString, mbMergeMode);
mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, newString, "", "help", mbMergeMode);
}
msKey.clear();
iType = 2;
......
......@@ -35,16 +35,9 @@ convert_xrm::convert_xrm(l10nMem& crMemory)
convert_xrm::~convert_xrm()
{
}
extern int xrmlex(void);
void convert_xrm::doExecute()
{
mcMemory.setResourceName("readmeitem");
xrmlex();
// write last part of file.
......@@ -124,7 +117,7 @@ void convert_xrm::stopCollectData(char *yytext)
copySource(yytext);
if (!mbNoCollectingData) {
mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, sText, mbMergeMode);
mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, sText, "", "readmeitem", mbMergeMode);
mbNoCollectingData = true;
if (mbMergeMode) {
sTagEnd = "</" + msTag.substr(1,msTag.size()-2) + ">\n";
......
......@@ -89,13 +89,15 @@ class l10nMem_enus_entry
public:
l10nMem_enus_entry(const string& sKey,
const string& sMsgId,
const string& sComment,
const string& sResource,
int iLineNo,
int iFileInx,
int iLangSize,
l10nMem::ENTRY_STATE eState)
: msMsgId(sMsgId),
msResId(sResource),
msComment(sComment),
msResource(sResource),
meState(eState),
miFileInx(iFileInx),
miLineNo(iLineNo)
......@@ -115,10 +117,11 @@ class l10nMem_enus_entry
string msKey; // key in po file and source file
string msMsgId; // en-US text from source file
string msResId; // Resource Id (to be used in msgcstr)
l10nMem::ENTRY_STATE meState; // status information
int miFileInx; // index of file name
int miLineNo; // line number
string msComment; // Comment (to be used in msgcstr)
string msResource; // Resource Id (to be used in msgcstr)
l10nMem::ENTRY_STATE meState; // status information
int miFileInx; // index of file name
int miLineNo; // line number
vector<l10nMem_lang_entry> mcLangText; // language texts (index is languageId)
};
......@@ -137,10 +140,9 @@ l10nMem::l10nMem()
{
myMem = this;
msModuleName = "default";
msResourceName = "";
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));
mcENUSlist.push_back(l10nMem_enus_entry("-genLang-", "-genLang-", "", "", 0, 0, 0, l10nMem::ENTRY_DELETED));
}
......@@ -204,20 +206,6 @@ const string& l10nMem::getModuleName()
void l10nMem::setResourceName(const string& sResourceName)
{
msResourceName = sResourceName;
}
const string& l10nMem::getResourceName()
{
return msResourceName;
}
void l10nMem::setLanguage(const string& sLanguage,
bool bCreate)
{
......@@ -284,28 +272,32 @@ void l10nMem::setDebug(bool doDebug)
void l10nMem::loadEntryKey(int iLineNo,
void l10nMem::loadEntryKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
const string& sMsgStr,
bool bIsFuzzy)
const string& sComment,
const string& sResource,
bool bIsFuzzy)
{
if (mbConvertMode)
convEntryKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy);
else if (!miCurLangInx)
loadENUSkey(iLineNo, sSourceFile, sKey, sMsgId);
loadENUSkey(iLineNo, sSourceFile, sKey, sMsgId, sComment, sResource);
else
loadLangKey(iLineNo, sSourceFile, sKey, sMsgId, sMsgStr, bIsFuzzy);
}
void l10nMem::setSourceKey(int iLineNo,
void l10nMem::setSourceKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
bool bMustExist)
const string& sComment,
const string& sResource,
bool bMustExist)
{
string newText(sMsgId);
int i;
......@@ -336,21 +328,17 @@ void l10nMem::setSourceKey(int iLineNo,
throw showError("key " + sKey + " does not exist");
// add key, if changed text, this is wrong but handled in reorganize
addKey(iLineNo, sSourceFile, sKey, newText, ENTRY_ADDED);
addKey(iLineNo, sSourceFile, sKey, newText, sComment, sResource, ENTRY_ADDED);
}
}
void l10nMem::saveTemplates(const string& sTargetDir, bool bKid, bool bForce)
void l10nMem::saveTemplates(const string& sTargetDir, bool bForce)
{
string target(msModuleName + ".pot");
int iE, iEsize = mcENUSlist.size();
// Dummy to satisfy compiler
if (bKid)
throw "-k not implemented";
// and reorganize db if needed
miCurFileInx = 0;
reorganize(false);
......@@ -359,8 +347,6 @@ void l10nMem::saveTemplates(const string& sTargetDir, bool bKid, bool bForce)
if (!needWrite(target, bForce))
return;
//JIX save HANDLE KID
// Save en-US
convert_po savePo(*this);
......@@ -372,7 +358,7 @@ void l10nMem::saveTemplates(const string& sTargetDir, bool bKid, bool bForce)
if (cE.meState == ENTRY_DELETED)
continue;
savePo.save(mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, "", cE.msResId, false);
savePo.save(mcFileList[cE.miFileInx].msFileName, cE.msKey, cE.msMsgId, "", cE.msComment, cE.msResource, false);
}
savePo.endSave();
}
......@@ -679,12 +665,12 @@ bool l10nMem::convFilterWarning(const string& sSourceFile,
void l10nMem::convEntryKey(int iLineNo,
void l10nMem::convEntryKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
const string& sMsgStr,
bool bIsFuzzy)
bool bIsFuzzy)
{
vector<int> ivEntryList;
string curFileName;
......@@ -774,23 +760,25 @@ void l10nMem::convEntryKey(int iLineNo,
void l10nMem::loadENUSkey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId)
void l10nMem::loadENUSkey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
const string& sComment,
const string& sResource)
{
// add it to vector and update file pointer
addKey(iLineNo, sSourceFile, sKey, sMsgId, ENTRY_DELETED);
addKey(iLineNo, sSourceFile, sKey, sMsgId, sComment, sResource, ENTRY_DELETED);
}
void l10nMem::loadLangKey(int iLineNo,
void l10nMem::loadLangKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
const string& sMsgStr,
bool bFuzzy)
bool bFuzzy)
{
if (!locateKey(iLineNo, sSourceFile, sKey, sMsgId, true))
throw l10nMem::showError(".po file contains unknown filename: " + sSourceFile + " or key: " + sKey);
......@@ -901,10 +889,12 @@ bool l10nMem::locateKey(int iLineNo,
void l10nMem::addKey(int iLineNo,
void l10nMem::addKey(int iLineNo,
const string& sSourceFile,
const string& sKey,
const string& sMsgId,
const string& sComment,
const string& sResource,
l10nMem::ENTRY_STATE eStat)
{
// check file
......@@ -917,7 +907,7 @@ void l10nMem::addKey(int iLineNo,
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, msResourceName, iLineNo, miCurFileInx,
mcENUSlist.push_back(l10nMem_enus_entry(sKey, sMsgId, sComment, sResource, iLineNo, miCurFileInx,
mcLangList.size(), eStat));
mcFileList[miCurFileInx].miEnd = miCurENUSinx;
}
......@@ -930,7 +920,7 @@ void l10nMem::addKey(int iLineNo,
curF.miEnd++;
miCurENUSinx = curF.miEnd;
mcENUSlist.insert(it + curF.miEnd,
l10nMem_enus_entry(sKey, sMsgId, msResourceName, iLineNo, miCurFileInx,
l10nMem_enus_entry(sKey, sMsgId, sComment, sResource, iLineNo, miCurFileInx,
mcLangList.size(), eStat));
for (int i = miCurFileInx + 1; i < iFsize; ++i) {
l10nMem_file_entry& curF2 = mcFileList[i];
......
......@@ -341,7 +341,7 @@ void handler::runExtract()
}
// and generate language file
mcMemory.saveTemplates(msTargetDir, false, mbForceSave);
mcMemory.saveTemplates(msTargetDir, mbForceSave);
}
......
......@@ -131,7 +131,5 @@ KEYID [a-zA-Z0-9_-]+
void ulf_dummyJustForCompiler()
{
char *txt = NULL;
// yy_flex_strlen(txt);
yyunput(0, txt);
yyunput(0, NULL);
}
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