Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with the structure for it - not finished
- Loading branch information
Showing
9 changed files
with
352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*************************************************************************** | ||
qgstranslationcontext.cpp - %{Cpp:License:ClassName} | ||
--------------------- | ||
begin : 23.5.2018 | ||
copyright : (C) 2018 by david | ||
email : [your-email-here] | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgstranslationcontext.h" | ||
|
||
#include <QDir> | ||
#include <QTextStream> | ||
#include <QDomElement> | ||
#include <QDomDocument> | ||
|
||
QgsTranslationContext::QgsTranslationContext() | ||
{} | ||
|
||
QgsProject *QgsTranslationContext::project() const | ||
{ | ||
return mProject; | ||
} | ||
|
||
void QgsTranslationContext::setProject( QgsProject *project ) | ||
{ | ||
mProject = project; | ||
} | ||
|
||
QString QgsTranslationContext::fileName() const | ||
{ | ||
return mFileName; | ||
} | ||
|
||
void QgsTranslationContext::setFileName( const QString &fileName ) | ||
{ | ||
mFileName = fileName; | ||
} | ||
|
||
void QgsTranslationContext::registerTranslation( const QString &context, const QString &source ) | ||
{ | ||
mTranslatableObjects.append( qMakePair( context, source ) ); | ||
} | ||
|
||
void QgsTranslationContext::writeTsFile() | ||
{ | ||
//write xml | ||
QDomDocument doc( QStringLiteral( "TS" ) ); | ||
|
||
for ( QPair < QString, QString > translatableObject : mTranslatableObjects ) | ||
{ | ||
QDomElement contextElement = doc.createElement( QStringLiteral( "context" ) ); | ||
doc.appendChild( contextElement ); | ||
|
||
QDomElement nameElement = doc.createElement( QStringLiteral( "name" ) ); | ||
QDomText nameText = doc.createTextNode( translatableObject.first ); | ||
nameElement.appendChild( nameText ); | ||
contextElement.appendChild( nameElement ); | ||
|
||
QDomElement messageElement = doc.createElement( QStringLiteral( "message" ) ); | ||
contextElement.appendChild( messageElement ); | ||
|
||
QDomElement sourceElement = doc.createElement( QStringLiteral( "source" ) ); | ||
QDomText sourceText = doc.createTextNode( translatableObject.second ); | ||
sourceElement.appendChild( sourceText ); | ||
messageElement.appendChild( sourceElement ); | ||
|
||
QDomElement translationElement = doc.createElement( QStringLiteral( "translation" ) ); | ||
QDomText translationText = doc.createTextNode( QStringLiteral( "testtranslation" ) ); | ||
translationElement.appendChild( translationText ); | ||
messageElement.appendChild( translationElement ); | ||
} | ||
|
||
//write file | ||
QFile tsFile( fileName() ); | ||
tsFile.open( QIODevice::WriteOnly ); | ||
QTextStream stream( &tsFile ); | ||
stream << doc.toString(); | ||
tsFile.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/*************************************************************************** | ||
qgstranslationcontext.h - %{Cpp:License:ClassName} | ||
--------------------- | ||
begin : 23.5.2018 | ||
copyright : (C) 2018 by david | ||
email : [your-email-here] | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSTRANSLATIONCONTEXT_H | ||
#define QGSTRANSLATIONCONTEXT_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgis_sip.h" | ||
#include "qgis.h" | ||
|
||
class QgsProject; | ||
|
||
/** | ||
* \ingroup core | ||
* \class QgsTranslationContext | ||
* \brief dave: write | ||
* | ||
* \since QGIS 3.2 | ||
*/ | ||
|
||
class CORE_EXPORT QgsTranslationContext | ||
{ | ||
public: | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
QgsTranslationContext( ); | ||
|
||
/** | ||
* Returns the project | ||
* \see setProject() | ||
*/ | ||
QgsProject *project() const; | ||
|
||
/** | ||
* Sets the \a project where the translation need to be done for | ||
* | ||
* \see project() | ||
*/ | ||
void setProject( QgsProject *project ); | ||
|
||
/** | ||
* Returns the TS fileName | ||
* \see setFileName() | ||
*/ | ||
QString fileName() const; | ||
|
||
/** | ||
* Sets the \a name of the TS file | ||
* | ||
* \see fileName() | ||
*/ | ||
void setFileName( const QString &fileName ); | ||
|
||
/** | ||
* Registers the \a string to be translated | ||
* | ||
* \param translationString name and path of the object need to be translated | ||
* \param layerName the name of the layer | ||
*/ | ||
void registerTranslation( const QString &context, const QString &source ); | ||
|
||
/** | ||
* Writes the Ts-file | ||
*/ | ||
void writeTsFile( ); | ||
|
||
private: | ||
|
||
QgsProject *mProject; | ||
QString mFileName; | ||
QList < QPair< QString, QString > > mTranslatableObjects; | ||
|
||
}; | ||
|
||
#endif // QGSTRANSLATIONCONTEXT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.