mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Issue #261: About translation to Korean
This commit is contained in:
@@ -153,6 +153,8 @@ add_library(Pdf4QtLibCore SHARED
|
||||
sources/pdfpagecontenteditorprocessor.cpp
|
||||
sources/pdfpagecontenteditorcontentstreambuilder.h
|
||||
sources/pdfpagecontenteditorcontentstreambuilder.cpp
|
||||
sources/pdfapplicationtranslator.h
|
||||
sources/pdfapplicationtranslator.cpp
|
||||
)
|
||||
|
||||
include(GenerateExportHeader)
|
||||
|
166
Pdf4QtLibCore/sources/pdfapplicationtranslator.cpp
Normal file
166
Pdf4QtLibCore/sources/pdfapplicationtranslator.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
// Copyright (C) 2025-2025 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pdfapplicationtranslator.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QMetaEnum>
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
PDFApplicationTranslator::PDFApplicationTranslator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PDFApplicationTranslator::~PDFApplicationTranslator()
|
||||
{
|
||||
uninstallTranslator();
|
||||
}
|
||||
|
||||
PDFApplicationTranslator::ELanguage PDFApplicationTranslator::getLanguage() const
|
||||
{
|
||||
return m_language;
|
||||
}
|
||||
|
||||
void PDFApplicationTranslator::installTranslator()
|
||||
{
|
||||
QDir applicationDirectory(QCoreApplication::applicationDirPath());
|
||||
applicationDirectory.cd("translations");
|
||||
QString translationPath = applicationDirectory.absolutePath();
|
||||
|
||||
Q_ASSERT(!m_translator);
|
||||
m_translator = new QTranslator();
|
||||
|
||||
switch (m_language)
|
||||
{
|
||||
case E_LANGUAGE_AUTOMATIC_SELECTION:
|
||||
{
|
||||
if (m_translator->load(QLocale::system(), "PDF4QT", "_", translationPath))
|
||||
{
|
||||
QCoreApplication::installTranslator(m_translator);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete m_translator;
|
||||
m_translator = nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case E_LANGUAGE_ENGLISH:
|
||||
case E_LANGUAGE_CZECH:
|
||||
case E_LANGUAGE_GERMAN:
|
||||
case E_LANGUAGE_KOREAN:
|
||||
case E_LANGUAGE_SPANISH:
|
||||
{
|
||||
QString languageFileName = getLanguageFileName();
|
||||
|
||||
if (m_translator->load(languageFileName, translationPath))
|
||||
{
|
||||
QCoreApplication::installTranslator(m_translator);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete m_translator;
|
||||
m_translator = nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
delete m_translator;
|
||||
m_translator = nullptr;
|
||||
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PDFApplicationTranslator::uninstallTranslator()
|
||||
{
|
||||
if (m_translator)
|
||||
{
|
||||
QCoreApplication::removeTranslator(m_translator);
|
||||
|
||||
delete m_translator;
|
||||
m_translator = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void PDFApplicationTranslator::loadSettings()
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<ELanguage>();
|
||||
std::string languageKeyString = loadLanguageKeyFromSettings().toStdString();
|
||||
std::optional<quint64> value = metaEnum.keyToValue(languageKeyString.c_str());
|
||||
m_language = static_cast<ELanguage>(value.value_or(E_LANGUAGE_AUTOMATIC_SELECTION));
|
||||
}
|
||||
|
||||
void PDFApplicationTranslator::saveSettings()
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<ELanguage>();
|
||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
settings.beginGroup("Language");
|
||||
settings.setValue("language", metaEnum.valueToKey(m_language));
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void PDFApplicationTranslator::setLanguage(ELanguage newLanguage)
|
||||
{
|
||||
m_language = newLanguage;
|
||||
}
|
||||
|
||||
QString PDFApplicationTranslator::loadLanguageKeyFromSettings()
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<ELanguage>();
|
||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
settings.beginGroup("Language");
|
||||
QString languageKey = settings.value("language", metaEnum.valueToKey(E_LANGUAGE_AUTOMATIC_SELECTION)).toString();
|
||||
settings.endGroup();
|
||||
|
||||
return languageKey;
|
||||
}
|
||||
|
||||
QString PDFApplicationTranslator::getLanguageFileName() const
|
||||
{
|
||||
switch (m_language)
|
||||
{
|
||||
case E_LANGUAGE_ENGLISH:
|
||||
return QLatin1String("PDF4QT_en.qm");
|
||||
case E_LANGUAGE_CZECH:
|
||||
return QLatin1String("PDF4QT_cs.qm");
|
||||
case E_LANGUAGE_GERMAN:
|
||||
return QLatin1String("PDF4QT_de.qm");
|
||||
case E_LANGUAGE_KOREAN:
|
||||
return QLatin1String("PDF4QT_es.qm");
|
||||
case E_LANGUAGE_SPANISH:
|
||||
return QLatin1String("PDF4QT_ko.qm");
|
||||
break;
|
||||
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
} // namespace
|
66
Pdf4QtLibCore/sources/pdfapplicationtranslator.h
Normal file
66
Pdf4QtLibCore/sources/pdfapplicationtranslator.h
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright (C) 2025-2025 Jakub Melka
|
||||
//
|
||||
// This file is part of PDF4QT.
|
||||
//
|
||||
// PDF4QT is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// PDF4QT is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef PDFAPPLICATIONTRANSLATOR_H
|
||||
#define PDFAPPLICATIONTRANSLATOR_H
|
||||
|
||||
#include "pdfglobal.h"
|
||||
|
||||
#include <QTranslator>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
class PDF4QTLIBCORESHARED_EXPORT PDFApplicationTranslator
|
||||
{
|
||||
Q_GADGET
|
||||
|
||||
public:
|
||||
explicit PDFApplicationTranslator();
|
||||
~PDFApplicationTranslator();
|
||||
|
||||
enum ELanguage
|
||||
{
|
||||
E_LANGUAGE_AUTOMATIC_SELECTION,
|
||||
E_LANGUAGE_ENGLISH,
|
||||
E_LANGUAGE_CZECH,
|
||||
E_LANGUAGE_GERMAN,
|
||||
E_LANGUAGE_KOREAN,
|
||||
E_LANGUAGE_SPANISH
|
||||
};
|
||||
|
||||
Q_ENUM(ELanguage)
|
||||
|
||||
void installTranslator();
|
||||
void uninstallTranslator();
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
|
||||
ELanguage getLanguage() const;
|
||||
void setLanguage(ELanguage newLanguage);
|
||||
|
||||
private:
|
||||
QString loadLanguageKeyFromSettings();
|
||||
QString getLanguageFileName() const;
|
||||
|
||||
QTranslator* m_translator = nullptr;
|
||||
ELanguage m_language = E_LANGUAGE_AUTOMATIC_SELECTION;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // PDFAPPLICATIONTRANSLATOR_H
|
@@ -161,7 +161,7 @@ void PDFDocumentSanitizer::performSanitizeMetadata()
|
||||
|
||||
PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Unknown, objects.begin(), objects.end(), processEntry);
|
||||
m_storage.setObjects(qMove(objects));
|
||||
Q_EMIT sanitizationProgress(tr("Metadata streams removed: %1").arg(counter));
|
||||
Q_EMIT sanitizationProgress(tr("Metadata streams removed: %1").arg(counter.load()));
|
||||
}
|
||||
|
||||
void PDFDocumentSanitizer::performSanitizeOutline()
|
||||
|
@@ -23,8 +23,8 @@
|
||||
#include "pdfconstants.h"
|
||||
#include "pdfdocumentbuilder.h"
|
||||
#include "pdfstreamfilters.h"
|
||||
#include "pdfdbgheap.h"
|
||||
#include "pdfdocumentwriter.h"
|
||||
#include "pdfdbgheap.h"
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
@@ -194,7 +194,7 @@ bool PDFOptimizer::performDereferenceSimpleObjects()
|
||||
|
||||
PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Unknown, objects.begin(), objects.end(), processEntry);
|
||||
m_storage.setObjects(qMove(objects));
|
||||
Q_EMIT optimizationProgress(tr("Simple objects dereferenced and embedded: %1").arg(counter));
|
||||
Q_EMIT optimizationProgress(tr("Simple objects dereferenced and embedded: %1").arg(counter.load()));
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -213,7 +213,7 @@ bool PDFOptimizer::performRemoveNullObjects()
|
||||
|
||||
PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Unknown, objects.begin(), objects.end(), processEntry);
|
||||
m_storage.setObjects(qMove(objects));
|
||||
Q_EMIT optimizationProgress(tr("Null objects entries from dictionaries removed: %1").arg(counter));
|
||||
Q_EMIT optimizationProgress(tr("Null objects entries from dictionaries removed: %1").arg(counter.load()));
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ bool PDFOptimizer::performRemoveUnusedObjects()
|
||||
|
||||
PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Unknown, range.begin(), range.end(), processEntry);
|
||||
m_storage.setObjects(qMove(objects));
|
||||
Q_EMIT optimizationProgress(tr("Unused objects removed: %1").arg(counter));
|
||||
Q_EMIT optimizationProgress(tr("Unused objects removed: %1").arg(counter.load()));
|
||||
|
||||
return counter > 0;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ bool PDFOptimizer::performMergeIdenticalObjects()
|
||||
}
|
||||
|
||||
m_storage.setObjects(qMove(objects));
|
||||
Q_EMIT optimizationProgress(tr("Identical objects merged: %1").arg(counter));
|
||||
Q_EMIT optimizationProgress(tr("Identical objects merged: %1").arg(counter.load()));
|
||||
|
||||
return counter > 0;
|
||||
}
|
||||
@@ -457,7 +457,7 @@ bool PDFOptimizer::performRecompressFlateStreams()
|
||||
|
||||
PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Unknown, objects.begin(), objects.end(), processEntry);
|
||||
m_storage.setObjects(qMove(objects));
|
||||
Q_EMIT optimizationProgress(tr("Bytes saved by recompressing stream: %1").arg(bytesSaved));
|
||||
Q_EMIT optimizationProgress(tr("Bytes saved by recompressing stream: %1").arg(bytesSaved.load()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user