aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/util.vala
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-04-07 11:09:47 +0200
committerfiaxh <git@mx.ax.lt>2017-04-10 15:47:21 +0200
commit9bc83539d124f9645dc92e9e39001cb0192dae61 (patch)
treea4b22a8ea3e10b6d0050c2e5669729919a1cb477 /libdino/src/util.vala
parentd8881c4b16a1cd376dd69304c44444aee581da32 (diff)
downloaddino-9bc83539d124f9645dc92e9e39001cb0192dae61.tar.gz
dino-9bc83539d124f9645dc92e9e39001cb0192dae61.zip
Gettext support
Diffstat (limited to 'libdino/src/util.vala')
-rw-r--r--libdino/src/util.vala37
1 files changed, 37 insertions, 0 deletions
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