[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [lokalize/frameworks] src: handle the case when xliff file doesn; t have target language set,
From:       Nick Shaforostoff <shafff () ukr ! net>
Date:       2014-12-20 0:12:41
Message-ID: E1Y27ez-0006iB-AN () scm ! kde ! org
[Download RAW message or body]

Git commit 6b15df2df5fb2e09f7512cd217aaf52d4d61c4cd by Nick Shaforostoff.
Committed on 20/12/2014 at 02:11.
Pushed by shaforo into branch 'frameworks'.

handle the case when xliff file doesn;t have target language set,
add proper extension when 'saving as'

M  +9    -1    src/catalog/catalog.cpp
M  +1    -0    src/catalog/catalog.h
M  +2    -1    src/catalog/catalogstorage.h
M  +12   -1    src/catalog/xliff/xliffstorage.cpp
M  +2    -0    src/catalog/xliff/xliffstorage.h
M  +38   -3    src/common/languagelistmodel.cpp
M  +2    -0    src/common/languagelistmodel.h
M  +12   -3    src/editortab.cpp

http://commits.kde.org/lokalize/6b15df2df5fb2e09f7512cd217aaf52d4d61c4cd

diff --git a/src/catalog/catalog.cpp b/src/catalog/catalog.cpp
index eb98164..7bd3861 100644
--- a/src/catalog/catalog.cpp
+++ b/src/catalog/catalog.cpp
@@ -75,7 +75,7 @@ QString Catalog::supportedFileTypes(bool includeTemplates)
     return all+QStringLiteral("Gettext (*.po);;XLIFF (*.xlf *.xliff);;Linguist \
(*.ts)");  }
 
-static const char* const extensions[]={".po",".pot",".xlf", ".ts"};
+static const char* const extensions[]={".po",".pot",".xlf",".xliff", ".ts"};
 
 static const char* const xliff_states[]={
         I18N_NOOP("New"),I18N_NOOP("Needs translation"),I18N_NOOP("Needs full \
localization"),I18N_NOOP("Needs adaptation"),I18N_NOOP("Translated"), @@ -494,6 \
+494,14 @@ QString Catalog::targetLangCode() const  return \
m_storage->targetLangCode();  }
 
+void Catalog::setTargetLangCode(const QString& targetLangCode)
+{
+    if (KDE_ISUNLIKELY( !m_storage ))
+        return;
+
+    return m_storage->setTargetLangCode(targetLangCode);
+}
+
 //END STORAGE TRANSLATION
 
 //BEGIN OPEN/SAVE
diff --git a/src/catalog/catalog.h b/src/catalog/catalog.h
index de7d6d4..493f1c9 100644
--- a/src/catalog/catalog.h
+++ b/src/catalog/catalog.h
@@ -196,6 +196,7 @@ public slots: //DBus interface
     QString fileType();
     QString sourceLangCode() const;
     QString targetLangCode() const;
+    void setTargetLangCode(const QString& targetLangCode);
 
 protected:
     virtual KAutoSaveFile* checkAutoSave(const QString& url);
diff --git a/src/catalog/catalogstorage.h b/src/catalog/catalogstorage.h
index 8ad6218..9369595 100644
--- a/src/catalog/catalogstorage.h
+++ b/src/catalog/catalogstorage.h
@@ -147,6 +147,7 @@ public:
 
     QString sourceLangCode() const{return m_sourceLangCode;}
     QString targetLangCode() const{return m_targetLangCode;}
+    virtual void setTargetLangCode(const QString& langCode) \
{m_targetLangCode=langCode;}  
 protected:
     QString m_url;
@@ -157,7 +158,7 @@ protected:
 };
 
 inline CatalogStorage::CatalogStorage()
-    : m_sourceLangCode("en_US")
+    : m_sourceLangCode(QStringLiteral("en_US"))
     , m_numberOfPluralForms(0)
 {
 }
