2014-01-18 17:23:55 +00:00
|
|
|
|
-- high level wrapper module for gettext
|
|
|
|
|
|
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
2019-09-06 15:01:37 +00:00
|
|
|
|
local Language = {
|
|
|
|
|
language_names = {
|
|
|
|
|
C = "English",
|
|
|
|
|
en = "English",
|
|
|
|
|
ca = "Catalá",
|
2020-09-20 18:43:13 +00:00
|
|
|
|
cs = "Čeština",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
de = "Deutsch",
|
2019-10-21 16:40:40 +00:00
|
|
|
|
eo = "Esperanto",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
es = "Español",
|
|
|
|
|
eu = "Euskara",
|
|
|
|
|
fr = "Français",
|
|
|
|
|
gl = "Galego",
|
|
|
|
|
it_IT = "Italiano",
|
2020-06-30 15:20:03 +00:00
|
|
|
|
he = "עִבְרִית",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
hu = "Magyar",
|
2021-02-01 21:35:15 +00:00
|
|
|
|
ka = "ქართული",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
nl_NL = "Nederlands",
|
|
|
|
|
nb_NO = "Norsk",
|
|
|
|
|
pl = "Polski",
|
|
|
|
|
pl_PL = "Polski2",
|
|
|
|
|
pt_PT = "Português",
|
|
|
|
|
pt_BR = "Português do Brasil",
|
2019-11-30 16:35:39 +00:00
|
|
|
|
ro = "Română",
|
|
|
|
|
ro_MD = "Română (Moldova)",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
sk = "Slovenčina",
|
|
|
|
|
sv = "Svenska",
|
|
|
|
|
vi = "Tiếng Việt",
|
|
|
|
|
tr = "Türkçe",
|
|
|
|
|
vi_VN = "Viet Nam",
|
|
|
|
|
ar_AA = "عربى",
|
|
|
|
|
bg_BG = "български",
|
|
|
|
|
bn = "বাঙালি",
|
|
|
|
|
el = "Ελληνικά",
|
|
|
|
|
fa = "فارسی",
|
|
|
|
|
ja = "日本語",
|
|
|
|
|
kk = "Қазақ",
|
|
|
|
|
ko_KR = "한글",
|
2021-08-24 21:51:39 +00:00
|
|
|
|
ru = "Русский",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
uk = "Українська",
|
|
|
|
|
zh = "中文",
|
|
|
|
|
zh_CN = "简体中文",
|
|
|
|
|
zh_TW = "中文(台灣)",
|
|
|
|
|
["zh_TW.Big5"] = "中文(台灣)(Big5)",
|
|
|
|
|
},
|
2019-12-06 21:55:33 +00:00
|
|
|
|
-- Languages that are written RTL, and should have the UI mirrored.
|
|
|
|
|
-- Should match lang tags defined in harfbuzz/src/hb-ot-tag-table.hh.
|
|
|
|
|
-- https://meta.wikimedia.org/wiki/Template:List_of_language_names_ordered_by_code
|
|
|
|
|
-- Not included are those absent or commented out in hb-ot-tag-table.hh.
|
|
|
|
|
languages_rtl = {
|
|
|
|
|
ar = true, -- Arabic
|
|
|
|
|
arz = true, -- Egyptian Arabic
|
|
|
|
|
ckb = true, -- Sorani (Central Kurdish)
|
|
|
|
|
dv = true, -- Divehi
|
|
|
|
|
fa = true, -- Persian
|
|
|
|
|
he = true, -- Hebrew
|
|
|
|
|
ks = true, -- Kashmiri
|
|
|
|
|
ku = true, -- Kurdish
|
|
|
|
|
ps = true, -- Pashto
|
|
|
|
|
sd = true, -- Sindhi
|
|
|
|
|
ug = true, -- Uyghur
|
|
|
|
|
ur = true, -- Urdu
|
|
|
|
|
yi = true, -- Yiddish
|
|
|
|
|
}
|
2019-09-06 15:01:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Language:getLanguageName(lang_locale)
|
|
|
|
|
return self.language_names[lang_locale] or lang_locale
|
|
|
|
|
end
|
2014-01-18 17:23:55 +00:00
|
|
|
|
|
2019-12-06 21:55:33 +00:00
|
|
|
|
function Language:isLanguageRTL(lang_locale)
|
|
|
|
|
if not lang_locale then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
local lang = lang_locale
|
|
|
|
|
local sep = lang:find("_")
|
|
|
|
|
if sep then
|
|
|
|
|
lang = lang:sub(1, sep-1)
|
|
|
|
|
end
|
|
|
|
|
return self.languages_rtl[lang] or false
|
|
|
|
|
end
|
|
|
|
|
|
2014-01-19 17:59:27 +00:00
|
|
|
|
function Language:changeLanguage(lang_locale)
|
2019-12-06 21:55:33 +00:00
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
2014-03-13 13:52:43 +00:00
|
|
|
|
_.changeLang(lang_locale)
|
|
|
|
|
G_reader_settings:saveSetting("language", lang_locale)
|
|
|
|
|
UIManager:show(InfoMessage:new{
|
2014-11-12 11:29:38 +00:00
|
|
|
|
text = _("Please restart KOReader for the new language setting to take effect."),
|
2014-03-13 13:52:43 +00:00
|
|
|
|
timeout = 3,
|
|
|
|
|
})
|
2014-01-18 17:23:55 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-09-06 15:01:37 +00:00
|
|
|
|
function Language:genLanguageSubItem(lang_locale)
|
2014-03-13 13:52:43 +00:00
|
|
|
|
return {
|
2019-09-06 15:01:37 +00:00
|
|
|
|
text = self:getLanguageName(lang_locale),
|
2014-06-08 06:09:59 +00:00
|
|
|
|
checked_func = function()
|
|
|
|
|
return G_reader_settings:readSetting("language") == lang_locale
|
|
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
self:changeLanguage(lang_locale)
|
|
|
|
|
end
|
|
|
|
|
}
|
2014-01-18 17:23:55 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Language:getLangMenuTable()
|
2014-03-13 13:52:43 +00:00
|
|
|
|
-- cache menu table
|
|
|
|
|
if not self.LangMenuTable then
|
|
|
|
|
self.LangMenuTable = {
|
|
|
|
|
text = _("Language"),
|
|
|
|
|
-- NOTE: language with no translation are commented out for now
|
|
|
|
|
sub_item_table = {
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("C"),
|
|
|
|
|
self:genLanguageSubItem("ca"),
|
2020-09-20 18:43:13 +00:00
|
|
|
|
self:genLanguageSubItem("cs"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("de"),
|
2019-10-21 16:40:40 +00:00
|
|
|
|
self:genLanguageSubItem("eo"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("es"),
|
|
|
|
|
self:genLanguageSubItem("eu"),
|
|
|
|
|
self:genLanguageSubItem("fr"),
|
|
|
|
|
self:genLanguageSubItem("gl"),
|
|
|
|
|
self:genLanguageSubItem("it_IT"),
|
|
|
|
|
self:genLanguageSubItem("hu"),
|
|
|
|
|
self:genLanguageSubItem("nl_NL"),
|
|
|
|
|
self:genLanguageSubItem("nb_NO"),
|
|
|
|
|
self:genLanguageSubItem("pl"),
|
|
|
|
|
--self:genLanguageSubItem("pl_PL"),
|
|
|
|
|
self:genLanguageSubItem("pt_PT"),
|
|
|
|
|
self:genLanguageSubItem("pt_BR"),
|
2019-11-30 16:35:39 +00:00
|
|
|
|
--self:genLanguageSubItem("ro"),
|
2019-12-16 19:21:07 +00:00
|
|
|
|
self:genLanguageSubItem("ro_MD"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("sk"),
|
|
|
|
|
self:genLanguageSubItem("sv"),
|
|
|
|
|
self:genLanguageSubItem("vi"),
|
|
|
|
|
self:genLanguageSubItem("tr"),
|
2019-10-21 16:40:40 +00:00
|
|
|
|
self:genLanguageSubItem("vi_VN"),
|
|
|
|
|
self:genLanguageSubItem("ar_AA"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("bg_BG"),
|
|
|
|
|
--self:genLanguageSubItem("bn"),
|
|
|
|
|
self:genLanguageSubItem("el"),
|
|
|
|
|
--self:genLanguageSubItem("fa"),
|
2020-06-30 15:20:03 +00:00
|
|
|
|
self:genLanguageSubItem("he"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("ja"),
|
|
|
|
|
--self:genLanguageSubItem("kk"),
|
|
|
|
|
self:genLanguageSubItem("ko_KR"),
|
|
|
|
|
self:genLanguageSubItem("ru"),
|
|
|
|
|
self:genLanguageSubItem("uk"),
|
|
|
|
|
--self:genLanguageSubItem("zh"),
|
|
|
|
|
self:genLanguageSubItem("zh_CN"),
|
|
|
|
|
self:genLanguageSubItem("zh_TW"),
|
|
|
|
|
--self:genLanguageSubItem("zh_TW.Big5"),
|
2014-03-13 13:52:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
return self.LangMenuTable
|
2014-01-18 17:23:55 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return Language
|