aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
Diffstat (limited to 'libdino')
-rw-r--r--libdino/CMakeLists.txt12
-rw-r--r--libdino/src/application.vala1
-rw-r--r--libdino/src/dino_i18n.h8
-rw-r--r--libdino/src/util.vala37
4 files changed, 57 insertions, 1 deletions
diff --git a/libdino/CMakeLists.txt b/libdino/CMakeLists.txt
index 0d1a9bf4..445f428a 100644
--- a/libdino/CMakeLists.txt
+++ b/libdino/CMakeLists.txt
@@ -42,6 +42,7 @@ SOURCES
src/service/util.vala
src/settings.vala
+ src/util.vala
CUSTOM_VAPIS
"${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi"
"${CMAKE_BINARY_DIR}/exports/qlite.vapi"
@@ -56,8 +57,17 @@ GENERATE_HEADER
dino
)
+add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/dino_i18n.h"
+COMMAND
+ cp "${CMAKE_CURRENT_SOURCE_DIR}/src/dino_i18n.h" "${CMAKE_BINARY_DIR}/exports/dino_i18n.h"
+DEPENDS
+ "${CMAKE_CURRENT_SOURCE_DIR}/src/dino_i18n.h"
+COMMENT
+ Copy header file dino_i18n.h
+)
+
add_definitions(${VALA_CFLAGS} -DDINO_PLUGINS_SYSTEM_PLUGIN_DIR="${PLUGIN_INSTALL_DIR}" -DDINO_PLUGINS_SYSTEM_LIBDIR_NAME="${LIBDIR_NAME}")
-add_library(libdino SHARED ${LIBDINO_VALA_C})
+add_library(libdino SHARED ${LIBDINO_VALA_C} ${CMAKE_BINARY_DIR}/exports/dino_i18n.h)
add_dependencies(libdino xmpp-vala-vapi qlite-vapi)
target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_PACKAGES} m)
set_target_properties(libdino PROPERTIES PREFIX "" VERSION 0.0 SOVERSION 0)
diff --git a/libdino/src/application.vala b/libdino/src/application.vala
index 37fbda8b..1ce0bca4 100644
--- a/libdino/src/application.vala
+++ b/libdino/src/application.vala
@@ -7,6 +7,7 @@ public class Dino.Application : Gtk.Application {
public Database db;
public StreamInteractor stream_interaction;
public Plugins.Registry plugin_registry = new Plugins.Registry();
+ public SearchPathGenerator? search_path_generator { get; set; }
static string print_xmpp;
diff --git a/libdino/src/dino_i18n.h b/libdino/src/dino_i18n.h
new file mode 100644
index 00000000..e1a65f41
--- /dev/null
+++ b/libdino/src/dino_i18n.h
@@ -0,0 +1,8 @@
+#ifndef __DINO_I18N_H__
+#define __DINO_I18N_H__
+
+#include<libintl.h>
+
+#define dino_gettext(String) ((char *) dgettext (GETTEXT_PACKAGE, String))
+
+#endif \ No newline at end of file
diff --git a/libdino/src/util.vala b/libdino/src/util.vala
new file mode 100644
index 00000000..29186aa0
--- /dev/null
+++ b/libdino/src/util.vala
@@ -0,0 +1,37 @@
+namespace Dino {
+
+public class SearchPathGenerator {
+
+ public string? exec_path { get; private set; }
+
+ public SearchPathGenerator(string? exec_path) {
+ this.exec_path = exec_path;
+ }
+
+ public string get_locale_path(string gettext_package, string locale_install_dir) {
+ string? locale_dir = null;
+ if (Path.get_dirname(exec_path).contains("dino") || Path.get_dirname(exec_path) == "." || Path.get_dirname(exec_path).contains("build")) {
+ string exec_locale = Path.build_filename(Path.get_dirname(exec_path), "locale");
+ if (FileUtils.test(Path.build_filename(exec_locale, "en", "LC_MESSAGES", gettext_package + ".mo"), FileTest.IS_REGULAR)) {
+ locale_dir = exec_locale;
+ }
+ }
+ return locale_dir ?? locale_install_dir;
+ }
+}
+
+[CCode (cname = "dino_gettext", cheader_filename = "dino_i18n.h")]
+public static extern unowned string _(string s);
+
+[CCode (cname = "bindtextdomain", cheader_filename = "libintl.h")]
+private static extern unowned string? bindtextdomain(string domainname, string? dirname);
+
+[CCode (cname = "bind_textdomain_codeset", cheader_filename = "libintl.h")]
+private static extern unowned string? bind_textdomain_codeset(string domainname, string? codeset);
+
+public static void internationalize(string gettext_package, string locales_dir) {
+ Intl.bind_textdomain_codeset(gettext_package, "UTF-8");
+ Intl.bindtextdomain(gettext_package, locales_dir);
+}
+
+} \ No newline at end of file