forked from enlightenment/efl
elua: i18n/l10n support including gettext module for user apps, bump gettext requirement to 0.18.3 (required for lua support in xgettext)
This commit is contained in:
parent
7876dd579f
commit
76b445fb6d
|
@ -249,7 +249,7 @@ EFL_INIT
|
|||
|
||||
### gettext
|
||||
|
||||
AM_GNU_GETTEXT_VERSION([0.17])
|
||||
AM_GNU_GETTEXT_VERSION([0.18.3])
|
||||
|
||||
m4_ifdef([AC_GNU_GETTEXT], [
|
||||
AC_GNU_GETTEXT([external])
|
||||
|
|
|
@ -8,7 +8,8 @@ bin_elua_elua_SOURCES = \
|
|||
|
||||
bin_elua_elua_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
-DELUA_CORE_DIR="\"$(datadir)/elua/core\"" \
|
||||
-DELUA_MODULES_DIR="\"$(datadir)/elua/modules\"" @ELUA_CFLAGS@
|
||||
-DELUA_MODULES_DIR="\"$(datadir)/elua/modules\"" @ELUA_CFLAGS@ \
|
||||
-DLOCALE_DIR=\"@LOCALE_DIR@\"
|
||||
bin_elua_elua_LDADD = @ELUA_LIBS@
|
||||
bin_elua_elua_DEPENDENCIES = @ELUA_INTERNAL_LIBS@
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
-- elua gettext module
|
||||
|
||||
local M = {}
|
||||
|
||||
local gettext = ...
|
||||
|
||||
local bind_textdomain = gettext.bind_textdomain
|
||||
local dgettext = gettext.dgettext
|
||||
|
||||
local domains = {}
|
||||
|
||||
M.register_domain = function(dom, dir)
|
||||
local d, err = bind_textdomain(dom, dir)
|
||||
if not d then
|
||||
return false, err
|
||||
end
|
||||
domains[dom] = d
|
||||
return true
|
||||
end
|
||||
|
||||
M.get_domain = function(dom)
|
||||
return domains[dom]
|
||||
end
|
||||
|
||||
M.gettext = function(dom, msgid)
|
||||
if not domains[dom] then return msgid end
|
||||
return dgettext(dom, msgid)
|
||||
end
|
||||
|
||||
return M
|
|
@ -195,6 +195,43 @@ const luaL_reg cutillib[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static int gettext_bind_textdomain(lua_State *L) {
|
||||
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;
|
||||
}
|
||||
|
||||
static int gettext_dgettext(lua_State *L) {
|
||||
const char *textdomain = luaL_checkstring(L, 1);
|
||||
const char *msgid = luaL_checkstring(L, 2);
|
||||
const char *lmsgid = dgettext(textdomain, msgid);
|
||||
if (msgid == lmsgid) {
|
||||
lua_pushvalue(L, 2);
|
||||
} else {
|
||||
lua_pushstring(L, lmsgid);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_reg gettextlib[] = {
|
||||
{ "bind_textdomain", gettext_bind_textdomain },
|
||||
{ "dgettext" , gettext_dgettext },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static void print_help(const char *progname, FILE *stream) {
|
||||
fprintf(stream, "Usage: %s [OPTIONS] [SCRIPT [ARGS]]\n\n"
|
||||
"A main entry for all EFL/LuaJIT powered applications.\n\n"
|
||||
|
@ -287,7 +324,6 @@ static int lua_main(lua_State *L) {
|
|||
}
|
||||
}
|
||||
snprintf(modfile, sizeof(modfile), "%s/module.lua", coref);
|
||||
|
||||
if (report(L, elua_loadfile(L, modfile))) {
|
||||
m->status = 1;
|
||||
return 0;
|
||||
|
@ -301,6 +337,15 @@ static int lua_main(lua_State *L) {
|
|||
luaL_register(L, NULL, cutillib);
|
||||
lua_call(L, 2, 0);
|
||||
|
||||
snprintf(modfile, sizeof(modfile), "%s/gettext.lua", coref);
|
||||
if (report(L, elua_loadfile(L, modfile))) {
|
||||
m->status = 1;
|
||||
return 0;
|
||||
}
|
||||
lua_createtable(L, 0, 0);
|
||||
luaL_register(L, NULL, gettextlib);
|
||||
lua_call(L, 1, 0);
|
||||
|
||||
elua_register_cache(L);
|
||||
lua_gc(L, LUA_GCRESTART, 0);
|
||||
|
||||
|
@ -346,6 +391,13 @@ int main(int argc, char **argv) {
|
|||
struct Main_Data m;
|
||||
lua_State *L = NULL;
|
||||
|
||||
#if ENABLE_NLS
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALE_DIR);
|
||||
bind_textdomain_codeset(PACKAGE, "UTF-8");
|
||||
textdomain(PACKAGE);
|
||||
#endif
|
||||
|
||||
eina_init();
|
||||
|
||||
if (!(el_log_domain = eina_log_domain_register("elua",
|
||||
|
|
|
@ -5,6 +5,13 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
#include <libintl.h>
|
||||
#define _(x) dgettext(PACKAGE, x)
|
||||
#else
|
||||
#define _(x) (x)
|
||||
#endif
|
||||
|
||||
#ifndef ELUA_CORE_DIR
|
||||
#define ELUA_CORE_DIR "."
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue