diff options
author | Daniel Kolesa <d.kolesa@samsung.com> | 2014-12-12 10:44:58 +0000 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@samsung.com> | 2014-12-12 10:44:58 +0000 |
commit | 784045df9ae73f4f74b52b5f2cc7a6254b9b7c1d (patch) | |
tree | 988a2444aa9cb16cd867e45015a57fb34d5425d6 /src/lib/elua/elua.c | |
parent | 56a8f13e5c9370a8a59c8b96a225250bda376e05 (diff) |
elua: move i18n setup to the library
Diffstat (limited to '')
-rw-r--r-- | src/lib/elua/elua.c | 52 |
1 files changed, 52 insertions, 0 deletions
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 | |||
67 | static 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 | |||
95 | const luaL_reg gettextlib[] = | ||
96 | { | ||
97 | { "bind_textdomain", _elua_gettext_bind_textdomain }, | ||
98 | { NULL, NULL } | ||
99 | }; | ||
100 | |||
101 | EAPI void | ||
102 | elua_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 | } | ||