Skip to content

Commit

Permalink
freedict: refactor writeWithDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 15, 2024
1 parent cf69365 commit ac9ee85
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions pyglossary/plugins/freedict/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,33 +213,40 @@ def writeChild(item: str | Element, depth: int) -> None:
for child in elem.xpath("child::node()"):
writeChild(child, 0)

def setAttribLangDir(
self,
attrib: dict[str, str],
):
try:
lang = attrib.pop(XMLLANG)
except KeyError:
return

attrib["lang"] = lang

if self._auto_rtl:
langObj = langDict[lang]
if langObj:
attrib["dir"] = "rtl" if langObj.rtl else "ltr"

def writeWithDirection(
self,
hf: T_htmlfile,
child: Element,
tag: str,
) -> None:
attrib = dict(child.attrib)
try:
lang = attrib.pop(XMLLANG)
except KeyError:
pass
else:
attrib["lang"] = lang
if self._auto_rtl:
langObj = langDict[lang]
if langObj:
if langObj.rtl:
attrib["dir"] = "rtl"
else:
attrib["dir"] = "ltr"
attrib: dict[str, str] = dict(child.attrib)

self.setAttribLangDir(attrib)

try:
type_ = attrib.pop("type")
except KeyError:
pass
else:
if type_ != "trans":
attrib["class"] = type_

with hf.element(tag, attrib=attrib):
self.writeRichText(hf, child)

Expand Down

0 comments on commit ac9ee85

Please sign in to comment.