diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fe45f23 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.16) +project(WinoMailQt VERSION 1.0.0 LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Find Qt components +find_package(Qt6 COMPONENTS Core Gui Widgets Network Sql WebEngineWidgets REQUIRED) + +# Find optional libraries (example: libetpan, gmime) +# find_package(PkgConfig REQUIRED) +# pkg_check_modules(LIBETPAN REQUIRED libetpan) +# pkg_check_modules(GMIME REQUIRED gmime-2.6) + +# Include directories +include_directories(${PROJECT_SOURCE_DIR}/src) + +# Source files - we will add them later +set(SRC_FILES + src/core/translator.cpp + src/services/synchronizer.cpp + # placeholder +) + +# Executable +add_executable(wino-mail-qt ${SRC_FILES}) + +# Link Qt +target_link_libraries(wino-mail-qt PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Network Qt6::Sql Qt6::WebEngineWidgets) + +# If using external libs +# target_link_libraries(wino-mail-qt PRIVATE ${LIBETPAN_LIBRARIES} ${GMIME_LIBRARIES}) +# target_include_directories(wino-mail-qt PRIVATE ${LIBETPAN_INCLUDE_DIRS} ${GMIME_INCLUDE_DIRS}) + +# Install (optional) +install(TARGETS wino-mail-qt DESTINATION bin) \ No newline at end of file diff --git a/resources/translations/en_US/resources.json b/resources/translations/en_US/resources.json new file mode 100644 index 0000000..6053100 --- /dev/null +++ b/resources/translations/en_US/resources.json @@ -0,0 +1,9 @@ +{ + "appName": "Wino Mail", + "welcomeMessage": "Welcome to Wino Mail", + "settings": "Settings", + "inbox": "Inbox", + "sent": "Sent", + "drafts": "Drafts", + "trash": "Trash" +} \ No newline at end of file diff --git a/src/core/translator.cpp b/src/core/translator.cpp new file mode 100644 index 0000000..e3b97a2 --- /dev/null +++ b/src/core/translator.cpp @@ -0,0 +1,59 @@ +#include "translator.h" +#include +#include +#include +#include + +Translator& Translator::instance() +{ + static Translator instance; + return instance; +} + +bool Translator::loadLanguage(const QString& langCode) +{ + QMutexLocker locker(&m_mutex); + m_translations.clear(); + + QString filePath = QStringLiteral("resources/translations/%1/resources.json").arg(langCode); + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "Failed to open translation file:" << filePath; + return false; + } + + QByteArray jsonData = file.readAll(); + file.close(); + + QJsonParseError parseError; + QJsonDocument doc = QJsonDocument::fromJson(jsonData, &parseError); + if (parseError.error != QJsonParseError::NoError) { + qWarning() << "Failed to parse translation JSON:" << parseError.errorString(); + return false; + } + + if (!doc.isObject()) { + qWarning() << "Translation JSON is not an object"; + return false; + } + + QJsonObject obj = doc.object(); + for (auto it = obj.begin(); it != obj.end(); ++it) { + if (it.value().isString()) { + m_translations.insert(it.key(), it.value().toString()); + } + } + + m_currentLang = langCode; + return true; +} + +QString Translator::tr(const QString& key) const +{ + QMutexLocker locker(&m_mutex); + auto it = m_translations.find(key); + if (it != m_translations.end()) { + return it.value(); + } + return key; // fallback to key +} \ No newline at end of file diff --git a/src/core/translator.h b/src/core/translator.h new file mode 100644 index 0000000..508a254 --- /dev/null +++ b/src/core/translator.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include + +class Translator +{ +public: + static Translator& instance(); + ~Translator() = default; + + // Load translation file for given language code (e.g., "en_US") + bool loadLanguage(const QString& langCode); + + // Translate a key, returns translated string or key if not found + QString tr(const QString& key) const; + + // Get current language code + QString currentLanguage() const { return m_currentLang; } + +private: + Translator() = default; + Q_DISABLE_COPY(Translator) + + QMap m_translations; + QString m_currentLang; + mutable QMutex m_mutex; +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..880bd0e --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,19 @@ +#include +#include +#include "core/translator.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + // Load English translation + Translator& translator = Translator::instance(); + if (!translator.loadLanguage("en_US")) { + qWarning() << "Failed to load translation"; + } + + qDebug() << translator.tr("appName"); + qDebug() << translator.tr("welcomeMessage"); + + return 0; +} \ No newline at end of file