Merge from vendor branch BZIP:
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / lib / lua / gettext / lua_gettext.c
1 /*
2  * $Id: lua_gettext.c,v 1.9 2005/04/04 13:56:37 den Exp $
3  */
4
5 #include <lua50/lua.h>
6 #include <lua50/lualib.h>
7 #include <lua50/lauxlib.h>
8
9 #include "libintl.h"
10
11 /*** Prototypes ***/
12
13 LUA_API int luaopen_lgettext(lua_State *);
14
15 /*** Globals ***/
16
17 const char *package = "";
18 const char *locale_dir = "";
19
20 /*** Methods ***/
21
22 static int
23 lua_gettext_init(lua_State *L __unused)
24 {
25         setlocale(LC_ALL, "");
26         bindtextdomain(package, locale_dir);
27         textdomain(package);
28
29         return(0);
30 }
31
32 static int
33 lua_gettext_set_package(lua_State *L)
34 {
35         package = luaL_checkstring(L, 1);
36
37         return(0);
38 }
39
40 static int
41 lua_gettext_set_locale_dir(lua_State *L)
42 {
43         locale_dir = luaL_checkstring(L, 1);
44
45         return(0);
46 }
47
48 static int
49 lua_gettext_translate(lua_State *L)
50 {
51         lua_pushstring(L, gettext(luaL_checkstring(L, 1)));
52         lua_pushstring(L, luaL_checkstring(L, 1));
53
54         return(1);
55 }
56
57 /**** Binding Tables ****/
58
59 const luaL_reg gettext_methods[] = {
60         {"init",                lua_gettext_init },
61         {"set_package",         lua_gettext_set_package },
62         {"set_locale_dir",      lua_gettext_set_locale_dir },
63         {"translate",           lua_gettext_translate },
64
65         {0, 0}
66 };
67
68 /*** REGISTER ***/
69
70 LUA_API int
71 luaopen_lgettext(lua_State *L)
72 {
73         luaL_openlib(L, "GetText", gettext_methods, 0);
74
75         return(1);
76 }