diff --git a/src/catalog/xliff/xliffstorage.cpp b/src/catalog/xliff/xliffstorage.cpp
index e3800cf..1551094 100644
--- a/src/catalog/xliff/xliffstorage.cpp
+++ b/src/catalog/xliff/xliffstorage.cpp
@@ -75,7 +75,7 @@ int XliffStorage::load(QIODevice* device)
     int errorLine;//+errorColumn;
     bool success=m_doc.setContent(&source, &reader, &errorMsg, \
&errorLine/*,errorColumn*/);  
-    if (!success)
+    if (!success || m_doc.elementsByTagName(QStringLiteral("file")).isEmpty())
     {
         qWarning()<<errorMsg;
         return errorLine+1;
@@ -180,6 +180,17 @@ int XliffStorage::size() const
     return m_map.size();
 }
 
+void XliffStorage::setTargetLangCode(const QString& langCode)
+{
+    m_targetLangCode=langCode;
+
+    QDomElement file=m_doc.elementsByTagName(QStringLiteral("file")).at(0).toElement();
 +    if (m_targetLangCode!=file.attribute(QStringLiteral("target-language")).replace('-', \
'_')) +    {
+        QString l=langCode;
+        file.setAttribute(QStringLiteral("target-language"), l.replace('_', '-'));
+    }
+}
 
 
 
diff --git a/src/catalog/xliff/xliffstorage.h b/src/catalog/xliff/xliffstorage.h
index 5aaef7c..9172d87 100644
--- a/src/catalog/xliff/xliffstorage.h
+++ b/src/catalog/xliff/xliffstorage.h
@@ -100,6 +100,8 @@ public:
     QString mimetype()const{return QStringLiteral("application/x-xliff");}
     QString fileType()const{return QStringLiteral("XLIFF (*.xliff *.xlf)");}
 
+    void setTargetLangCode(const QString& langCode);
+
 private:
     QDomElement unitForPos(int pos) const;
     QDomElement targetForPos(int pos) const;
diff --git a/src/common/languagelistmodel.cpp b/src/common/languagelistmodel.cpp
index f974557..5fbd0f8 100644
--- a/src/common/languagelistmodel.cpp
+++ b/src/common/languagelistmodel.cpp
@@ -107,7 +107,7 @@ QVariant LanguageListModel::data(const QModelIndex& index, int \
                role) const
             if (code.contains('_')) code=QString::fromRawData(code.unicode()+3, \
2).toLower();  if (code!="C")
             {
-                static QString flagPath("l10n/%1/flag.png");
+                static const QString flagPath("l10n/%1/flag.png");
                 path=QStandardPaths::locate(QStandardPaths::GenericDataLocation, \
QStringLiteral("locale/") + flagPath.arg(code));  }
             iconCache[langCode]=QIcon(path);
@@ -124,11 +124,13 @@ QVariant LanguageListModel::data(const QModelIndex& index, int \
role) const  if (displayNames.at(index.row()).length())
             return displayNames.at(index.row());
 #ifndef NOKDE
-            return QVariant::fromValue<QString>(displayNames[index.row()]=KConfigGroup(m_systemLangList,code).readEntry("Name")%" \
("%code%")"); +            return QVariant::fromValue<QString>(
+                displayNames[index.row()]=KConfigGroup(m_systemLangList,code).readEntry("Name")%QStringLiteral(" \
(")%code%')');  #else
         QLocale l(code);
 //        if (l.language()==QLocale::C && code!="C")
-        return QVariant::fromValue<QString>(displayNames[index.row()]=QLocale::languageToString(l.language())%" \
("%code%")"); +        return QVariant::fromValue<QString>(
+            displayNames[index.row()]=QLocale::languageToString(l.language())%QStringLiteral(" \
(")%code%')');  #endif
     }
     return QStringListModel::data(index, role);
@@ -148,3 +150,36 @@ QString LanguageListModel::langCodeForSortModelRow(int row)
 {
     return stringList().at(m_sortModel->mapToSource(m_sortModel->index(row,0)).row());
  }
