aboutsummaryrefslogtreecommitdiff
path: root/src/localization.cpp
blob: 07b69f5185d4debe94984be788b6570f37e4657a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "kristall.hpp"

#include <QDebug>
#include <QLibraryInfo>

#include "localization.hpp"

Localization::Localization(QObject *parent) : QObject(parent)
{

}

void Localization::setLocale(const std::optional<QLocale> &locale)
{
    this->locale = locale;

    if(this->locale != std::nullopt)
        this->translate(*this->locale);
    else
        this->translate(QLocale());
}

void Localization::translate(const QLocale &locale)
{
    this->qt.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    this->kristall.load(locale, "kristall", "_", ":/i18n");

    emit this->translationChanged();

    qDebug() << "new locale is" << locale.bcp47Name() << locale.nativeLanguageName();
}