diff --git a/Makefile b/Makefile index 93bd9b3bf..b422d4c82 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,14 @@ EMU_DIR=emu # files to copy from main directory LUA_FILES=reader.lua +# for gettext +DOMAIN=koreader +TEMPLATE_DIR=l10n/templates +KOREADER_MISC_TOOL=../misc +XGETTEXT_BIN=$(KOREADER_MISC_TOOL)/gettext/lua_xgettext.py +MO_DIR=i18n + + all: $(KOR_BASE)/koreader-base $(KOR_BASE)/extr $(KOR_BASE)/koreader-base $(KOR_BASE)/extr: @@ -61,6 +69,7 @@ customupdate: $(KOR_BASE)/koreader-base $(KOR_BASE)/extr $(STRIP) --strip-unneeded $(INSTALL_DIR)/libs/* cp -rpL $(KOR_BASE)/data/*.css $(INSTALL_DIR)/data cp -rpL $(KOR_BASE)/fonts $(INSTALL_DIR) + cp -rp $(KOR_BASE)/i18n $(INSTALL_DIR) rm $(INSTALL_DIR)/fonts/droid/DroidSansFallbackFull.ttf echo $(VERSION) > git-rev cp -r git-rev resources $(INSTALL_DIR) @@ -70,3 +79,17 @@ customupdate: $(KOR_BASE)/koreader-base $(KOR_BASE)/extr rm -rf $(INSTALL_DIR) # @TODO write an installation script for KUAL (houqp) + +pot: + $(XGETTEXT_BIN) reader.lua `find frontend -iname "*.lua"` \ + > $(TEMPLATE_DIR)/$(DOMAIN).pot + +mo: + for po in `find l10n -iname '*.po'`; do \ + resource=`basename $$po .po` ; \ + lingua=`dirname $$po | xargs basename` ; \ + mkdir -p $(MO_DIR)/$$lingua/LC_MESSAGES/ ; \ + msgfmt -o $(MO_DIR)/$$lingua/LC_MESSAGES/$$resource.mo $$po ; \ + done + + diff --git a/frontend/gettext.lua b/frontend/gettext.lua new file mode 100644 index 000000000..4e0533e68 --- /dev/null +++ b/frontend/gettext.lua @@ -0,0 +1,11 @@ + +lua_gettext.init("./i18n", "koreader") + + +function _(string) + return lua_gettext.translate(string) +end + +function gettextChangeLang(new_lang) + lua_gettext.change_lang(new_lang) +end diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index f75923bb3..4d77e520f 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -8,7 +8,7 @@ Device = { function Device:getModel() local std_out = io.popen("grep 'MX' /proc/cpuinfo | cut -d':' -f2 | awk {'print $2'}", "r") - local cpu_mod = std_out:read() + local cpu_mod = std_out:read() if not cpu_mod then local ret = os.execute("grep 'Hardware : Mario Platform' /proc/cpuinfo", "r") if ret ~= 0 then @@ -122,7 +122,7 @@ function Device:usbPlugIn() if self.charging_mode == false and self.screen_saver_mode == false then Screen:saveCurrentBB() --UIManager:show(InfoMessage:new{ - --text = "Going into USB mode... ", + --text = "Going into USB mode... ", --timeout = 2, --}) --util.sleep(1) diff --git a/frontend/ui/font.lua b/frontend/ui/font.lua index 3d9ec96cb..836508e2a 100644 --- a/frontend/ui/font.lua +++ b/frontend/ui/font.lua @@ -5,9 +5,10 @@ Font = { -- default font for menu contents cfont = "droid/DroidSansFallback.ttf", -- default font for title - tfont = "NimbusSanL-BoldItal.cff", + --tfont = "NimbusSanL-BoldItal.cff", + tfont = "droid/DroidSansFallback.ttf", -- default font for footer - ffont = "droid/DroidSans.ttf", + ffont = "droid/DroidSansFallback.ttf", -- default font for reading position info rifont = "droid/DroidSans.ttf", diff --git a/frontend/ui/reader/readermenu.lua b/frontend/ui/reader/readermenu.lua index a2a0efef8..59bd2dfa1 100644 --- a/frontend/ui/reader/readermenu.lua +++ b/frontend/ui/reader/readermenu.lua @@ -31,7 +31,7 @@ function ReaderMenu:init() if Device:hasKeyboard() then self.key_events = { - ShowMenu = { { "Menu" }, doc = "show menu" }, + ShowMenu = { { _("Menu") }, doc = _("show menu") }, } end end @@ -58,13 +58,25 @@ function ReaderMenu:setUpdateItemTable() end table.insert(self.tab_item_table.main, { - text = "Help", + text = _("Help"), callback = function() UIManager:show(InfoMessage:new{ - text = "Just kidding, this page is not implemented yet.", + text = _("Just kidding, this page is not implemented yet."), }) end }) + + table.insert(self.tab_item_table.main, { + text = _("Languages"), + sub_item_table = { + { + text = "简体中文", + callback = function() + gettextChangeLang("zh_CN.UTF-8") + end, + }, + } + }) end function ReaderMenu:onShowMenu() @@ -80,7 +92,6 @@ function ReaderMenu:onShowMenu() local main_menu = nil if Device:isTouchDevice() then main_menu = TouchMenu:new{ - name = "main_menu", width = Screen:getWidth(), tab_item_table = { self.tab_item_table.navi, @@ -92,7 +103,7 @@ function ReaderMenu:onShowMenu() } else main_menu = Menu:new{ - title = "Document menu", + title = _("Document menu"), item_table = {}, width = Screen:getWidth() - 100, } diff --git a/frontend/ui/reader/readertoc.lua b/frontend/ui/reader/readertoc.lua index 355ca5483..6a227919e 100644 --- a/frontend/ui/reader/readertoc.lua +++ b/frontend/ui/reader/readertoc.lua @@ -1,6 +1,6 @@ ReaderToc = InputContainer:new{ toc = nil, - toc_menu_title = "Table of contents", + toc_menu_title = _("Table of contents"), } function ReaderToc:init() @@ -8,7 +8,7 @@ function ReaderToc:init() self.key_events = { ShowToc = { { "T" }, - doc = "show Table of Content menu" }, + doc = _("show Table of Content menu") }, } end self.ui.menu:registerToMainMenu(self) @@ -82,7 +82,7 @@ function ReaderToc:onShowToc() } local toc_menu = Menu:new{ - title = "Table of Contents", + title = _("Table of Contents"), item_table = self.toc, ui = self.ui, width = Screen:getWidth()-50, diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index fcdae4423..b30964024 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -3,6 +3,7 @@ require "ui/device" require "ui/inputevent" require "ui/screen" require "debug" +require "gettext" -- initialize output module, this must be initialized before Input Screen:init() diff --git a/l10n/.tx/config b/l10n/.tx/config new file mode 100644 index 000000000..be9284551 --- /dev/null +++ b/l10n/.tx/config @@ -0,0 +1,9 @@ +[main] +host = https://www.transifex.com + +[koreader.koreader] +file_filter = /koreader.po +source_file = templates/koreader.pot +source_lang = en +type = PO + diff --git a/l10n/Makefile b/l10n/Makefile new file mode 100644 index 000000000..b85aaf32e --- /dev/null +++ b/l10n/Makefile @@ -0,0 +1,12 @@ +all: update + +update: + tx pull -a + +bootstrap: + tx set --auto-local -r koreader.koreader "/koreader.po" \ + --source-language=en \ + --source-file "templates/koreader.pot" --execute + +.PHONY: all clean + diff --git a/l10n/templates/koreader.pot b/l10n/templates/koreader.pot new file mode 100644 index 000000000..baee69a54 --- /dev/null +++ b/l10n/templates/koreader.pot @@ -0,0 +1,149 @@ +# KOReader PATH/TO/FILE.PO +# Copyright (C) 2005-2013 KOReader Development Team +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: https://github.com/koreader/koreader-base/issues\n" +"POT-Creation-Date: 2013-04-07 18:47+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: frontend/ui/reader/readerconfig.lua:117 +msgid "" +")\n" +"end\n" +"\n" +"function ReaderConfig:onCloseDocument()\n" +" self.configurable:saveSettings(self.ui.doc_settings, self.options.prefix.." +msgstr "" + +#: reader.lua:196 +msgid "" +"-d start in debug mode" +msgstr "" + +#: reader.lua:197 +msgid "" +"-h show this usage help" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:106 +msgid "" +"Document menu" +msgstr "" + +#: reader.lua:87 +msgid "" +"Exit" +msgstr "" + +#: reader.lua:149 +msgid "" +"FileManager" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:61 +msgid "" +"Help" +msgstr "" + +#: reader.lua:17 +msgid "" +"Home" +msgstr "" + +#: reader.lua:105 +msgid "" +"Home menu" +msgstr "" + +#: reader.lua:202 +msgid "" +"If you don't pass any path, the last viewed document will be opened" +msgstr "" + +#: reader.lua:199 +msgid "" +"If you give the name of a directory instead of a file path, a file" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:64 +msgid "" +"Just kidding, this page is not implemented yet." +msgstr "" + +#: frontend/ui/reader/readermenu.lua:70 +msgid "" +"Languages" +msgstr "" + +#: reader.lua:82 +msgid "" +"Last documents" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:34 +msgid "" +"Menu" +msgstr "" + +#: reader.lua:126 +msgid "" +"No reader engine for this file" +msgstr "" + +#: reader.lua:194 +msgid "" +"Read all the books on your E-Ink reader" +msgstr "" + +#: reader.lua:205 +msgid "" +"See http://github.com/koreader/kindlepdfviewer for more info." +msgstr "" + +#: reader.lua:17 +msgid "" +"Show Home Menu" +msgstr "" + +#: frontend/ui/reader/readertoc.lua:87 +msgid "" +"Table of Contents" +msgstr "" + +#: frontend/ui/reader/readertoc.lua:5 +msgid "" +"Table of contents" +msgstr "" + +#: reader.lua:204 +msgid "" +"This software is licensed under the GPLv3." +msgstr "" + +#: reader.lua:200 +msgid "" +"chooser will show up and let you select a file" +msgstr "" + +#: frontend/ui/reader/readertoc.lua:13 +msgid "" +"show Table of Content menu" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:34 +msgid "" +"show menu" +msgstr "" + +#: reader.lua:193 +msgid "" +"usage: ./reader.lua [OPTION] ... path" +msgstr "" + + diff --git a/l10n/zh_CN/koreader.po b/l10n/zh_CN/koreader.po new file mode 100644 index 000000000..054b58f37 --- /dev/null +++ b/l10n/zh_CN/koreader.po @@ -0,0 +1,127 @@ +# KOReader PATH/TO/FILE.PO +# Copyright (C) 2005-2013 KOReader Development Team +# +# Translators: +# Qingping Hou , 2013. +msgid "" +msgstr "" +"Project-Id-Version: KOReader\n" +"Report-Msgid-Bugs-To: https://github.com/koreader/koreader-base/issues\n" +"POT-Creation-Date: 2013-04-07 18:47+0000\n" +"PO-Revision-Date: 2013-04-07 18:50+0000\n" +"Last-Translator: houqp \n" +"Language-Team: Chinese (China) (http://www.transifex.com/projects/p/koreader/language/zh_CN/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: zh_CN\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: frontend/ui/reader/readerconfig.lua:117 +msgid "" +")\n" +"end\n" +"\n" +"function ReaderConfig:onCloseDocument()\n" +"\tself.configurable:saveSettings(self.ui.doc_settings, self.options.prefix.." +msgstr "" + +#: reader.lua:196 +msgid "-d start in debug mode" +msgstr "" + +#: reader.lua:197 +msgid "-h show this usage help" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:106 +msgid "Document menu" +msgstr "" + +#: reader.lua:87 +msgid "Exit" +msgstr "退出" + +#: reader.lua:149 +msgid "FileManager" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:61 +msgid "Help" +msgstr "帮助" + +#: reader.lua:17 +msgid "Home" +msgstr "" + +#: reader.lua:105 +msgid "Home menu" +msgstr "" + +#: reader.lua:202 +msgid "If you don't pass any path, the last viewed document will be opened" +msgstr "" + +#: reader.lua:199 +msgid "If you give the name of a directory instead of a file path, a file" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:64 +msgid "Just kidding, this page is not implemented yet." +msgstr "" + +#: frontend/ui/reader/readermenu.lua:70 +msgid "Languages" +msgstr "语言" + +#: reader.lua:82 +msgid "Last documents" +msgstr "" + +#: frontend/ui/reader/readermenu.lua:34 +msgid "Menu" +msgstr "菜单" + +#: reader.lua:126 +msgid "No reader engine for this file" +msgstr "" + +#: reader.lua:194 +msgid "Read all the books on your E-Ink reader" +msgstr "" + +#: reader.lua:205 +msgid "See http://github.com/koreader/kindlepdfviewer for more info." +msgstr "" + +#: reader.lua:17 +msgid "Show Home Menu" +msgstr "" + +#: frontend/ui/reader/readertoc.lua:87 +msgid "Table of Contents" +msgstr "目录" + +#: frontend/ui/reader/readertoc.lua:5 +msgid "Table of contents" +msgstr "目录" + +#: reader.lua:204 +msgid "This software is licensed under the GPLv3." +msgstr "" + +#: reader.lua:200 +msgid "chooser will show up and let you select a file" +msgstr "" + +#: frontend/ui/reader/readertoc.lua:13 +msgid "show Table of Content menu" +msgstr "显示目录菜单" + +#: frontend/ui/reader/readermenu.lua:34 +msgid "show menu" +msgstr "显示菜单" + +#: reader.lua:193 +msgid "usage: ./reader.lua [OPTION] ... path" +msgstr "" diff --git a/reader.lua b/reader.lua index 61ced9868..236e6239e 100755 --- a/reader.lua +++ b/reader.lua @@ -8,12 +8,13 @@ require "ui/readerui" require "document/document" require "settings" require "dbg" +require "gettext" HomeMenu = InputContainer:new{ item_table = {}, key_events = { - TapShowMenu = { {"Home"}, doc = "Show Home Menu"}, + TapShowMenu = { {_("Home")}, doc = _("Show Home Menu")}, }, ges_events = { TapShowMenu = { @@ -44,14 +45,14 @@ function exitReader() local dev = Device:getTouchInputDev() if dev then local width, height = Screen:getWidth(), Screen:getHeight() - input.fakeTapInput(dev, + input.fakeTapInput(dev, math.min(width, height)/2, math.max(width, height)-30 ) end end end - + os.exit(0) end @@ -78,12 +79,12 @@ function HomeMenu:setUpdateItemTable() }) end table.insert(self.item_table, { - text = "Last documents", + text = _("Last documents"), sub_item_table = hist_sub_item_table, }) table.insert(self.item_table, { - text = "Exit", + text = _("Exit"), callback = function() exitReader() end @@ -101,7 +102,7 @@ function HomeMenu:onTapShowMenu() local home_menu = Menu:new{ show_parent = menu_container, - title = "Home menu", + title = _("Home menu"), item_table = self.item_table, width = Screen:getWidth() - 100, } @@ -121,7 +122,9 @@ end function showReader(file, pass) local document = DocumentRegistry:openDocument(file) if not document then - UIManager:show(InfoMessage:new{ text = "No reader engine for this file" }) + UIManager:show(InfoMessage:new{ + text = _("No reader engine for this file") + }) return end @@ -143,7 +146,7 @@ function showHomePage(path) local FileManager = FileChooser:new{ show_parent = HomePage, - title = "FileManager", + title = _("FileManager"), path = path, width = Screen:getWidth(), height = Screen:getHeight(), @@ -188,19 +191,19 @@ longopts = { } function showusage() - print("usage: ./reader.lua [OPTION] ... path") - print("Read all the books on your E-Ink reader") + print(_("usage: ./reader.lua [OPTION] ... path")) + print(_("Read all the books on your E-Ink reader")) print("") - print("-d start in debug mode") - print("-h show this usage help") + print(_("-d start in debug mode")) + print(_("-h show this usage help")) print("") - print("If you give the name of a directory instead of a file path, a file") - print("chooser will show up and let you select a file") + print(_("If you give the name of a directory instead of a file path, a file")) + print(_("chooser will show up and let you select a file")) print("") - print("If you don't pass any path, the last viewed document will be opened") + print(_("If you don't pass any path, the last viewed document will be opened")) print("") - print("This software is licensed under the GPLv3.") - print("See http://github.com/koreader/kindlepdfviewer for more info.") + print(_("This software is licensed under the GPLv3.")) + print(_("See http://github.com/koreader/kindlepdfviewer for more info.")) return end