[Libreoffice-commits] .: Branch 'feature/killsdf' - l10ntools/inc l10ntools/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Sep 24 09:05:18 PDT 2012
l10ntools/inc/po.hxx | 60 ++-------
l10ntools/source/po.cxx | 261 ++++++++++++++++++-------------------------
l10ntools/source/renewpo.cxx | 17 +-
3 files changed, 136 insertions(+), 202 deletions(-)
New commits:
commit 27335522a2bfccb7254e146e1b35aa406772508d
Author: Zolnai Tamás <zolnaitamas2000 at gmail.com>
Date: Sun Sep 23 11:10:45 2012 +0200
Use PoEntry and PoHeader more like an interface
Delete all members except member with type
GenPoEntry and use getter methods to define
them.
Plus correct renewpo.
Change-Id: I97665b406467053fce8b4864b47456762887e715
Reviewed-on: https://gerrit.libreoffice.org/681
Reviewed-by: Andras Timar <atimar at suse.com>
Tested-by: Andras Timar <atimar at suse.com>
diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx
index 81bafe7..686c9f3 100644
--- a/l10ntools/inc/po.hxx
+++ b/l10ntools/inc/po.hxx
@@ -15,9 +15,7 @@
class GenPoEntry
{
-
private:
-
OString m_sWhiteSpace;
OString m_sExtractCom;
OString m_sReference;
@@ -57,40 +55,30 @@ public:
class PoEntry
{
+private:
+ GenPoEntry m_aGenPo;
+
public:
enum SDFPARTS { PROJECT, SOURCEFILE, DUMMY, RESOURCETYPE, GROUPID,
LOCALID, HELPID, PLATFORM, WIDTH, LANGUAGEID,
TEXT, HELPTEXT, QUICKHELPTEXT, TITLE, TIMESTAMP };
enum TYPE { TTEXT=TEXT, TQUICKHELPTEXT=QUICKHELPTEXT, TTITLE=TITLE };
-private:
-
- GenPoEntry m_aGenPo;
- OString m_sSourceFile;
- OString m_sGroupId;
- OString m_sLocalId;
- OString m_sResourceType;
- TYPE m_eType;
- OString m_sHelpText;
-
- void SetMembers();
-public:
PoEntry();
- PoEntry(const OString& i_rSDFLine,
+ PoEntry(const OString& rSDFLine,
const TYPE eType = TTEXT);
- virtual ~PoEntry();
-
- OString getSourceFile() const { return m_sSourceFile; }
- OString getGroupId() const { return m_sGroupId; }
- OString getLocalId() const { return m_sLocalId; }
- OString getResourceType() const { return m_sResourceType; }
- TYPE getType() const { return m_eType; }
- OString getHelpText() const { return m_sHelpText; }
+ ~PoEntry();
+
+ OString getSourceFile() const;
+ OString getGroupId() const;
+ OString getLocalId() const;
+ OString getResourceType() const;
+ TYPE getType() const;
OString getUnTransStr() const;
OString getTransStr() const;
- bool getFuzzy() const { return m_aGenPo.getFuzzy(); }
- bool isNull() const { return m_aGenPo.isNull(); }
- OString getKeyId() const { return m_aGenPo.getKeyId(); }
+ bool getFuzzy() const;
+ bool isNull() const;
+ OString getKeyId() const;
void setUnTransStr(const OString& rUnTransStr);
void setTransStr(const OString& rTransStr);
void setFuzzy(const bool bFuzzy);
@@ -104,31 +92,15 @@ public:
class PoHeader
{
-
private:
GenPoEntry m_aGenPo;
- OString m_sExtractionSource;
- OString m_sProjectIdVersion;
- OString m_sReportMsgidBugsTo;
- OString m_sPotCreationDate;
- OString m_sPoRevisionDate;
- OString m_sLastTranslator;
- OString m_sLanguageTeam;
- OString m_sLanguage;
- OString m_sMimeVersion;
- OString m_sContentType;
- OString m_sEncoding;
- OString m_sPluralForms;
- OString m_sXGenerator;
- OString m_sXAcceleratorMarker;
-
- void SetMembers();
+
public:
PoHeader();
PoHeader( const OString& rExtSrc );
~PoHeader();
- OString getLanguage() const { return m_sLanguage; }
+ OString getLanguage() const;
void writeToFile(std::ofstream& rOFStream);
void readFromFile(std::ifstream& rIFStream);
};
diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx
index 3be13fc..f433aab 100644
--- a/l10ntools/source/po.cxx
+++ b/l10ntools/source/po.cxx
@@ -382,37 +382,38 @@ OString ImplEscapeSDFText(const OString& rText,const bool bHelpText = false)
//Default constructor
PoEntry::PoEntry()
: m_aGenPo( GenPoEntry() )
- , m_sSourceFile( OString() )
- , m_sGroupId( OString() )
- , m_sLocalId( OString() )
- , m_sResourceType( OString() )
- , m_eType( TTEXT )
- , m_sHelpText( OString() )
{
}
//Construct PoEntry from sdfline
PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType)
: m_aGenPo( GenPoEntry() )
- , m_sSourceFile( OString() )
- , m_sGroupId( OString() )
- , m_sLocalId( OString() )
- , m_sResourceType(OString() )
- , m_eType( TTEXT )
- , m_sHelpText( OString() )
{
std::vector<OString> vParts;
ImplSplitAt(rSDFLine,'\t',vParts);
if(vParts.size()!=15) throw;
+ m_aGenPo.setWhiteSpace("\n");
+
+ m_aGenPo.setReference(vParts[SOURCEFILE].
+ copy(vParts[SOURCEFILE].lastIndexOf("\\")+1));
- m_sSourceFile = vParts[SOURCEFILE].
- copy(vParts[SOURCEFILE].lastIndexOf("\\")+1);
- m_sResourceType = vParts[RESOURCETYPE];
- m_sGroupId = vParts[GROUPID];
- m_sLocalId = vParts[LOCALID];
- m_eType = eType;
- m_sHelpText = vParts[HELPTEXT];
+ m_aGenPo.setExtractCom(vParts[HELPTEXT]);
+ OString sContext = vParts[GROUPID] + "\n" +
+ (vParts[LOCALID].isEmpty() ? "" : vParts[LOCALID] + "\n") +
+ vParts[RESOURCETYPE];
+ switch(eType){
+ case TTEXT:
+ sContext += ".text"; break;
+ case TQUICKHELPTEXT:
+ sContext += ".quickhelptext"; break;
+ case TTITLE:
+ sContext += ".title"; break;
+ default:
+ throw; break;
+ }
+ m_aGenPo.setContext(sContext);
setUnTransStr(vParts[eType]);
+ m_aGenPo.genKeyId();
}
//Destructor
@@ -420,46 +421,82 @@ PoEntry::~PoEntry()
{
}
-//Set members on the basis of m_aGenPo
-void PoEntry::SetMembers()
+//Get name of file from which entry is extracted
+OString PoEntry::getSourceFile() const
{
- if( !m_aGenPo.isNull() )
- {
- m_sSourceFile = m_aGenPo.getReference();
- OString sContext = m_aGenPo.getContext();
- m_sGroupId = sContext.getToken(0,'\n');
+ return m_aGenPo.getReference();
+}
- if (sContext.indexOf('\n')==sContext.lastIndexOf('\n'))
- m_sResourceType = sContext.getToken(1,'\n').getToken(0,'.');
- else
- {
- m_sLocalId = sContext.getToken(1,'\n');
- m_sResourceType = sContext.getToken(2,'\n').getToken(0,'.');
- }
- if (sContext.endsWith(".text"))
- m_eType = TTEXT;
- else if (sContext.endsWith(".quickhelptext"))
- m_eType = TQUICKHELPTEXT;
- else if (sContext.endsWith(".title"))
- m_eType = TTITLE;
- else{
- throw;}
- m_sHelpText = m_aGenPo.getExtractCom();
- }
+//Get groupid
+OString PoEntry::getGroupId() const
+{
+ return m_aGenPo.getContext().getToken(0,'\n');
+}
+
+//Get localid
+OString PoEntry::getLocalId() const
+{
+ const OString sContext = m_aGenPo.getContext();
+ if (sContext.indexOf('\n')==sContext.lastIndexOf('\n'))
+ return OString();
+ else
+ return sContext.getToken(1,'\n');
+}
+
+//Get the type of component from which entry is extracted
+OString PoEntry::getResourceType() const
+{
+ const OString sContext = m_aGenPo.getContext();
+ if (sContext.indexOf('\n')==sContext.lastIndexOf('\n'))
+ return sContext.getToken(1,'\n').getToken(0,'.');
+ else
+ return sContext.getToken(2,'\n').getToken(0,'.');
+}
+
+//Get the type of entry
+PoEntry::TYPE PoEntry::getType() const
+{
+ const OString sContext = m_aGenPo.getContext();
+ if (sContext.endsWith(".text"))
+ return TTEXT;
+ else if (sContext.endsWith(".quickhelptext"))
+ return TQUICKHELPTEXT;
+ else if (sContext.endsWith(".title"))
+ return TTITLE;
+ else throw;
}
+//Check wheather entry is fuzzy
+bool PoEntry::getFuzzy() const
+{
+ return m_aGenPo.getFuzzy();
+}
+
+//Check wheather entry is null
+bool PoEntry::isNull() const
+{
+ return m_aGenPo.isNull();
+}
+
+//Get keyid
+OString PoEntry::getKeyId() const
+{
+ return m_aGenPo.getKeyId();
+}
+
+
//Get translation string in sdf/merge format
OString PoEntry::getUnTransStr() const
{
return ImplEscapeSDFText(m_aGenPo.getUnTransStr(),
- m_sSourceFile.endsWith(".xhp"));
+ getSourceFile().endsWith(".xhp"));
}
//Get translated string in sdf/merge format
OString PoEntry::getTransStr() const
{
return ImplEscapeSDFText(m_aGenPo.getTransStr(),
- m_sSourceFile.endsWith(".xhp"));
+ getSourceFile().endsWith(".xhp"));
}
@@ -468,7 +505,7 @@ void PoEntry::setUnTransStr(const OString& rUnTransStr)
{
m_aGenPo.setUnTransStr(
ImplUnEscapeSDFText(
- rUnTransStr,m_sSourceFile.endsWith(".xhp")));
+ rUnTransStr,getSourceFile().endsWith(".xhp")));
}
//Set translated string when input is in sdf format
@@ -476,7 +513,7 @@ void PoEntry::setTransStr(const OString& rTransStr)
{
m_aGenPo.setTransStr(
ImplUnEscapeSDFText(
- rTransStr,m_sSourceFile.endsWith(".xhp")));
+ rTransStr,getSourceFile().endsWith(".xhp")));
}
//Set fuzzy flag
@@ -488,25 +525,6 @@ void PoEntry::setFuzzy(const bool bFuzzy)
//Write to file
void PoEntry::writeToFile(std::ofstream& rOFStream)
{
- m_aGenPo.setWhiteSpace("\n");
- m_aGenPo.setExtractCom(m_sHelpText);
- m_aGenPo.setReference(m_sSourceFile);
-
- OString sContext = m_sGroupId + "\n" +
- (m_sLocalId.isEmpty() ? "" : m_sLocalId + "\n") +
- m_sResourceType;
- switch(m_eType){
- case TTEXT:
- sContext += ".text"; break;
- case TQUICKHELPTEXT:
- sContext += ".quickhelptext"; break;
- case TTITLE:
- sContext += ".title"; break;
- default:
- throw; break;
- }
- m_aGenPo.setContext(sContext);
- m_aGenPo.genKeyId();
m_aGenPo.writeToFile(rOFStream);
}
@@ -516,16 +534,15 @@ void PoEntry::readFromFile(std::ifstream& rIFStream)
{
*this = PoEntry();
m_aGenPo.readFromFile(rIFStream);
- SetMembers();
}
//Check whether po-s belong to the same localization component
bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2)
{
- return ( rPo1.m_sSourceFile == rPo2.m_sSourceFile &&
- rPo1.m_sGroupId == rPo2.m_sGroupId &&
- rPo1.m_sLocalId == rPo2.m_sLocalId &&
- rPo1.m_sResourceType == rPo2.m_sResourceType );
+ return ( rPo1.getSourceFile() == rPo2.getSourceFile() &&
+ rPo1.getGroupId() == rPo2.getGroupId() &&
+ rPo1.getLocalId() == rPo2.getLocalId() &&
+ rPo1.getResourceType() == rPo2.getResourceType() );
}
//Class PoHeader
@@ -540,113 +557,57 @@ OString ImplGetTime()
return pBuff;
}
-//Get relevant part of actual token
-OString ImplGetElement(const OString& rText, const sal_Int32 nToken)
-{
- OString sToken = rText.getToken(nToken,'\n');
- sal_Int32 nFirstIndex = sToken.indexOf(':') + 2;
- return sToken.copy( nFirstIndex,sToken.getLength()-nFirstIndex );
-}
-
//Default Constructor
PoHeader::PoHeader()
: m_aGenPo( GenPoEntry() )
- , m_sExtractionSource( OString() )
- , m_sProjectIdVersion( OString() )
- , m_sReportMsgidBugsTo( OString() )
- , m_sPotCreationDate( OString() )
- , m_sPoRevisionDate( OString() )
- , m_sLastTranslator( OString() )
- , m_sLanguageTeam( OString() )
- , m_sLanguage( OString() )
- , m_sMimeVersion( OString() )
- , m_sContentType( OString() )
- , m_sEncoding( OString() )
- , m_sPluralForms( OString() )
- , m_sXGenerator( OString() )
- , m_sXAcceleratorMarker( OString() )
{
}
//Template Constructor
PoHeader::PoHeader( const OString& rExtSrc )
: m_aGenPo( GenPoEntry() )
- , m_sExtractionSource( rExtSrc )
- , m_sProjectIdVersion( "PACKAGE VERSION" )
- , m_sReportMsgidBugsTo( OString("https://bugs.freedesktop.org/") +
- "enter_bug.cgi?product=LibreOffice&" +
- "bug_status=UNCONFIRMED&component=UI" )
- , m_sPotCreationDate( ImplGetTime() )
- , m_sPoRevisionDate( "YEAR-MO-DA HO:MI+ZONE" )
- , m_sLastTranslator( "FULL NAME <EMAIL at ADDRESS>" )
- , m_sLanguageTeam( "LANGUAGE <LL at li.org>" )
- , m_sLanguage( OString() )
- , m_sMimeVersion( "1.0" )
- , m_sContentType( "text/plain; charset=UTF-8" )
- , m_sEncoding( "8bit" )
- , m_sPluralForms( OString() )
- , m_sXGenerator( "LibreOffice" )
- , m_sXAcceleratorMarker( "~" )
{
+ m_aGenPo.setExtractCom("extracted from " + rExtSrc);
+ m_aGenPo.setTransStr(
+ OString("Project-Id-Version: PACKAGE VERSION\n"
+ "Report-Msgid-Bugs-To: https://bugs.freedesktop.org/enter_bug.cgi?"
+ "product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n"
+ "POT-Creation-Date: ") + ImplGetTime() +
+ OString("\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+ "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+ "Language-Team: LANGUAGE <LL at li.org>\n"
+ "MIME-Version: 1.0\n"
+ "Content-Type: text/plain; charset=UTF-8\n"
+ "Content-Transfer-Encoding: 8bit\n"
+ "X-Genarator: LibreOffice\n"
+ "X-Accelerator_Marker: ~\n"));
}
PoHeader::~PoHeader()
{
}
-//Set members on the basis of m_aGenPo
-void PoHeader::SetMembers()
+//Get the language of header
+OString PoHeader::getLanguage() const
{
- if( !m_aGenPo.isNull() )
- {
- m_sExtractionSource = m_aGenPo.getExtractCom();
- OString sTemp = m_aGenPo.getTransStr();
-
- sal_Int32 nToken = 0;
- m_sProjectIdVersion = ImplGetElement(sTemp,nToken++);
- m_sReportMsgidBugsTo = ImplGetElement(sTemp,nToken++);
- m_sPotCreationDate = ImplGetElement(sTemp,nToken++);
- m_sPoRevisionDate = ImplGetElement(sTemp,nToken++);
- m_sLastTranslator = ImplGetElement(sTemp,nToken++);
- m_sLanguageTeam = ImplGetElement(sTemp,nToken++);
- if( sTemp.getToken(nToken,'\n').match("Language:") )
- m_sLanguage = ImplGetElement(sTemp,nToken++);
- m_sMimeVersion = ImplGetElement(sTemp,nToken++);
- m_sContentType = ImplGetElement(sTemp,nToken++);
- m_sEncoding = ImplGetElement(sTemp,nToken++);
- if( sTemp.getToken(nToken,'\n').match("Plural-Forms:") )
- m_sPluralForms = ImplGetElement(sTemp,nToken++);
- m_sXGenerator = ImplGetElement(sTemp,nToken++);
- m_sXAcceleratorMarker = ImplGetElement(sTemp,nToken);
- }
+ const OString sLang = "Language: ";
+ const OString sTransStr = m_aGenPo.getTransStr();
+ const sal_Int32 nFirstIndex = sTransStr.indexOf(sLang)+sLang.getLength();
+ const sal_Int32 nCount = sTransStr.indexOf('\n',nFirstIndex)-nFirstIndex;
+ return sTransStr.copy(nFirstIndex,nCount);
}
+//Write out to file
void PoHeader::writeToFile(std::ofstream& rOFStream)
{
- m_aGenPo.setExtractCom("extracted from " + m_sExtractionSource);
- m_aGenPo.setTransStr(
- "Project-Id-Version: " + m_sProjectIdVersion + "\n" +
- "Report-Msgid-Bugs-To: " + m_sReportMsgidBugsTo + "\n" +
- "POT-Creation-Date: " + m_sPotCreationDate + "\n" +
- "PO-Revision-Date: " + m_sPoRevisionDate + "\n" +
- "Last-Translator: " + m_sLastTranslator + "\n" +
- "Language-Team: " + m_sLanguageTeam + "\n" +
- ( m_sLanguage.isEmpty() ? "" : "Language: " + m_sLanguage + "\n" ) +
- "MIME-Version: " + m_sMimeVersion + "\n" +
- "Content-Type: " + m_sContentType + "\n" +
- "Content-Transfer-Encoding: " + m_sEncoding + "\n" +
- ( m_sPluralForms.isEmpty() ? "" :
- "Plural-Forms: " + m_sPluralForms + "\n" ) +
- "X-Genarator: " + m_sXGenerator + "\n" +
- "X-Accelerator_Marker: " + m_sXAcceleratorMarker + "\n");
m_aGenPo.writeToFile(rOFStream);
}
+//Read from file
void PoHeader::readFromFile(std::ifstream& rIFStream)
{
*this = PoHeader();
m_aGenPo.readFromFile(rIFStream);
- SetMembers();
}
diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx
index 3e4e98f..398b23b 100644
--- a/l10ntools/source/renewpo.cxx
+++ b/l10ntools/source/renewpo.cxx
@@ -106,7 +106,7 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath,
getline(aSDFInput,s);
sLine = OString(s.data(),s.length());
OString sActTrans;
- if (IsSameEntry(sActUnTrans,sLine))
+ if (!aSDFInput.eof() && IsSameEntry(sActUnTrans,sLine))
{
sActTrans = sLine;
getline(aSDFInput,s);
@@ -134,16 +134,18 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath,
sActUnTrans = DelLocalId(sActUnTrans);
}*/
PoEntry aPE(sActUnTrans, vTypes[nIndex]);
- aPE.setTransStr(sActTrans.getToken(vTypes[nIndex],'\t'));
- aPE.setFuzzy(sActTrans.isEmpty() ? 0 :
- bool(sActTrans.getToken(PoEntry::DUMMY,'\t').
- copy(nDummyBit++,1).toInt32()));
+ const OString sActStr =
+ sActTrans.getToken(vTypes[nIndex],'\t');
+ aPE.setTransStr(sActStr);
+ aPE.setFuzzy( sActStr.isEmpty() ? false :
+ static_cast<bool>(sActTrans.getToken(PoEntry::DUMMY,'\t').
+ copy(nDummyBit++,1).toBoolean()));
aPE.writeToFile(aOutPut);
}
}
-
//Check wheather next entry is in the same po file
- OString sNextSourcePath = GetPath(sPath,sLine);
+ OString sNextSourcePath =
+ !aSDFInput.eof() ? GetPath(sPath,sLine) : "";
if (sNextSourcePath!=sActSourcePath)
{
aOutPut.close();
@@ -156,7 +158,6 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath,
//Close and remove sdf file
aSDFInput.close();
system(("rm " + SDFFileName).getStr());
- aOutPut.close();
}
More information about the Libreoffice-commits
mailing list