Skip to content

Commit

Permalink
Merge pull request #5 from houqp/houqp-master
Browse files Browse the repository at this point in the history
add lua_gettext module
  • Loading branch information
chrox committed Apr 8, 2013
2 parents 73ffa9e + 85a586a commit 141b9c0
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 6 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ libs-emu
*.orig
lua
lua-*
.reader.kpdfview.lua
mupdf-thirdparty.zip
djvulibre*
crash.log
Expand All @@ -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/
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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)/ \
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions koreader-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "input.h"
#include "ft.h"
#include "util.h"
#include "lua_gettext.h"

#include "lfs.h"

Expand Down Expand Up @@ -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);

Expand Down
67 changes: 67 additions & 0 deletions lua_gettext.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
KOReader-base: gettext module for Lua
Copyright (C) 2013 Qingping Hou <qingping.hou@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/


#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;
}
29 changes: 29 additions & 0 deletions lua_gettext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
KOReader-base: gettext module for Lua
Copyright (C) 2013 Qingping Hou <qingping.hou@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/

#ifndef _GETTEXT_H
#define _GETTEXT_H

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

#include "libintl.h"

int luaopen_lgettext(lua_State *L);
#endif

0 comments on commit 141b9c0

Please sign in to comment.