From 96123b0722022928db4d1d6eb7bec15543c7b6c2 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 7 Apr 2013 16:02:10 +0800 Subject: [PATCH 1/2] add lua_gettext module --- Makefile | 5 ++-- koreader-base.c | 2 ++ lua_gettext.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ lua_gettext.h | 29 +++++++++++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 lua_gettext.c create mode 100644 lua_gettext.h diff --git a/Makefile b/Makefile index 669999d80..7c3ddf90b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ include Makefile.defs all: koreader-base extr -koreader-base: koreader-base.o einkfb.o pdf.o blitbuffer.o drawcontext.o koptcontext.o input.o $(POPENNSLIB) util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRELIB) $(CRE_3RD_LIBS) pic.o pic_jpeg.o $(K2PDFOPTLIB) +koreader-base: koreader-base.o einkfb.o pdf.o blitbuffer.o drawcontext.o koptcontext.o input.o $(POPENNSLIB) util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRELIB) $(CRE_3RD_LIBS) pic.o lua_gettext.o pic_jpeg.o $(K2PDFOPTLIB) $(CC) \ $(CFLAGS) \ koreader-base.o \ @@ -23,6 +23,7 @@ koreader-base: koreader-base.o einkfb.o pdf.o blitbuffer.o drawcontext.o koptcon $(THIRDPARTYLIBS) \ djvu.o \ cre.o \ + lua_gettext.o \ $(STATICLIBSTDCPP) \ $(LDFLAGS) \ -Wl,-rpath=$(LIBDIR)/ \ @@ -57,7 +58,7 @@ koreader-base.o koptcontext.o pdf.o: %.o: %.c djvu.o: %.o: %.c $(CC) -c $(KOREADER_BASE_CFLAGS) $(K2PDFOPT_CFLAGS) -I$(DJVUDIR)/ $< -o $@ -pic.o: %.o: %.c +pic.o lua_gettext.o: %.o: %.c $(CC) -c $(KOREADER_BASE_CFLAGS) $< -o $@ pic_jpeg.o: %.o: %.c diff --git a/koreader-base.c b/koreader-base.c index 6e31e3cc5..1957c66ed 100644 --- a/koreader-base.c +++ b/koreader-base.c @@ -35,6 +35,7 @@ #include "input.h" #include "ft.h" #include "util.h" +#include "lua_gettext.h" #include "lfs.h" @@ -105,6 +106,7 @@ int main(int argc, char **argv) { luaopen_util(L); luaopen_ft(L); luaopen_mupdfimg(L); + luaopen_luagettext(L); luaopen_lfs(L); diff --git a/lua_gettext.c b/lua_gettext.c new file mode 100644 index 000000000..b85966c46 --- /dev/null +++ b/lua_gettext.c @@ -0,0 +1,67 @@ +/* + KOReader-base: gettext module for Lua + Copyright (C) 2013 Qingping Hou + + adapted from: + www.it.freebsd.org/ports/local-distfiles/philip/lua_gettext.c%3frev=1.15 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#include "lua_gettext.h" + + +extern int _nl_msg_cat_cntr; + + + +static int lua_gettext_init(lua_State *L) { + const char* locale_dir = luaL_checkstring(L, 1); + const char* package = luaL_checkstring(L, 2); + + setlocale(LC_ALL, ""); + bindtextdomain(package, locale_dir); + textdomain(package); + + return(0); +} + +static int lua_gettext_translate(lua_State *L) { + lua_pushstring(L, gettext(luaL_checkstring(L, 1))); + + return(1); +} + +static int lua_gettext_change_lang(lua_State *L) { + setenv("LANGUAGE", luaL_checkstring(L, 1), 1); + ++_nl_msg_cat_cntr; + + return(0); +} + + +static const luaL_reg lua_gettext_func[] = { + {"init", lua_gettext_init}, + {"translate", lua_gettext_translate}, + {"change_lang", lua_gettext_change_lang}, + {NULL, NULL} +}; + + +int luaopen_luagettext(lua_State *L) { + luaL_register(L, "lua_gettext", lua_gettext_func); + + return 1; +} diff --git a/lua_gettext.h b/lua_gettext.h new file mode 100644 index 000000000..089beba26 --- /dev/null +++ b/lua_gettext.h @@ -0,0 +1,29 @@ +/* + KOReader-base: gettext module for Lua + Copyright (C) 2013 Qingping Hou + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _GETTEXT_H +#define _GETTEXT_H + +#include +#include +#include + +#include "libintl.h" + +int luaopen_lgettext(lua_State *L); +#endif From 85a586a61b99d3d092805d6d205b5eb87e2e070e Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 7 Apr 2013 16:02:25 +0800 Subject: [PATCH 2/2] update gitignore --- .gitignore | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5c95bb8a7..dbd5104e3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ libs-emu *.orig lua lua-* -.reader.kpdfview.lua mupdf-thirdparty.zip djvulibre* crash.log @@ -16,18 +15,18 @@ slider_watcher *.o tags -kindlepdfviewer-*.zip /.cproject /.project -/.reader.kpdfview -/settings.reader.lua fonts data history screenshots cr3cache +extr +libs +koreader-base kpvcrlib/CMakeCache.txt kpvcrlib/CMakeFiles/