+static int template_L_load_catalog(lua_State *L) {
+ const char *lang = luaL_optstring(L, 1, "en");
+ const char *dir = luaL_optstring(L, 2, NULL);
+ lua_pushboolean(L, !lmo_load_catalog(lang, dir));
+ return 1;
+}
+
+static int template_L_close_catalog(lua_State *L) {
+ const char *lang = luaL_optstring(L, 1, "en");
+ lmo_close_catalog(lang);
+ return 0;
+}
+
+static int template_L_change_catalog(lua_State *L) {
+ const char *lang = luaL_optstring(L, 1, "en");
+ lua_pushboolean(L, !lmo_change_catalog(lang));
+ return 1;
+}
+
+static int template_L_translate(lua_State *L) {
+ size_t len;
+ char *tr;
+ int trlen;
+ const char *key = luaL_checklstring(L, 1, &len);
+
+ switch (lmo_translate(key, len, &tr, &trlen))
+ {
+ case 0:
+ lua_pushlstring(L, tr, trlen);
+ return 1;
+
+ case -1:
+ return 0;
+ }
+
+ lua_pushnil(L);
+ lua_pushstring(L, "no catalog loaded");
+ return 2;
+}
+
+static int template_L_hash(lua_State *L) {
+ size_t len;
+ const char *key = luaL_checklstring(L, 1, &len);
+ lua_pushinteger(L, sfh_hash(key, len));
+ return 1;
+}
+