[grilo-plugins] lua-factory: Add dgettext() binding to Lua



commit 3cda4587a6b4a23c46f7b13c24affa0955a7c071
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Feb 25 13:45:57 2014 +0100

    lua-factory: Add dgettext() binding to Lua

 src/lua-factory/grl-lua-library.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index dbdd88c..efd69f9 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -573,6 +573,33 @@ grl_l_warning (lua_State *L)
   return 0;
 }
 
+/**
+ * grl.dgettext
+ *
+ * @domain: (string) the domain to use for the translation
+ * @str: (string) the string to translate
+ * @return: the translated string
+ */
+static gint
+grl_l_dgettext (lua_State *L)
+{
+  const gchar *domain;
+  const gchar *str;
+  gchar *output;
+
+  luaL_argcheck (L, lua_isstring (L, 1), 1, "expecting domain name as string");
+  luaL_argcheck (L, lua_isstring (L, 2), 2, "expecting string to translate as string");
+
+  domain = lua_tolstring (L, 1, NULL);
+  str = lua_tolstring (L, 2, NULL);
+
+  bind_textdomain_codeset (domain, "UTF-8");
+  output = dgettext (domain, str);
+  lua_pushstring (L, output);
+
+  return 1;
+}
+
 /* ================== Lua-Library initialization =========================== */
 
 gint
@@ -586,6 +613,7 @@ luaopen_grilo (lua_State *L)
     {"fetch", &grl_l_fetch},
     {"debug", &grl_l_debug},
     {"warning", &grl_l_warning},
+    {"dgettext", &grl_l_dgettext},
     {NULL, NULL}
   };
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]