summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-08-23 00:52:14 -0400
committerDavid Robillard <d@drobilla.net>2022-08-23 01:20:56 -0400
commit496f3eb577739bf667665efc490e583baa45eb2e (patch)
treef4a2f77c684215c1639525014a264f9bf11e0d4f /src
parentd39dbde2d05ae1c3483b311f0890fb97b35b5716 (diff)
downloadpatchage-496f3eb577739bf667665efc490e583baa45eb2e.tar.gz
patchage-496f3eb577739bf667665efc490e583baa45eb2e.tar.bz2
patchage-496f3eb577739bf667665efc490e583baa45eb2e.zip
Add i18n support
Diffstat (limited to 'src')
-rw-r--r--src/CanvasModule.cpp6
-rw-r--r--src/CanvasPort.hpp3
-rw-r--r--src/Legend.cpp3
-rw-r--r--src/Patchage.cpp37
-rw-r--r--src/i18n.hpp15
-rw-r--r--src/main.cpp11
-rw-r--r--src/patchage.ui.in6
-rw-r--r--src/patchage_config.h19
8 files changed, 77 insertions, 23 deletions
diff --git a/src/CanvasModule.cpp b/src/CanvasModule.cpp
index d3908df..e93cefe 100644
--- a/src/CanvasModule.cpp
+++ b/src/CanvasModule.cpp
@@ -90,15 +90,15 @@ CanvasModule::show_menu(GdkEventButton* ev)
if (_type == SignalDirection::duplex) {
items.push_back(Gtk::Menu_Helpers::MenuElem(
- "_Split", sigc::mem_fun(this, &CanvasModule::on_split)));
+ _("_Split"), sigc::mem_fun(this, &CanvasModule::on_split)));
update_menu();
} else {
items.push_back(Gtk::Menu_Helpers::MenuElem(
- "_Join", sigc::mem_fun(this, &CanvasModule::on_join)));
+ _("_Join"), sigc::mem_fun(this, &CanvasModule::on_join)));
}
items.push_back(Gtk::Menu_Helpers::MenuElem(
- "_Disconnect", sigc::mem_fun(this, &CanvasModule::on_disconnect)));
+ _("_Disconnect"), sigc::mem_fun(this, &CanvasModule::on_disconnect)));
_menu->popup(ev->button, ev->time);
return true;
diff --git a/src/CanvasPort.hpp b/src/CanvasPort.hpp
index 548c9e5..c3195a9 100644
--- a/src/CanvasPort.hpp
+++ b/src/CanvasPort.hpp
@@ -6,6 +6,7 @@
#include "PortID.hpp"
#include "PortType.hpp"
+#include "i18n.hpp"
#include "warnings.hpp"
PATCHAGE_DISABLE_GANV_WARNINGS
@@ -82,7 +83,7 @@ public:
Gtk::Menu* menu = Gtk::manage(new Gtk::Menu());
menu->items().push_back(Gtk::Menu_Helpers::MenuElem(
- "Disconnect", sigc::mem_fun(this, &Port::disconnect)));
+ _("Disconnect"), sigc::mem_fun(this, &Port::disconnect)));
menu->popup(ev->button.button, ev->button.time);
return true;
diff --git a/src/Legend.cpp b/src/Legend.cpp
index bdf51bc..a4e8705 100644
--- a/src/Legend.cpp
+++ b/src/Legend.cpp
@@ -5,6 +5,7 @@
#include "Configuration.hpp"
#include "PortType.hpp"
+#include "i18n.hpp"
#include "patchage_config.h"
#include <gdkmm/color.h>
@@ -23,7 +24,7 @@ namespace patchage {
Legend::Legend(const Configuration& configuration)
{
add_button(PortType::jack_audio,
- "Audio",
+ _("Audio"),
configuration.get_port_color(PortType::jack_audio));
#if USE_JACK_METADATA
diff --git a/src/Patchage.cpp b/src/Patchage.cpp
index 1f3d706..c3166c2 100644
--- a/src/Patchage.cpp
+++ b/src/Patchage.cpp
@@ -23,6 +23,7 @@
#include "Widget.hpp"
#include "event_to_string.hpp"
#include "handle_event.hpp"
+#include "i18n.hpp"
#include "patchage_config.h" // IWYU pragma: keep
#include "warnings.hpp"
@@ -445,11 +446,14 @@ Patchage::update_toolbar()
const auto buffer_size = _drivers.jack()->buffer_size();
const auto sample_rate = _drivers.jack()->sample_rate();
if (sample_rate != 0) {
- const auto latency_ms =
- buffer_size * 1000 / static_cast<float>(sample_rate);
+ const auto sample_rate_khz = sample_rate / 1000.0;
+ const auto latency_ms = buffer_size / sample_rate_khz;
+
+ _latency_label->set_label(" " +
+ fmt::format(_("frames at {} kHz ({:0.2f} ms)"),
+ sample_rate_khz,
+ latency_ms));
- _latency_label->set_label(fmt::format(
- " frames @ {} kHz ({:0.2f} ms)", sample_rate / 1000, latency_ms));
_latency_label->set_visible(true);
_buf_size_combo->set_active(
static_cast<int>(log2f(_drivers.jack()->buffer_size()) - 5));
@@ -467,12 +471,13 @@ Patchage::update_load()
{
if (_drivers.jack() && _drivers.jack()->is_attached()) {
const auto xruns = _drivers.jack()->xruns();
+
+ _dropouts_label->set_text(" " + fmt::format(_("Dropouts: {}"), xruns));
+
if (xruns > 0u) {
- _dropouts_label->set_text(fmt::format(" Dropouts: {}", xruns));
_dropouts_label->show();
_clear_load_but->show();
} else {
- _dropouts_label->set_text(" Dropouts: 0");
_dropouts_label->hide();
_clear_load_but->hide();
}
@@ -502,7 +507,7 @@ Patchage::store_window_location()
void
Patchage::clear_load()
{
- _dropouts_label->set_text(" Dropouts: 0");
+ _dropouts_label->set_text(" " + fmt::format(_("Dropouts: {}"), 0U));
_dropouts_label->hide();
_clear_load_but->hide();
if (_drivers.jack()) {
@@ -830,7 +835,9 @@ Patchage::on_quit()
void
Patchage::on_export_image()
{
- Gtk::FileChooserDialog dialog("Export Image", Gtk::FILE_CHOOSER_ACTION_SAVE);
+ Gtk::FileChooserDialog dialog(_("Export Image"),
+ Gtk::FILE_CHOOSER_ACTION_SAVE);
+
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
dialog.set_default_response(Gtk::RESPONSE_OK);
@@ -850,7 +857,7 @@ Patchage::on_export_image()
dialog.add_filter(filt);
}
- auto* bg_but = new Gtk::CheckButton("Draw _Background", true);
+ auto* bg_but = new Gtk::CheckButton(_("Draw _Background"), true);
auto* extra = new Gtk::Alignment(1.0, 0.5, 0.0, 0.0);
bg_but->set_active(true);
extra->add(*Gtk::manage(bg_but));
@@ -860,12 +867,12 @@ Patchage::on_export_image()
if (dialog.run() == Gtk::RESPONSE_OK) {
const std::string filename = dialog.get_filename();
if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
- Gtk::MessageDialog confirm(std::string("File exists! Overwrite ") +
- filename + "?",
- true,
- Gtk::MESSAGE_WARNING,
- Gtk::BUTTONS_YES_NO,
- true);
+ Gtk::MessageDialog confirm(
+ fmt::format(_("File exists! Overwrite {}?"), filename),
+ true,
+ Gtk::MESSAGE_WARNING,
+ Gtk::BUTTONS_YES_NO,
+ true);
confirm.set_transient_for(dialog);
if (confirm.run() != Gtk::RESPONSE_YES) {
return;
diff --git a/src/i18n.hpp b/src/i18n.hpp
new file mode 100644
index 0000000..4cf082d
--- /dev/null
+++ b/src/i18n.hpp
@@ -0,0 +1,15 @@
+// Copyright 2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef PATCHAGE_I18N_HPP
+#define PATCHAGE_I18N_HPP
+
+#include <libintl.h>
+
+/// Mark a string literal as translatable
+#define _(msgid) gettext(msgid)
+
+/// Mark a string literal as non-translatable
+// #define N_(msgid) (msgid)
+
+#endif // PATCHAGE_I18N_HPP
diff --git a/src/main.cpp b/src/main.cpp
index 4466e15..d76413f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,6 +21,10 @@
#include <glibmm/ustring.h>
#include <gtkmm/main.h>
+#if USE_GETTEXT
+# include <libintl.h>
+#endif
+
#include <cstring>
#include <exception>
#include <iostream>
@@ -94,6 +98,13 @@ main(int argc, char** argv)
set_bundle_environment();
#endif
+#if USE_GETTEXT
+ setlocale(LC_ALL, "");
+ bindtextdomain("patchage", PATCHAGE_LOCALE_DIR);
+ bind_textdomain_codeset("patchage", "UTF-8");
+ textdomain("patchage");
+#endif
+
try {
Glib::thread_init();
diff --git a/src/patchage.ui.in b/src/patchage.ui.in
index c63566a..89d749d 100644
--- a/src/patchage.ui.in
+++ b/src/patchage.ui.in
@@ -362,7 +362,7 @@
<child>
<object class="GtkLabel" id="latency_label">
<property name="can_focus">False</property>
- <property name="label" translatable="yes">frames @ ? kHz (? ms)</property>
+ <property name="label" translatable="yes">frames at ? kHz (? ms)</property>
</object>
<packing>
<property name="expand">False</property>
@@ -388,7 +388,7 @@
<object class="GtkLabel" id="dropouts_label">
<property name="can_focus">False</property>
<property name="visible">False</property>
- <property name="label" translatable="yes"> Dropouts: 0</property>
+ <property name="label" translatable="yes">Dropouts: {}</property>
</object>
</child>
</object>
@@ -502,7 +502,7 @@
<property name="version">@PATCHAGE_VERSION@</property>
<property name="copyright" translatable="no">© 2005-2022 David Robillard
© 2008 Nedko Arnaudov</property>
- <property name="comments" translatable="yes">A JACK and ALSA front-end.</property>
+ <property name="comments" translatable="yes">A modular patchbay for JACK and ALSA applications.</property>
<property name="website">http://drobilla.net/software/patchage</property>
<property name="license" translatable="no"> GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
diff --git a/src/patchage_config.h b/src/patchage_config.h
index e5f56df..6c3ad90 100644
--- a/src/patchage_config.h
+++ b/src/patchage_config.h
@@ -46,6 +46,19 @@
# endif
# endif
+// GNU gettext()
+# ifndef HAVE_GETTEXT
+# ifdef __has_include
+# if __has_include(<libintl.h>)
+# define HAVE_GETTEXT 1
+# else
+# define HAVE_GETTEXT 0
+# endif
+# else
+# define HAVE_GETTEXT 0
+# endif
+# endif
+
// JACK metadata API
# ifndef HAVE_JACK_METADATA
# ifdef __has_include
@@ -75,6 +88,12 @@
# define USE_DLADDR 0
#endif
+#if HAVE_GETTEXT
+# define USE_GETTEXT 1
+#else
+# define USE_GETTEXT 0
+#endif
+
#if HAVE_JACK_METADATA
# define USE_JACK_METADATA 1
#else