Skip to content

Commit

Permalink
QuickDic6: remove language options in favor of --source-lang and `-…
Browse files Browse the repository at this point in the history
…-target-lang`

also refactor language code detection code
  • Loading branch information
ilius committed Nov 4, 2024
1 parent 8fb74b0 commit 6f54817
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 49 deletions.
8 changes: 3 additions & 5 deletions doc/p/quickdic6.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@

### Write options

| Name | Default | Type | Comment |
| ---------------- | ------- | ---- | -------------------------------------------------- |
| normalizer_rules | | str | ICU normalizer rules to use for index sorting |
| source_lang | | str | The language of the tokens in the dictionary index |
| target_lang | | str | The language of the dictionary entries |
| Name | Default | Type | Comment |
| ---------------- | ------- | ---- | --------------------------------------------- |
| normalizer_rules | | str | ICU normalizer rules to use for index sorting |

### Dependencies for reading

Expand Down
16 changes: 1 addition & 15 deletions plugins-meta/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -1419,28 +1419,14 @@
"type": "str",
"customValue": true,
"comment": "ICU normalizer rules to use for index sorting"
},
"source_lang": {
"class": "StrOption",
"type": "str",
"customValue": true,
"comment": "The language of the tokens in the dictionary index"
},
"target_lang": {
"class": "StrOption",
"type": "str",
"customValue": true,
"comment": "The language of the dictionary entries"
}
},
"canRead": true,
"canWrite": true,
"sortOnWrite": "never",
"readOptions": {},
"writeOptions": {
"normalizer_rules": "",
"source_lang": "",
"target_lang": ""
"normalizer_rules": ""
},
"readDepends": {
"icu": "PyICU"
Expand Down
41 changes: 12 additions & 29 deletions pyglossary/plugins/quickdic6.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pyglossary.core import log
from pyglossary.flags import NEVER
from pyglossary.html_utils import unescape_unicode
from pyglossary.langs import langDict
from pyglossary.option import (
Option,
StrOption,
Expand Down Expand Up @@ -65,12 +64,6 @@
"normalizer_rules": StrOption(
comment="ICU normalizer rules to use for index sorting",
),
"source_lang": StrOption(
comment="The language of the tokens in the dictionary index",
),
"target_lang": StrOption(
comment="The language of the dictionary entries",
),
}

HASH_SET_INIT = (
Expand Down Expand Up @@ -810,8 +803,6 @@ def __iter__(self) -> typing.Iterator[EntryType]:

class Writer:
_normalizer_rules = ""
_source_lang = ""
_target_lang = ""

def __init__(self, glos: GlossaryType) -> None:
self._glos = glos
Expand Down Expand Up @@ -852,28 +843,20 @@ def write(self) -> typing.Generator[None, EntryType, None]:
# specifies the entry type to use.
htmls.append((0, words[0], entry.defi))

glos = self._glos

log.info("Collecting meta data ...")
name = self._glos.getInfo("bookname")
name = glos.getInfo("bookname")
if not name:
name = self._glos.getInfo("description")
name = glos.getInfo("description")

sourceLang = (
self._glos.sourceLang
if not self._source_lang
else langDict[self._source_lang]
)
targetLang = (
self._glos.targetLang
if not self._target_lang
else langDict[self._target_lang]
)
if sourceLang and targetLang:
sourceLang = sourceLang.code
targetLang = targetLang.code
else:
# fallback if no languages are specified
sourceLang = targetLang = "EN"
langs = f"{sourceLang}->{targetLang}"
sourceLangCode, targetLangCode = "EN", "EN"
if glos.sourceLang:
sourceLangCode = glos.sourceLang.code
if glos.targetLang:
targetLangCode = glos.targetLang.code

langs = f"{sourceLangCode}->{targetLangCode}"
if langs not in name.lower():
name = f"{self._glos.getInfo('name')} ({langs})"

Expand All @@ -898,7 +881,7 @@ def write(self) -> typing.Generator[None, EntryType, None]:
# indices: list[EntryIndexTuple] | None = None,
)

short_name = long_name = iso = sourceLang
short_name = long_name = iso = sourceLangCode
normalizer_rules = self._normalizer_rules or (
default_de_normalizer_rules if iso == "DE" else default_normalizer_rules
)
Expand Down

0 comments on commit 6f54817

Please sign in to comment.