1 /*
2 This file is part of darktable,
3 Copyright (C) 2015-2020 darktable developers.
4
5 darktable is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 darktable is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "libintl.h"
19 #include "lua/lua.h"
20 // function used by the lua interpreter to load darktable
21
lua_gettext(lua_State * L)22 static int lua_gettext(lua_State*L)
23 {
24 const char* msgid = luaL_checkstring(L,1);
25 lua_pushstring(L,gettext(msgid));
26 return 1;
27 }
28
lua_dgettext(lua_State * L)29 static int lua_dgettext(lua_State*L)
30 {
31 const char* domainname = luaL_checkstring(L,1);
32 const char* msgid = luaL_checkstring(L,2);
33 lua_pushstring(L,dgettext(domainname,msgid));
34 return 1;
35 }
36
lua_ngettext(lua_State * L)37 static int lua_ngettext(lua_State*L)
38 {
39 const char* msgid = luaL_checkstring(L,1);
40 const char* msgid_plural = luaL_checkstring(L,2);
41 int n = luaL_checkinteger(L,3);
42 lua_pushstring(L,ngettext(msgid,msgid_plural,n));
43 return 1;
44 }
45
lua_dngettext(lua_State * L)46 static int lua_dngettext(lua_State*L)
47 {
48 const char* domainname = luaL_checkstring(L,1);
49 const char* msgid = luaL_checkstring(L,2);
50 const char* msgid_plural = luaL_checkstring(L,3);
51 int n = luaL_checkinteger(L,4);
52 lua_pushstring(L,dngettext(domainname,msgid,msgid_plural,n));
53 return 1;
54 }
55
lua_bindtextdomain(lua_State * L)56 static int lua_bindtextdomain(lua_State*L)
57 {
58 const char* domainname = luaL_checkstring(L,1);
59 const char* dirname = luaL_checkstring(L,2);
60 bindtextdomain(domainname,dirname);
61 return 0;
62 }
63
64
dt_lua_init_gettext(lua_State * L)65 int dt_lua_init_gettext(lua_State *L)
66 {
67
68 dt_lua_push_darktable_lib(L);
69 dt_lua_goto_subtable(L,"gettext");
70
71 lua_pushcfunction(L,lua_gettext);
72 lua_setfield(L,-2,"gettext");
73 lua_pushcfunction(L,lua_dgettext);
74 lua_setfield(L,-2,"dgettext");
75 //lua_pushcfunction(L,lua_dcgettext);
76 //lua_setfield(L,-2,"dcgettext");
77 lua_pushcfunction(L,lua_ngettext);
78 lua_setfield(L,-2,"ngettext");
79 lua_pushcfunction(L,lua_dngettext);
80 lua_setfield(L,-2,"dngettext");
81 //lua_pushcfunction(L,lua_dcngettext);
82 //lua_setfield(L,-2,"dcngettext");
83 lua_pushcfunction(L,lua_bindtextdomain);
84 lua_setfield(L,-2,"bindtextdomain");
85
86 lua_pop(L,1);
87 return 0;
88 }
89 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
90 // vim: shiftwidth=2 expandtab tabstop=2 cindent
91 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
92