[Libreoffice-commits] .: 2 commits - l10ntools/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Nov 21 13:52:49 PST 2012


 l10ntools/source/merge.cxx     |   37 +++++++++++++++++--------------------
 l10ntools/source/propmerge.cxx |    8 +++++---
 l10ntools/source/treemerge.cxx |    6 ++++--
 3 files changed, 26 insertions(+), 25 deletions(-)

New commits:
commit 9c4f31c168e12fc5432ebdd15f247c285358ffc8
Author: Zolnai Tamás <zolnaitamas2000g at gmail.com>
Date:   Wed Nov 21 22:40:13 2012 +0100

    Get language id from path of po file
    
    Language ids in po headers can be various so
    its simpler to extract from path.
    
    Change-Id: I3e9447359f3c054aea32b5417b2168025168c556

diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index af2ebdc..3ff5400 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -39,7 +39,7 @@ namespace
 
     static bool lcl_ReadPoChecked(
         PoEntry& o_rPoEntry, PoIfstream& rPoFile,
-        const std::string& rFileName)
+        const OString& rFileName)
     {
         try
         {
@@ -51,7 +51,7 @@ namespace
             {
                 printf(
                     "Warning : %s contains invalid entry\n",
-                    rFileName.c_str() );
+                    rFileName.getStr() );
                 return false;
             }
         }
@@ -159,19 +159,20 @@ MergeDataFile::MergeDataFile(
         printf("Warning : Can't open po path container file");
         return;
     }
-    std::string sPoFileName;
-    aInputStream >> sPoFileName;
+    std::string sPoFile;
+    aInputStream >> sPoFile;
     bool bFirstLang = true;
     while( !aInputStream.eof() )
     {
         const OString sHack("HACK");
         const OString sFileName( lcl_NormalizeFilename(rFile) );
         const bool bReadAll = sFileName.isEmpty();
+        const OString sPoFileName(sPoFile.data(), sPoFile.length());
         PoIfstream aPoInput;
-        aPoInput.open( OString(sPoFileName.data(), sPoFileName.length()) );
+        aPoInput.open( sPoFileName );
         if ( !aPoInput.isOpen() )
         {
-            printf( "Warning : Can't open %s\n", sPoFileName.c_str() );
+            printf( "Warning : Can't open %s\n", sPoFileName.getStr() );
             return;
         }
         PoHeader aPoHeader;
@@ -185,24 +186,20 @@ MergeDataFile::MergeDataFile(
             {
                 printf(
                     "Warning : %s has invalid header\n",
-                    sPoFileName.c_str() );
+                    sPoFileName.getStr() );
                 return;
             }
         }
+
         OString sLang;
-        try
-        {
-            sLang = aPoHeader.getLanguage().replaceAll("_","-");
-        }
-        catch( PoHeader::Exception& aException )
+        //Get language id from path
         {
-            if( aException == PoHeader::NOLANG )
-            {
-                printf(
-                    "Warning : %s' header not has language specification\n",
-                    sPoFileName.c_str() );
-                return;
-            }
+            const OString sTransSource("translations/source/");
+            const sal_Int32 nStart =
+                sPoFileName.indexOf(sTransSource)+sTransSource.getLength();
+            const sal_Int32 nCount =
+                sPoFileName.indexOf("/",nStart) - nStart;
+            sLang = sPoFileName.copy(nStart,nCount);
         }
         aLanguageSet.insert( sLang );
         PoEntry aNextPo;
@@ -276,7 +273,7 @@ MergeDataFile::MergeDataFile(
             }
         }
         aPoInput.close();
-        aInputStream >> sPoFileName;
+        aInputStream >> sPoFile;
         bFirstLang = false;
     }
     aInputStream.close();
commit 8ae3ddca7e99d2bdbaadd5e0c82de2f0fbd30f91
Author: Zolnai Tamás <zolnaitamas2000g at gmail.com>
Date:   Wed Nov 21 21:52:01 2012 +0100

    Fix language id checking
    
    The result of GetLanguages() is a vector, but
    behind it the language ids stored in a set, so
    the order not depend on which id was inserted first.
    With language ids which are after qtz in alphabetic order
    this checkings works wrong.
    
    Change-Id: I4e15d4de576b1fc567692109311c053b0d93ea60

diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx
index 91ea78b..a4440e9 100644
--- a/l10ntools/source/propmerge.cxx
+++ b/l10ntools/source/propmerge.cxx
@@ -182,13 +182,15 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil
 
     MergeDataFile aMergeDataFile( rMergeSrc, m_sSource, false );
 
-    const std::vector<OString> aLanguages = aMergeDataFile.GetLanguages();
-    if( m_sLang != "qtz" && !aLanguages.empty() && aLanguages[0] != m_sLang )
+    const std::vector<OString> vLanguages = aMergeDataFile.GetLanguages();
+    if( m_sLang != "qtz" && vLanguages.size()>=2 &&
+        vLanguages[vLanguages[0]!="qtz" ? 0 : 1] != m_sLang )
     {
         std::cerr
             << "Propex error: given language conflicts with "
             << "language of Mergedata file: "
-            << m_sLang.getStr() << " - " << aLanguages[0].getStr() << std::endl;
+            << m_sLang.getStr() << " - "
+            << vLanguages[vLanguages[0]!="qtz" ? 0 : 1].getStr() << std::endl;
         return;
     }
 
diff --git a/l10ntools/source/treemerge.cxx b/l10ntools/source/treemerge.cxx
index ed96da2..bc9596c 100644
--- a/l10ntools/source/treemerge.cxx
+++ b/l10ntools/source/treemerge.cxx
@@ -282,12 +282,14 @@ void TreeParser::Merge(
         MergeDataFile aMergeDataFile(
             rMergeSrc, static_cast<OString>( m_pSource->name ), false );
         const std::vector<OString> vLanguages = aMergeDataFile.GetLanguages();
-        if( !vLanguages.empty() && vLanguages[0] != m_sLang )
+        if( vLanguages.size()>=2 &&
+            vLanguages[vLanguages[0]=="qtz" ? 0 : 1] != m_sLang )
         {
             std::cerr
                 << "Treex error: given language conflicts with "
                 << "language of Mergedata file: "
-                << m_sLang.getStr() << " - " << vLanguages[0].getStr() << std::endl;
+                << m_sLang.getStr() << " - "
+                << vLanguages[vLanguages[0]=="qtz" ? 0 : 1].getStr() << std::endl;
             return;
         }
         lcl_MergeLevel(


More information about the Libreoffice-commits mailing list