added support method for getting current languages values

This commit is contained in:
Andrei Yankovich 2022-02-21 14:45:00 +03:00
parent b6d3b0f72e
commit f466dd6437
2 changed files with 21 additions and 0 deletions

View File

@ -40,9 +40,16 @@ bool Locales::setLocalePrivate(const QLocale &locale) {
} }
emit sigTranslationChanged(); emit sigTranslationChanged();
_currentLocate = locale;
return _translations.size(); return _translations.size();
} }
const QLocale &Locales::currentLocate() {
auto obj = instance();
return obj->currentLocatePrivate();
}
bool Locales::setLocale(const QLocale &locale) { bool Locales::setLocale(const QLocale &locale) {
auto obj = instance(); auto obj = instance();
return obj->setLocalePrivate(locale); return obj->setLocalePrivate(locale);
@ -78,12 +85,17 @@ void Locales::removeOldTranslation() {
QCoreApplication::removeTranslator(tr); QCoreApplication::removeTranslator(tr);
delete tr; delete tr;
} }
_translations.clear();
} }
void Locales::addLocationPrivate(const QString &location) { void Locales::addLocationPrivate(const QString &location) {
_locations += location; _locations += location;
} }
const QLocale &Locales::currentLocatePrivate() const {
return _currentLocate;
}
void Locales::addLocation(const QString &location) { void Locales::addLocation(const QString &location) {
auto obj = instance(); auto obj = instance();
obj->addLocationPrivate(location); obj->addLocationPrivate(location);

View File

@ -66,6 +66,12 @@ public:
*/ */
static Locales *instance(); static Locales *instance();
/**
* @brief currentLocate This method return current locate of applicatuon.
* @return current or last sets locate of applciation.
*/
static const QLocale &currentLocate();
signals: signals:
/** /**
* @brief sigTranslationChanged Emited when set new locale for application. * @brief sigTranslationChanged Emited when set new locale for application.
@ -82,6 +88,9 @@ private:
void removeOldTranslation(); void removeOldTranslation();
void addLocationPrivate(const QString& location); void addLocationPrivate(const QString& location);
const QLocale &currentLocatePrivate() const;
QLocale _currentLocate;
QSet<QString> _locations; QSet<QString> _locations;
QList<QTranslator *> _translations; QList<QTranslator *> _translations;