summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2014-12-12 10:44:58 +0000
committerDaniel Kolesa <d.kolesa@samsung.com>2014-12-12 10:44:58 +0000
commit784045df9ae73f4f74b52b5f2cc7a6254b9b7c1d (patch)
tree988a2444aa9cb16cd867e45015a57fb34d5425d6 /src/lib
parent56a8f13e5c9370a8a59c8b96a225250bda376e05 (diff)
elua: move i18n setup to the library
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/elua/Elua.h6
-rw-r--r--src/lib/elua/elua.c52
-rw-r--r--src/lib/elua/elua_private.h12
3 files changed, 70 insertions, 0 deletions
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index 3a284ca7bf..7b8387eae0 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -54,9 +54,15 @@ extern "C" {
54 54
55#ifdef EFL_BETA_API_SUPPORT 55#ifdef EFL_BETA_API_SUPPORT
56 56
57#include <lua.h>
58#include <lualib.h>
59#include <lauxlib.h>
60
57EAPI int elua_init(void); 61EAPI int elua_init(void);
58EAPI int elua_shutdown(void); 62EAPI int elua_shutdown(void);
59 63
64EAPI void elua_state_setup_i18n(lua_State *L);
65
60#endif 66#endif
61 67
62#ifdef __cplusplus 68#ifdef __cplusplus
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index a8b7715c91..ea23bc6cdc 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -63,3 +63,55 @@ elua_shutdown(void)
63 eina_shutdown(); 63 eina_shutdown();
64 return _elua_init_counter; 64 return _elua_init_counter;
65} 65}
66
67static int
68_elua_gettext_bind_textdomain(lua_State *L)
69{
70#ifdef ENABLE_NLS
71 const char *textdomain = luaL_checkstring(L, 1);
72 const char *dirname = luaL_checkstring(L, 2);
73 const char *ret;
74 if (!textdomain[0] || !strcmp(textdomain, PACKAGE))
75 {
76 lua_pushnil(L);
77 lua_pushliteral(L, "invalid textdomain");
78 return 2;
79 }
80 if (!(ret = bindtextdomain(textdomain, dirname)))
81 {
82 lua_pushnil(L);
83 lua_pushstring(L, strerror(errno));
84 return 2;
85 }
86 bind_textdomain_codeset(textdomain, "UTF-8");
87 lua_pushstring(L, ret);
88 return 1;
89#else
90 lua_pushliteral(L, "");
91 return 1;
92#endif
93}
94
95const luaL_reg gettextlib[] =
96{
97 { "bind_textdomain", _elua_gettext_bind_textdomain },
98 { NULL, NULL }
99};
100
101EAPI void
102elua_state_setup_i18n(lua_State *L)
103{
104#ifdef ENABLE_NLS
105 char *(*dgettextp)(const char*, const char*) = dgettext;
106 char *(*dngettextp)(const char*, const char*, const char*, unsigned long)
107 = dngettext;
108#endif
109 lua_createtable(L, 0, 0);
110 luaL_register(L, NULL, gettextlib);
111#ifdef ENABLE_NLS
112 lua_pushlightuserdata(L, *((void**)&dgettextp));
113 lua_setfield(L, -2, "dgettext");
114 lua_pushlightuserdata(L, *((void**)&dngettextp));
115 lua_setfield(L, -2, "dngettext");
116#endif
117}
diff --git a/src/lib/elua/elua_private.h b/src/lib/elua/elua_private.h
index a4be6fbfff..0e1e9be515 100644
--- a/src/lib/elua/elua_private.h
+++ b/src/lib/elua/elua_private.h
@@ -1,6 +1,18 @@
1#ifndef _ELUA_PRIVATE_H 1#ifndef _ELUA_PRIVATE_H
2#define _ELUA_PRIVATE_H 2#define _ELUA_PRIVATE_H
3 3
4#ifdef HAVE_CONFIG_H
5# include <config.h>
6#endif
7
8#ifdef ENABLE_NLS
9# include <locale.h>
10# include <libintl.h>
11# define _(x) dgettext(PACKAGE, x)
12#else
13# define _(x) (x)
14#endif
15
4#include <stdio.h> 16#include <stdio.h>
5#include <stdlib.h> 17#include <stdlib.h>
6 18