Skip to content

Commit

Permalink
#282 Loading translation from config
Browse files Browse the repository at this point in the history
  • Loading branch information
francescmm committed Oct 28, 2023
1 parent 64618af commit de3ec62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/big_widgets/ConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ ConfigWidget::ConfigWidget(const QSharedPointer<GitBase> &git, QWidget *parent)
else if (mergeStrategyFF.contains("true", Qt::CaseInsensitive))
ui->cbPullStrategy->setCurrentIndex(2);

fillLanguageBox();

connect(ui->cbPullStrategy, SIGNAL(currentIndexChanged(int)), this, SLOT(onPullStrategyChanged(int)));

connect(ui->buttonGroup, qOverload<QAbstractButton *>(&QButtonGroup::buttonClicked), this,
Expand Down Expand Up @@ -221,8 +223,6 @@ ConfigWidget::ConfigWidget(const QSharedPointer<GitBase> &git, QWidget *parent)
size = calculateDirSize(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
ui->lCacheSize->setText(QString("%1 KB").arg(size));

fillLanguageBox();

mPluginsDownloader->checkAvailablePlugins();
}

Expand Down Expand Up @@ -393,7 +393,7 @@ void ConfigWidget::saveConfig()
emit reloadDiffFont();
emit commitTitleMaxLenghtChanged();

if (mShowResetMsg)
if (mShowResetMsg || qobject_cast<QComboBox*>(sender()) == ui->cbLanguage)
{
QMessageBox::information(this, tr("Reset needed!"),
tr("You need to restart GitQlient to see the changes in the styles applied."));
Expand Down Expand Up @@ -677,7 +677,7 @@ void ConfigWidget::loadPlugins(QMap<QString, QObject *> plugins)

void ConfigWidget::fillLanguageBox() const
{
const auto currentLanguage = GitQlientSettings().globalValue("UILanguage", "gitqlient_en.qm").toString();
const auto currentLanguage = GitQlientSettings().globalValue("UILanguage", "gitqlient_en").toString();

const auto list = QDir(":translations", "gitqlient_*.qm").entryList();
QDirIterator trIter(":translations", QStringList() << "gitqlient_*.qm");
Expand All @@ -686,12 +686,13 @@ void ConfigWidget::fillLanguageBox() const
{
trIter.next();

const auto name = trIter.fileName();
auto start = name.indexOf('_') + 1;
auto end = name.lastIndexOf('.');
QLocale tmpLocale(name.mid(start, end - start));
QString languageItem = QLocale::languageToString(tmpLocale.language()) + QLatin1String(" (")
+ QLocale::countryToString(tmpLocale.country()) + QLatin1Char(')');
auto name = trIter.fileName();
name.remove(".qm");

const auto lang = name.mid(name.indexOf('_') + 1);
QLocale tmpLocale(lang);
const auto languageItem = QString::fromUtf8("%1 (%2)").arg(QLocale::languageToString(tmpLocale.language()),
QLocale::countryToString(tmpLocale.country()));

ui->cbLanguage->addItem(languageItem, name);

Expand Down
7 changes: 4 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QTranslator>

#include <GitQlient.h>
#include <GitQlientSettings.h>
#include <QLogger.h>

using namespace QLogger;
Expand All @@ -29,11 +30,11 @@ int main(int argc, char *argv[])
QFontDatabase::addApplicationFont(":/DejaVuSans");
QFontDatabase::addApplicationFont(":/DejaVuSansMono");

const auto languageFile = GitQlientSettings().globalValue("UILanguage","gitqlient_en").toString();
QTranslator qtTranslator;
if (qtTranslator.load(QLocale(), QString::fromUtf8("gitqlient"), QString::fromUtf8("_"), QString::fromUtf8(":/translations/")))
{

if (qtTranslator.load(languageFile, QString::fromUtf8(":/translations/")))
app.installTranslator(&qtTranslator);
}

QStringList repos;
if (GitQlient::parseArguments(app.arguments(), &repos))
Expand Down

0 comments on commit de3ec62

Please sign in to comment.