forked from enlightenment/efl
elua: move i18n setup to the library
This commit is contained in:
parent
56a8f13e5c
commit
784045df9a
|
@ -326,40 +326,6 @@ const luaL_reg cutillib[] =
|
||||||
{ NULL , NULL }
|
{ NULL , NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
|
||||||
elua_gettext_bind_textdomain(lua_State *L)
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_NLS
|
|
||||||
const char *textdomain = luaL_checkstring(L, 1);
|
|
||||||
const char *dirname = luaL_checkstring(L, 2);
|
|
||||||
const char *ret;
|
|
||||||
if (!textdomain[0] || !strcmp(textdomain, PACKAGE))
|
|
||||||
{
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushliteral(L, "invalid textdomain");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
if (!(ret = bindtextdomain(textdomain, dirname)))
|
|
||||||
{
|
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushstring(L, strerror(errno));
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
bind_textdomain_codeset(textdomain, "UTF-8");
|
|
||||||
lua_pushstring(L, ret);
|
|
||||||
return 1;
|
|
||||||
#else
|
|
||||||
lua_pushliteral(L, "");
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
const luaL_reg gettextlib[] =
|
|
||||||
{
|
|
||||||
{ "bind_textdomain", elua_gettext_bind_textdomain },
|
|
||||||
{ NULL, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
elua_print_help(const char *pname, FILE *stream)
|
elua_print_help(const char *pname, FILE *stream)
|
||||||
{
|
{
|
||||||
|
@ -413,12 +379,6 @@ elua_main(lua_State *L)
|
||||||
int argc = m->argc;
|
int argc = m->argc;
|
||||||
char **argv = m->argv;
|
char **argv = m->argv;
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
|
||||||
char *(*dgettextp)(const char*, const char*) = dgettext;
|
|
||||||
char *(*dngettextp)(const char*, const char*, const char*, unsigned long)
|
|
||||||
= dngettext;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
elua_progname = (argv[0] && argv[0][0]) ? argv[0] : "elua";
|
elua_progname = (argv[0] && argv[0][0]) ? argv[0] : "elua";
|
||||||
|
|
||||||
while ((ch = getopt_long(argc, argv, "+LhC:M:A:e:l:I:E", lopt, NULL)) != -1)
|
while ((ch = getopt_long(argc, argv, "+LhC:M:A:e:l:I:E", lopt, NULL)) != -1)
|
||||||
|
@ -507,14 +467,7 @@ elua_main(lua_State *L)
|
||||||
m->status = 1;
|
m->status = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
lua_createtable(L, 0, 0);
|
elua_state_setup_i18n(L);
|
||||||
luaL_register(L, NULL, gettextlib);
|
|
||||||
#ifdef ENABLE_NLS
|
|
||||||
lua_pushlightuserdata(L, *((void**)&dgettextp));
|
|
||||||
lua_setfield(L, -2, "dgettext");
|
|
||||||
lua_pushlightuserdata(L, *((void**)&dngettextp));
|
|
||||||
lua_setfield(L, -2, "dngettext");
|
|
||||||
#endif
|
|
||||||
lua_call(L, 1, 0);
|
lua_call(L, 1, 0);
|
||||||
|
|
||||||
elua_register_cache(L);
|
elua_register_cache(L);
|
||||||
|
|
|
@ -54,9 +54,15 @@ extern "C" {
|
||||||
|
|
||||||
#ifdef EFL_BETA_API_SUPPORT
|
#ifdef EFL_BETA_API_SUPPORT
|
||||||
|
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lualib.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
|
||||||
EAPI int elua_init(void);
|
EAPI int elua_init(void);
|
||||||
EAPI int elua_shutdown(void);
|
EAPI int elua_shutdown(void);
|
||||||
|
|
||||||
|
EAPI void elua_state_setup_i18n(lua_State *L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -63,3 +63,55 @@ elua_shutdown(void)
|
||||||
eina_shutdown();
|
eina_shutdown();
|
||||||
return _elua_init_counter;
|
return _elua_init_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_elua_gettext_bind_textdomain(lua_State *L)
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_NLS
|
||||||
|
const char *textdomain = luaL_checkstring(L, 1);
|
||||||
|
const char *dirname = luaL_checkstring(L, 2);
|
||||||
|
const char *ret;
|
||||||
|
if (!textdomain[0] || !strcmp(textdomain, PACKAGE))
|
||||||
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushliteral(L, "invalid textdomain");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
if (!(ret = bindtextdomain(textdomain, dirname)))
|
||||||
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
lua_pushstring(L, strerror(errno));
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
bind_textdomain_codeset(textdomain, "UTF-8");
|
||||||
|
lua_pushstring(L, ret);
|
||||||
|
return 1;
|
||||||
|
#else
|
||||||
|
lua_pushliteral(L, "");
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_reg gettextlib[] =
|
||||||
|
{
|
||||||
|
{ "bind_textdomain", _elua_gettext_bind_textdomain },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
EAPI void
|
||||||
|
elua_state_setup_i18n(lua_State *L)
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_NLS
|
||||||
|
char *(*dgettextp)(const char*, const char*) = dgettext;
|
||||||
|
char *(*dngettextp)(const char*, const char*, const char*, unsigned long)
|
||||||
|
= dngettext;
|
||||||
|
#endif
|
||||||
|
lua_createtable(L, 0, 0);
|
||||||
|
luaL_register(L, NULL, gettextlib);
|
||||||
|
#ifdef ENABLE_NLS
|
||||||
|
lua_pushlightuserdata(L, *((void**)&dgettextp));
|
||||||
|
lua_setfield(L, -2, "dgettext");
|
||||||
|
lua_pushlightuserdata(L, *((void**)&dngettextp));
|
||||||
|
lua_setfield(L, -2, "dngettext");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
#ifndef _ELUA_PRIVATE_H
|
#ifndef _ELUA_PRIVATE_H
|
||||||
#define _ELUA_PRIVATE_H
|
#define _ELUA_PRIVATE_H
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_NLS
|
||||||
|
# include <locale.h>
|
||||||
|
# include <libintl.h>
|
||||||
|
# define _(x) dgettext(PACKAGE, x)
|
||||||
|
#else
|
||||||
|
# define _(x) (x)
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue