smart-translate 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smart_translate/rules.py +10 -8
- smart_translate/rules_loader.py +4 -7
- {smart_translate-0.1.0.dist-info → smart_translate-0.1.1.dist-info}/METADATA +1 -1
- {smart_translate-0.1.0.dist-info → smart_translate-0.1.1.dist-info}/RECORD +6 -6
- {smart_translate-0.1.0.dist-info → smart_translate-0.1.1.dist-info}/WHEEL +0 -0
- {smart_translate-0.1.0.dist-info → smart_translate-0.1.1.dist-info}/top_level.txt +0 -0
smart_translate/rules.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
from
|
|
2
|
-
import json
|
|
1
|
+
from .rules_loader import load_custom_rules
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return json.load(f)
|
|
3
|
+
# Load rules ONCE at import time
|
|
4
|
+
CUSTOM_REPLACEMENTS = load_custom_rules()
|
|
7
5
|
|
|
8
6
|
|
|
9
|
-
def apply_custom_rules(text, rules=
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
def apply_custom_rules(text, rules=None):
|
|
8
|
+
if rules is None:
|
|
9
|
+
rules = CUSTOM_REPLACEMENTS
|
|
10
|
+
|
|
11
|
+
for key, value in rules.items():
|
|
12
|
+
text = text.replace(key, value)
|
|
13
|
+
|
|
12
14
|
return text
|
smart_translate/rules_loader.py
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
|
-
from
|
|
2
|
+
from importlib import resources
|
|
3
3
|
|
|
4
|
-
RULES_FILE = Path(__file__).parent / "rules" / "custom.rules.json"
|
|
5
4
|
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return json.load(f)
|
|
10
|
-
return {}
|
|
5
|
+
def load_custom_rules():
|
|
6
|
+
with resources.files("smart_translate.rules").joinpath("custom_rules.json").open("r", encoding="utf-8") as f:
|
|
7
|
+
return json.load(f)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
smart_translate/__init__.py,sha256=VRuHy9VW11TqaPBWrzodvgAfdzeBzrNG2D6_vfMZTFo,74
|
|
2
2
|
smart_translate/config.py,sha256=GwTSOljxfl7jJTtt-3neUQT8kdWdF8r84jPggUNE26s,374
|
|
3
3
|
smart_translate/protector.py,sha256=X1W7l7gOCCk1juHg1nMZFISg2A84IALLoMP-XWSRx9E,432
|
|
4
|
-
smart_translate/rules.py,sha256=
|
|
5
|
-
smart_translate/rules_loader.py,sha256=
|
|
4
|
+
smart_translate/rules.py,sha256=t9xjwCCYoSSIaafHwa73PIBFxmif0NkZX4eZjGSdHTs,331
|
|
5
|
+
smart_translate/rules_loader.py,sha256=BmFT1CMYtGqL38ioAAoNXonW0CuIUKQ2fojqYmKfTnw,220
|
|
6
6
|
smart_translate/translator.py,sha256=1Sxvgg_Nk2x19yptdAxIPOJypaEGHZda7BLkDjaZ8po,1630
|
|
7
7
|
smart_translate/rules/custom_rules.json,sha256=vSxEV_-9m6KeqTRD99zP-rM0OkfTpcOxrrU4xj3zg_M,59
|
|
8
|
-
smart_translate-0.1.
|
|
9
|
-
smart_translate-0.1.
|
|
10
|
-
smart_translate-0.1.
|
|
11
|
-
smart_translate-0.1.
|
|
8
|
+
smart_translate-0.1.1.dist-info/METADATA,sha256=GKfbwp3M1kuY6IQ7OZcIA9Gpb57tuZxCvajRKbXRlhc,314
|
|
9
|
+
smart_translate-0.1.1.dist-info/WHEEL,sha256=WnJ8fYhv8N4SYVK2lLYNI6N0kVATA7b0piVUNvqIIJE,91
|
|
10
|
+
smart_translate-0.1.1.dist-info/top_level.txt,sha256=_rsLKFGg25xW6sAKnNBl1ZOUvimEK7DcCNTU-W1s6NY,16
|
|
11
|
+
smart_translate-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|