4
0
mirror of https://github.com/QuasarApp/QuasarAppLib.git synced 2025-05-04 21:49:42 +00:00

addd addLocation method

This commit is contained in:
Andrei Yankovich 2021-05-05 15:44:21 +03:00
parent da1df65ada
commit 621fc4a5d0
2 changed files with 18 additions and 1 deletions

@ -24,7 +24,7 @@ bool Locales::setLocalePrivate(const QLocale &locale) {
QFileInfoList qmFiles;
for (const auto &location: qAsConst(_locations)) {
qmFiles += QDir(location).entryInfoList({"*" + locale.bcp47Name() + "*.qm"}, QDir::Files);
qmFiles += QDir(location).entryInfoList({"*" + locale.bcp47Name() + "*.qm"}, QDir::Files);
}
for (const auto & file: qAsConst(qmFiles)) {
@ -80,6 +80,15 @@ void Locales::removeOldTranslation() {
}
}
void Locales::addLocationPrivate(const QString &location) {
_locations += location;
}
void Locales::addLocation(const QString &location) {
auto obj = instance();
obj->addLocationPrivate(location);
}
Locales::~Locales() {
removeOldTranslation();
}

@ -53,6 +53,13 @@ public:
*/
static bool init(const QLocale &locale = QLocale::system(),
const QSet<QString> & location = {});
/**
* @brief addLocation This method add location for qm files. Use This method if you create a own library with translations supports.
* @param location This is a new location of the qm files.
*/
static void addLocation(const QString& location);
/**
* @brief instance This method return pointer to the Locales service.
* @return return pointer to the Locales static object
@ -73,6 +80,7 @@ private:
bool initPrivate(const QLocale &locale = QLocale::system(),
const QSet<QString> &location = {});
void removeOldTranslation();
void addLocationPrivate(const QString& location);
QSet<QString> _locations;
QList<QTranslator *> _translations;