apply rtl dir to webviews
https://forums.ankiweb.net/t/gui-problems-with-right-to-left-languages/1205
This commit is contained in:
parent
b5cbfe3bbb
commit
01ff6ab55d
@ -185,6 +185,10 @@ def set_lang(lang: str, locale_dir: str) -> None:
|
||||
locale_folder = locale_dir
|
||||
|
||||
|
||||
def is_rtl(lang: str) -> bool:
|
||||
return lang in ("he", "ar", "fa")
|
||||
|
||||
|
||||
# strip off unicode isolation markers from a translated string
|
||||
# for testing purposes
|
||||
def without_unicode_isolation(s: str) -> str:
|
||||
|
@ -209,7 +209,7 @@ def setupLangAndBackend(
|
||||
anki.lang.set_lang(lang, ldir)
|
||||
|
||||
# switch direction for RTL languages
|
||||
if lang in ("he", "ar", "fa"):
|
||||
if anki.lang.is_rtl(lang):
|
||||
app.setLayoutDirection(Qt.RightToLeft)
|
||||
else:
|
||||
app.setLayoutDirection(Qt.LeftToRight)
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Copyright: Ankitects Pty Ltd and contributors
|
||||
# -*- coding: utf-8 -*-
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import dataclasses
|
||||
import json
|
||||
import math
|
||||
@ -8,7 +9,8 @@ import re
|
||||
import sys
|
||||
from typing import Any, Callable, List, Optional, Sequence, Tuple
|
||||
|
||||
from anki.lang import _
|
||||
import anki
|
||||
from anki.lang import _, is_rtl
|
||||
from anki.utils import isLin, isMac, isWin
|
||||
from aqt import gui_hooks
|
||||
from aqt.qt import *
|
||||
@ -420,13 +422,19 @@ div[contenteditable="true"]:focus {
|
||||
|
||||
body_class = theme_manager.body_class()
|
||||
|
||||
if is_rtl(anki.lang.currentLang):
|
||||
lang_dir = "rtl"
|
||||
else:
|
||||
lang_dir = "ltr"
|
||||
|
||||
|
||||
html = """
|
||||
<!doctype html>
|
||||
<html><head>
|
||||
<title>{}</title>
|
||||
|
||||
<style>
|
||||
body {{ zoom: {}; background: {}; {} }}
|
||||
body {{ zoom: {}; background: {}; direction: {}; {} }}
|
||||
{}
|
||||
</style>
|
||||
|
||||
@ -438,6 +446,7 @@ body {{ zoom: {}; background: {}; {} }}
|
||||
self.title,
|
||||
self.zoomFactor(),
|
||||
self._getWindowColor().name(),
|
||||
lang_dir,
|
||||
fontspec,
|
||||
widgetspec,
|
||||
head,
|
||||
|
Loading…
Reference in New Issue
Block a user