i18n (en and fr).

main
bog 2023-12-27 05:26:44 +01:00
parent 470e656713
commit 6e4b01972a
6 changed files with 64 additions and 3 deletions

20
i18n/pix_en.ts Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>QAction</name>
<message>
<location filename="../src/gui/Window.cpp" line="25"/>
<source>quit</source>
<translation>Quit</translation>
</message>
</context>
<context>
<name>QMenu</name>
<message>
<location filename="../src/gui/Window.cpp" line="22"/>
<source>file</source>
<translation>File</translation>
</message>
</context>
</TS>

20
i18n/pix_fr.ts Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="fr_FR">
<context>
<name>QAction</name>
<message>
<location filename="../src/gui/Window.cpp" line="25"/>
<source>quit</source>
<translation>Quitter</translation>
</message>
</context>
<context>
<name>QMenu</name>
<message>
<location filename="../src/gui/Window.cpp" line="22"/>
<source>file</source>
<translation>Fichier</translation>
</message>
</context>
</TS>

View File

@ -8,8 +8,11 @@ project(
] ]
) )
data_dir = get_option('prefix') / get_option('datadir') / 'pixtool'
conf = configuration_data() conf = configuration_data()
conf.set('version', meson.project_version()) conf.set('version', meson.project_version())
conf.set('datadir', data_dir)
configure_file( configure_file(
input: 'src/conf.in.hpp', input: 'src/conf.in.hpp',
@ -26,6 +29,15 @@ qt_src = qt6.compile_moc(
] ]
) )
translations = qt6.compile_translations(
ts_files: [
'i18n/pix_en.ts',
'i18n/pix_fr.ts'
],
install: true,
install_dir: data_dir / 'i18n'
)
pixtool = static_library( pixtool = static_library(
'pixtool-core', 'pixtool-core',
sources: [ sources: [
@ -41,7 +53,7 @@ pixtool = static_library(
# gui # gui
'src/gui/Window.cpp', 'src/gui/Window.cpp',
] + qt_src, ] + qt_src + translations,
dependencies: [ dependencies: [
qt6_dep, qt6_dep,
dependency('spdlog') dependency('spdlog')

View File

@ -1,6 +1,8 @@
#ifndef pt_CONF_HPP #ifndef pt_CONF_HPP
#define pt_CONF_HPP #define pt_CONF_HPP
#include <filesystem>
#define PT_VERSION std::string("@version@") #define PT_VERSION std::string("@version@")
#define PT_DATADIR std::filesystem::path("@datadir@")
#endif #endif

View File

@ -19,10 +19,10 @@ namespace pt
QMenuBar* bar = new QMenuBar {this}; QMenuBar* bar = new QMenuBar {this};
QMenu* file = new QMenu {"File"}; QMenu* file = new QMenu {QMenu::tr("file")};
bar->addMenu(file); bar->addMenu(file);
QAction* quit = new QAction {"Quit"}; QAction* quit = new QAction {QAction::tr("quit")};
file->addAction(quit); file->addAction(quit);
connect(quit, &QAction::triggered, [this](){ connect(quit, &QAction::triggered, [this](){

View File

@ -1,5 +1,7 @@
#include <iostream> #include <iostream>
#include <QApplication> #include <QApplication>
#include <QTranslator>
#include "model/PixTool.hpp" #include "model/PixTool.hpp"
#include "gui/Window.hpp" #include "gui/Window.hpp"
#include "Presenter.hpp" #include "Presenter.hpp"
@ -9,8 +11,13 @@ int main(int argc, char** argv)
{ {
spdlog::set_level(spdlog::level::debug); spdlog::set_level(spdlog::level::debug);
QApplication app {argc, argv}; QApplication app {argc, argv};
QTranslator translator;
Q_UNUSED(translator.load(QString::fromStdString(PT_DATADIR / "i18n" / "pix_fr.qm")));
app.installTranslator(&translator);
pt::gui::Window window; pt::gui::Window window;
pt::model::PixTool pixtool; pt::model::PixTool pixtool;