+
+
+#include "prefs.h"
+#include "project.h"
+#include <klocalizedstring.h>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QComboBox>
+#include <QDialogButtonBox>
+#include <QDialog>
+
+QString getTargetLangCode(const QString& title)
+{
+    QDialog dlg(SettingsController::instance()->mainWindowPtr());
+    dlg.setWindowTitle(title);
+    QHBoxLayout* l=new QHBoxLayout(&dlg);
+    l->addWidget(new QLabel(i18n("Target language:"), &dlg));
+    QComboBox* lc=new QComboBox(&dlg);
+    l->addWidget(lc);
+    lc->setModel(LanguageListModel::instance()->sortModel());
+    lc->setCurrentIndex(LanguageListModel::instance()->sortModelRowForLangCode( \
Project::instance()->targetLangCode() )); +    QDialogButtonBox* btn=new \
QDialogButtonBox(QDialogButtonBox::Ok, &dlg); +    l->addWidget(btn);
+    QObject::connect(btn, SIGNAL(accepted()), &dlg, SLOT(accept()));
+
+    if (!dlg.exec())
+        return Project::instance()->targetLangCode();
+
+    return LanguageListModel::instance()->langCodeForSortModelRow(lc->currentIndex());
 +}
+
+
+
diff --git a/src/common/languagelistmodel.h b/src/common/languagelistmodel.h
index 1cfaca7..7dcf968 100644
--- a/src/common/languagelistmodel.h
+++ b/src/common/languagelistmodel.h
@@ -58,4 +58,6 @@ public:
     QString langCodeForSortModelRow(int);
 };
 
+QString getTargetLangCode(const QString& title);
+
 #endif // LANGUAGELISTMODEL_H
diff --git a/src/editortab.cpp b/src/editortab.cpp
index b20b816..8adf66f 100644
--- a/src/editortab.cpp
+++ b/src/editortab.cpp
@@ -52,6 +52,7 @@
 
 #include "project.h"
 #include "prefs.h"
+#include "languagelistmodel.h"
 #include "kdemacros.h"
 
 #ifndef NOKDE
@@ -859,7 +860,7 @@ bool EditorTab::fileOpen(QString filePath, QString \
suggestedDirPath, bool silent  
 
         //TODO "test" for the name????
-        m_catalog->setActivePhase("test",Project::local()->role());
+        //m_catalog->setActivePhase("test",Project::local()->role());
 //Project
         if (!m_project->isLoaded())
         {
@@ -878,9 +879,14 @@ bool EditorTab::fileOpen(QString filePath, QString \
suggestedDirPath, bool silent  //enforce autosync
             m_syncViewSecondary->mergeOpen(filePath);
             
-            if (!m_project->isLoaded() && m_project->desirablePath().isEmpty())
+            if (!m_project->isLoaded())
             {
-                m_project->setDesirablePath(fileInfo.absolutePath()+QStringLiteral("/index.lokalize"));
 +                if (m_project->desirablePath().isEmpty())
+                    \
m_project->setDesirablePath(fileInfo.absolutePath()+QStringLiteral("/index.lokalize"));
 +
+                if (m_catalog->targetLangCode().isEmpty() /*&& \
m_project->targetLangCode().length()*/) +                    \
m_catalog->setTargetLangCode(getTargetLangCode(fileInfo.fileName())); +
                 //_project->setLangCode(m_catalog->targetLangCode());
             }
                 
@@ -913,6 +919,9 @@ bool EditorTab::saveFileAs()
     QString filePath=QFileDialog::getSaveFileName(this, i18nc("@title:window", "Save \
                File As"),
                                              \
QFileInfo(m_catalog->url()).absolutePath(), m_catalog->fileType());  if \
(filePath.isEmpty()) return false; +    if \
(!Catalog::extIsSupported(filePath)&&m_catalog->url().contains('.')) +        \
filePath+=m_catalog->url().mid(m_catalog->url().lastIndexOf('.')); +
     return saveFile(filePath);
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic