apply rtl dir to webviews

https://forums.ankiweb.net/t/gui-problems-with-right-to-left-languages/1205
This commit is contained in:
Damien Elmes 2020-07-21 11:52:25 +10:00
parent b5cbfe3bbb
commit 01ff6ab55d
3 changed files with 16 additions and 3 deletions

View File

@ -185,6 +185,10 @@ def set_lang(lang: str, locale_dir: str) -> None:
locale_folder = locale_dir 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 # strip off unicode isolation markers from a translated string
# for testing purposes # for testing purposes
def without_unicode_isolation(s: str) -> str: def without_unicode_isolation(s: str) -> str:

View File

@ -209,7 +209,7 @@ def setupLangAndBackend(
anki.lang.set_lang(lang, ldir) anki.lang.set_lang(lang, ldir)
# switch direction for RTL languages # switch direction for RTL languages
if lang in ("he", "ar", "fa"): if anki.lang.is_rtl(lang):
app.setLayoutDirection(Qt.RightToLeft) app.setLayoutDirection(Qt.RightToLeft)
else: else:
app.setLayoutDirection(Qt.LeftToRight) app.setLayoutDirection(Qt.LeftToRight)

View File

@ -1,6 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import dataclasses import dataclasses
import json import json
import math import math
@ -8,7 +9,8 @@ import re
import sys import sys
from typing import Any, Callable, List, Optional, Sequence, Tuple 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 anki.utils import isLin, isMac, isWin
from aqt import gui_hooks from aqt import gui_hooks
from aqt.qt import * from aqt.qt import *
@ -420,13 +422,19 @@ div[contenteditable="true"]:focus {
body_class = theme_manager.body_class() body_class = theme_manager.body_class()
if is_rtl(anki.lang.currentLang):
lang_dir = "rtl"
else:
lang_dir = "ltr"
html = """ html = """
<!doctype html> <!doctype html>
<html><head> <html><head>
<title>{}</title> <title>{}</title>
<style> <style>
body {{ zoom: {}; background: {}; {} }} body {{ zoom: {}; background: {}; direction: {}; {} }}
{} {}
</style> </style>
@ -438,6 +446,7 @@ body {{ zoom: {}; background: {}; {} }}
self.title, self.title,
self.zoomFactor(), self.zoomFactor(),
self._getWindowColor().name(), self._getWindowColor().name(),
lang_dir,
fontspec, fontspec,
widgetspec, widgetspec,
head, head,