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",
|
2024-03-20 22:41:32 +00:00
|
|
|
|
en_GB = "English (United Kingdom)",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
ca = "Catalá",
|
2020-09-20 18:43:13 +00:00
|
|
|
|
cs = "Čeština",
|
2024-01-16 21:33:15 +00:00
|
|
|
|
da = "Dansk",
|
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",
|
2022-05-08 11:52:34 +00:00
|
|
|
|
fi = "Suomi",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
fr = "Français",
|
|
|
|
|
gl = "Galego",
|
|
|
|
|
it_IT = "Italiano",
|
2020-06-30 15:20:03 +00:00
|
|
|
|
he = "עִבְרִית",
|
2022-05-08 11:52:34 +00:00
|
|
|
|
hr = "Hrvatski",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
hu = "Magyar",
|
2022-05-08 11:52:34 +00:00
|
|
|
|
lt_LT = "Lietuvių",
|
2022-05-07 16:36:06 +00:00
|
|
|
|
lv = "Latviešu",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
nl_NL = "Nederlands",
|
2024-01-16 21:33:15 +00:00
|
|
|
|
nb_NO = "Norsk bokmål",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
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",
|
2022-10-12 09:25:43 +00:00
|
|
|
|
th = "ภาษาไทย",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
vi = "Tiếng Việt",
|
|
|
|
|
tr = "Türkçe",
|
|
|
|
|
vi_VN = "Viet Nam",
|
2022-12-02 17:39:47 +00:00
|
|
|
|
ar = "عربى",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
bg_BG = "български",
|
2022-03-15 22:13:13 +00:00
|
|
|
|
bn = "বাংলা",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
el = "Ελληνικά",
|
|
|
|
|
fa = "فارسی",
|
2022-05-08 11:52:34 +00:00
|
|
|
|
hi = "हिन्दी",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
ja = "日本語",
|
2022-05-08 11:52:34 +00:00
|
|
|
|
ka = "ქართული",
|
2019-09-06 15:01:37 +00:00
|
|
|
|
kk = "Қазақ",
|
|
|
|
|
ko_KR = "한글",
|
2021-08-24 21:51:39 +00:00
|
|
|
|
ru = "Русский",
|
2022-05-08 11:52:34 +00:00
|
|
|
|
sr = "Српски",
|
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 UIManager = require("ui/uimanager")
|
2014-03-13 13:52:43 +00:00
|
|
|
|
_.changeLang(lang_locale)
|
|
|
|
|
G_reader_settings:saveSetting("language", lang_locale)
|
2022-12-03 20:29:13 +00:00
|
|
|
|
UIManager:askForRestart(_("Please restart KOReader for the new language setting to take effect."))
|
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"),
|
2024-03-20 22:41:32 +00:00
|
|
|
|
self:genLanguageSubItem("en_GB"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
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"),
|
2022-05-08 11:52:34 +00:00
|
|
|
|
self:genLanguageSubItem("fi"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("fr"),
|
|
|
|
|
self:genLanguageSubItem("gl"),
|
2022-05-08 11:52:34 +00:00
|
|
|
|
self:genLanguageSubItem("hr"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("it_IT"),
|
|
|
|
|
self:genLanguageSubItem("hu"),
|
2022-05-08 11:52:34 +00:00
|
|
|
|
self:genLanguageSubItem("lt_LT"),
|
2022-05-07 16:36:06 +00:00
|
|
|
|
self:genLanguageSubItem("lv"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("nl_NL"),
|
|
|
|
|
self:genLanguageSubItem("nb_NO"),
|
|
|
|
|
self:genLanguageSubItem("pl"),
|
|
|
|
|
--self:genLanguageSubItem("pl_PL"),
|
|
|
|
|
self:genLanguageSubItem("pt_PT"),
|
|
|
|
|
self:genLanguageSubItem("pt_BR"),
|
2024-03-20 22:41:32 +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"),
|
2022-12-02 17:39:47 +00:00
|
|
|
|
self:genLanguageSubItem("ar"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("bg_BG"),
|
|
|
|
|
--self:genLanguageSubItem("bn"),
|
|
|
|
|
self:genLanguageSubItem("el"),
|
2023-01-10 20:27:36 +00:00
|
|
|
|
self:genLanguageSubItem("fa"),
|
2020-06-30 15:20:03 +00:00
|
|
|
|
self:genLanguageSubItem("he"),
|
2022-05-08 11:52:34 +00:00
|
|
|
|
self:genLanguageSubItem("hi"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
self:genLanguageSubItem("ja"),
|
2022-05-08 11:52:34 +00:00
|
|
|
|
self:genLanguageSubItem("ka"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
--self:genLanguageSubItem("kk"),
|
|
|
|
|
self:genLanguageSubItem("ko_KR"),
|
|
|
|
|
self:genLanguageSubItem("ru"),
|
2022-05-08 11:52:34 +00:00
|
|
|
|
self:genLanguageSubItem("sr"),
|
2019-09-06 15:01:37 +00:00
|
|
|
|
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
|