Page MenuHomePhorge

No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c94e6ac..efcaf6b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,105 +1,99 @@
-set(KAZV_DATA_DIR ${KDE_INSTALL_DATADIR}/kazv)
-set(KAZV_L10N_DIR ${KAZV_DATA_DIR}/l10n)
if(WIN32)
set(KAZV_IS_WINDOWS 1)
else()
set(KAZV_IS_WINDOWS 0)
endif()
-configure_file(kazv-path-config.hpp.in kazv-path-config.hpp)
configure_file(kazv-version.cpp.in kazv-version.cpp)
configure_file(kazv-platform.hpp.in kazv-platform.hpp)
configure_file(kazv-defs.hpp.in kazv-defs.hpp)
set(kazvprivlib_SRCS
qt-job-handler.cpp
qt-job.cpp
${CMAKE_CURRENT_BINARY_DIR}/kazv-version.cpp
matrix-sdk.cpp
matrix-room.cpp
matrix-room-list.cpp
matrix-room-timeline.cpp
matrix-room-member.cpp
matrix-room-member-list-model.cpp
matrix-event-reader.cpp
matrix-event-reader-list-model.cpp
matrix-event.cpp
matrix-link.cpp
meta-types.cpp
l10n-provider.cpp
qt-rand-adapter.cpp
helper.cpp
matrix-promise.cpp
kazv-util.cpp
matrix-sticker-pack.cpp
matrix-sticker.cpp
matrix-sticker-pack-list.cpp
matrix-sticker-pack-source.cpp
matrix-user-given-attrs-map.cpp
qt-promise-handler.cpp
device-mgmt/matrix-device.cpp
device-mgmt/matrix-device-list.cpp
kazv-config.cpp
+ kazv-path-config.cpp
kazv-io-manager.cpp
kazv-io-job.cpp
kazv-file.cpp
upload-job-model.cpp
kazv-markdown.cpp
shortcuts/shortcut-util.cpp
register-types.cpp
)
ecm_qt_declare_logging_category(kazvprivlib_SRCS
HEADER kazv-log.hpp
IDENTIFIER kazvLog
CATEGORY_NAME moe.kazv.mxc.kazv
)
add_library(kazvprivlib STATIC ${kazvprivlib_SRCS})
target_link_libraries(kazvprivlib PUBLIC
libkazv::kazvall
Qt${QT_MAJOR_VERSION}::Core
Qt${QT_MAJOR_VERSION}::Network
Threads::Threads
Qt${QT_MAJOR_VERSION}::Gui
Qt${QT_MAJOR_VERSION}::Qml
Qt${QT_MAJOR_VERSION}::Quick
Qt${QT_MAJOR_VERSION}::QuickControls2
Qt${QT_MAJOR_VERSION}::Svg
Qt${QT_MAJOR_VERSION}::Concurrent
Qt${QT_MAJOR_VERSION}::Widgets
KF${KF_MAJOR_VERSION}::ConfigCore KF${KF_MAJOR_VERSION}::KIOCore
KF${KF_MAJOR_VERSION}::Notifications
${CMARK_TARGET_NAME}
)
target_include_directories(kazvprivlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(kazvprivlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/device-mgmt)
set(kazv_SRCS
main.cpp
resources.qrc
+ l10n/translations.qrc
)
add_executable(kazv ${kazv_SRCS})
target_link_libraries(kazv
PRIVATE
kazvprivlib
)
set(kazv_INSTALL_ARGS ${KF_INSTALL_TARGETS_DEFAULT_ARGS})
if(NOT kazv_INSTALL_ARGS)
set(kazv_INSTALL_ARGS ${KF${KF_MAJOR_VERSION}_INSTALL_TARGETS_DEFAULT_ARGS})
endif()
install(TARGETS kazv ${kazv_INSTALL_ARGS})
-install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/l10n/
- DESTINATION ${KAZV_L10N_DIR}
- FILES_MATCHING PATTERN "*.ftl"
- PATTERN "*.json"
- )
add_subdirectory(tests)
diff --git a/src/kazv-path-config.cpp b/src/kazv-path-config.cpp
new file mode 100644
index 0000000..b9e0bab
--- /dev/null
+++ b/src/kazv-path-config.cpp
@@ -0,0 +1,21 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2021-2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <kazv-defs.hpp>
+#include "kazv-path-config.hpp"
+#include <QCoreApplication>
+#include <QStandardPaths>
+
+QString appDir()
+{
+ return QCoreApplication::applicationDirPath();
+}
+
+QString kazvUserDataDir()
+{
+ static QString dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
+ return dir;
+}
diff --git a/src/kazv-path-config.hpp b/src/kazv-path-config.hpp
new file mode 100644
index 0000000..78f2f5f
--- /dev/null
+++ b/src/kazv-path-config.hpp
@@ -0,0 +1,14 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2021-2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <kazv-defs.hpp>
+#include <QString>
+
+QString appDir();
+
+QString kazvUserDataDir();
diff --git a/src/kazv-path-config.hpp.in b/src/kazv-path-config.hpp.in
deleted file mode 100644
index 0af7d37..0000000
--- a/src/kazv-path-config.hpp.in
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * This file is part of kazv.
- * SPDX-FileCopyrightText: 2021-2024 tusooa <tusooa@kazv.moe>
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-#pragma once
-
-#include <kazv-defs.hpp>
-
-#include <QString>
-#include <QCoreApplication>
-#include <QStandardPaths>
-#include <QDir>
-#include <filesystem>
-
-namespace KazvPathConfigDetail
-{
- inline QString dirName(QString dir)
- {
- QDir d(dir);
- d.cdUp();
- return d.absolutePath();
- }
-
- inline QString pathJoin(QString dir, QString file)
- {
- using StdPath = std::filesystem::path;
-
- return QString::fromStdString((StdPath(dir.toStdString()) / StdPath(file.toStdString())).string());
- }
-}
-
-inline QString appDir()
-{
- static QString dir = QCoreApplication::applicationDirPath();
- return dir;
-}
-
-inline QString installPrefixDir()
-{
- static QString dir = KazvPathConfigDetail::dirName(appDir());
- return dir;
-}
-
-inline QString kazvDataDir()
-{
- static QString dir = KazvPathConfigDetail::pathJoin(installPrefixDir(), QString(R"xxx(${KAZV_DATA_DIR})xxx"));
- return dir;
-}
-
-inline QString kazvL10nDir()
-{
- static QString dir = KazvPathConfigDetail::pathJoin(installPrefixDir(), QString(R"xxx(${KAZV_L10N_DIR})xxx"));
- return dir;
-}
-
-inline QString kazvUserDataDir()
-{
- static QString dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
- return dir;
-}
diff --git a/src/l10n-provider.cpp b/src/l10n-provider.cpp
index d785719..ddda561 100644
--- a/src/l10n-provider.cpp
+++ b/src/l10n-provider.cpp
@@ -1,118 +1,118 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2021-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <kazv-defs.hpp>
#include "l10n-provider.hpp"
#include <optional>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStringBuilder>
+#include <QDir>
#include <stdexcept>
#include "kazv-path-config.hpp"
static QString l10nConfigFile()
{
- static QString file = KazvPathConfigDetail::pathJoin(kazvL10nDir(), QString("config.json"));
- return file;
+ return QString(":/l10n/config.json");
}
static QString dirForLocale(QString locale)
{
- return KazvPathConfigDetail::pathJoin(kazvL10nDir(), locale);
+ return QString(":/l10n/") + locale;
}
static QString readWholeFile(QString path)
{
QFile f(path);
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
throw std::runtime_error("Cannot open " + path.toStdString() + " for reading.");
}
QTextStream stream(&f);
#if KAZV_KF_QT_MAJOR_VERSION == 5
stream.setCodec("UTF-8");
#else
stream.setEncoding(QStringConverter::Utf8);
#endif
return stream.readAll();
}
struct L10nProviderPrivate
{
std::optional<QJsonObject> cachedLocaleToNameMap;
QMap<QString, QString> cachedFtlData;
void cacheAvailableLocales();
void cacheFtlDataFor(QString locale);
};
void L10nProviderPrivate::cacheAvailableLocales()
{
if (cachedLocaleToNameMap.has_value()) {
return;
} else {
auto fn = l10nConfigFile();
auto content = readWholeFile(fn);
auto j = QJsonDocument::fromJson(content.toUtf8());
auto availableLocales = j["availableLocales"].toObject();
cachedLocaleToNameMap = std::move(availableLocales);
}
}
void L10nProviderPrivate::cacheFtlDataFor(QString locale)
{
if (cachedFtlData.contains(locale)) {
return;
}
auto dn = dirForLocale(locale);
auto files = QDir(dn).entryInfoList(QStringList{QStringLiteral("*.ftl")}, QDir::NoFilter, QDir::Name);
QString s;
const QString newline = "\n";
for (auto f : files) {
auto fn = f.absoluteFilePath();
s.append(readWholeFile(fn));
s.append(newline);
}
cachedFtlData[locale] = s;
}
L10nProvider::L10nProvider(QObject *parent)
: QObject(parent)
, m_d(new L10nProviderPrivate)
{
}
L10nProvider::~L10nProvider() = default;
QStringList L10nProvider::availableLocaleCodes()
{
m_d->cacheAvailableLocales();
return m_d->cachedLocaleToNameMap.value().keys();
}
QJsonObject L10nProvider::availableLocaleToNameMap()
{
m_d->cacheAvailableLocales();
return m_d->cachedLocaleToNameMap.value();
}
QJsonObject L10nProvider::getFtlData(QStringList desiredLocales)
{
QJsonObject data;
for (auto locale : desiredLocales) {
m_d->cacheFtlDataFor(locale);
data[locale] = m_d->cachedFtlData[locale];
}
return data;
}
diff --git a/src/l10n/translations.qrc b/src/l10n/translations.qrc
new file mode 100644
index 0000000..5069a6f
--- /dev/null
+++ b/src/l10n/translations.qrc
@@ -0,0 +1,14 @@
+<RCC>
+ <qresource prefix="/l10n">
+ <file>config.json</file>
+ <file>en/010-kazv-terms.ftl</file>
+ <file>en/100-ui.ftl</file>
+ <file>cmn-Hans/010-kazv-terms.ftl</file>
+ <file>cmn-Hans/100-ui.ftl</file>
+ <file>hi/010-kazv-terms.ftl</file>
+ <file>hi/100-ui.ftl</file>
+ <!-- The following is used for the systems where symlink is not well-supported. -->
+ <file alias="zh-Hans/010-kazv-terms.ftl">cmn-Hans/010-kazv-terms.ftl</file>
+ <file alias="zh-Hans/100-ui.ftl">cmn-Hans/100-ui.ftl</file>
+ </qresource>
+</RCC>

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 6:40 AM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39696
Default Alt Text
(9 KB)

Event Timeline