Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Müller <fmueller@owncloud.com>2021-03-16 17:46:41 +0300
committerFabian Müller <80399010+fmoc@users.noreply.github.com>2021-03-31 12:43:26 +0300
commitc6bfd2ba59358a09ff1e0e0cc8c79c10addb77d4 (patch)
treeedd842ed1bbef5824624d4152d4b4dc29bd627ae /src/gui/translations.cpp
parent3ecdfcc97636c3fb160aa86a12c7cb67b6d682f6 (diff)
Move translations-related functionaltiy into new utility namespace
Diffstat (limited to 'src/gui/translations.cpp')
-rw-r--r--src/gui/translations.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/gui/translations.cpp b/src/gui/translations.cpp
new file mode 100644
index 000000000..4b2529f43
--- /dev/null
+++ b/src/gui/translations.cpp
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
+ * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ * Copyright (C) by Fabian Müller <fmueller@owncloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+#include "translations.h"
+
+#include "config.h"
+#include "theme.h"
+
+#include <QApplication>
+#include <QLoggingCategory>
+#include <QDir>
+#include <QDirIterator>
+
+namespace OCC {
+
+namespace Translations {
+
+ Q_LOGGING_CATEGORY(lcTranslations, "gui.translations", QtInfoMsg)
+
+ const QString translationsFilePrefix()
+ {
+ return QStringLiteral("client_");
+ }
+
+ const QString translationsFileSuffix()
+ {
+ return QStringLiteral(".qm");
+ }
+
+ QString applicationTrPath()
+ {
+ QString devTrPath = qApp->applicationDirPath() + QString::fromLatin1("/../src/gui/");
+ if (QDir(devTrPath).exists()) {
+ // might miss Qt, QtKeyChain, etc.
+ qCWarning(lcTranslations) << "Running from build location! Translations may be incomplete!";
+ return devTrPath;
+ }
+#if defined(Q_OS_WIN)
+ return QApplication::applicationDirPath();
+#elif defined(Q_OS_MAC)
+ return QApplication::applicationDirPath() + QLatin1String("/../Resources/Translations"); // path defaults to app dir.
+#elif defined(Q_OS_UNIX)
+ return QStringLiteral(SHAREDIR "/" APPLICATION_EXECUTABLE "/i18n/");
+#endif
+ }
+
+ QSet<QString> listAvailableTranslations()
+ {
+ QSet<QString> availableTranslations;
+
+ // calculate a glob pattern which can be used in the iterator below to match only translations files
+ QString pattern = translationsFilePrefix() + "*" + translationsFileSuffix();
+
+ QDirIterator it(Translations::applicationTrPath(), QStringList() << pattern);
+
+ while (it.hasNext()) {
+ // extract locale part from filename
+ // of course, this method relies on the filenames to be accurate
+ const auto fileName = QFileInfo(it.next()).fileName();
+ const auto localePartLength = fileName.length() - translationsFileSuffix().length() - translationsFilePrefix().length();
+ QString localeName = fileName.mid(translationsFilePrefix().length(), localePartLength);
+
+ availableTranslations.insert(localeName);
+ }
+
+ return availableTranslations;
+ }
+
+} // namespace Translations
+
+} // namespace OCC