elua lib: add a func to retrieve the current translation lang

This commit is contained in:
Daniel Kolesa 2015-04-30 11:15:48 +01:00
parent 093c7aa596
commit 3a685d40c0
2 changed files with 20 additions and 1 deletions

View File

@ -258,9 +258,29 @@ _elua_gettext_bind_textdomain(lua_State *L)
#endif
}
static int
_elua_get_message_language(lua_State *L)
{
const char *e;
e = getenv("LANGUAGE");
if (e && e[0]) goto success;
e = getenv("LC_ALL");
if (e && e[0]) goto success;
e = getenv("LC_MESSAGES");
if (e && e[0]) goto success;
e = getenv("LANG");
if (e && e[0]) goto success;
lua_pushnil(L);
return 1;
success:
lua_pushstring(L, e);
return 1;
};
const luaL_reg gettextlib[] =
{
{ "bind_textdomain", _elua_gettext_bind_textdomain },
{ "get_message_language", _elua_get_message_language },
{ NULL, NULL }
};

View File

@ -7,7 +7,6 @@ local M = {}
local gettext = ...
local bind_textdomain = gettext.bind_textdomain
local bind_textdomain_codeset = gettext.bind_textdomain_codeset
local dgettext = gettext.dgettext
local dngettext = gettext.dngettext