#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#ifdef ENABLE_NLS
#include <libintl.h>
#endif

int
lua_init_gettext(lua_State *L)
{
#ifdef ENABLE_NLS
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
#endif
	return(0);
}

int
lua_gettext(lua_State *L)
{
#ifdef ENABLE_NLS
	lua_pushstring(L, gettext(luaL_checkstring(L, 1)));
#else
	lua_pushstring(L, luaL_checkstring(L, 1));
#endif
	return(1);
}

LUA_API int
lua_gettext_register(lua_State *L)
{
	lua_register(L, "init_gettext", lua_init_gettext);
	lua_register(L, "gettext", lua_gettext);
	return(1);
}
