mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[RTL UI] adds bidi.lua, bootstrap UI mirroring with RTL languages
Set default language (for Harfbuzz to pick up localized glyphs in a font), default text direction, and UI element mirroring depending on the UI language.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
-- high level wrapper module for gettext
|
||||
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local _ = require("gettext")
|
||||
|
||||
local Language = {
|
||||
@@ -47,13 +45,46 @@ local Language = {
|
||||
zh_TW = "中文(台灣)",
|
||||
["zh_TW.Big5"] = "中文(台灣)(Big5)",
|
||||
},
|
||||
-- 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
|
||||
}
|
||||
}
|
||||
|
||||
function Language:getLanguageName(lang_locale)
|
||||
return self.language_names[lang_locale] or lang_locale
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
function Language:changeLanguage(lang_locale)
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local UIManager = require("ui/uimanager")
|
||||
_.changeLang(lang_locale)
|
||||
G_reader_settings:saveSetting("language", lang_locale)
|
||||
UIManager:show(InfoMessage:new{
|
||||
|
||||
Reference in New Issue
Block a user