smart-translate 0.1.0__py3-none-any.whl → 0.1.2__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 CHANGED
@@ -1,12 +1,12 @@
1
- from importlib import resources
2
- import json
1
+ # smart_translate/rules.py
3
2
 
4
- def load_custom_rules():
5
- with resources.files("smart_translate.rules").joinpath("custom_rules.json").open("r") as f:
6
- return json.load(f)
3
+ CUSTOM_REPLACEMENTS = {}
7
4
 
5
+ def apply_custom_rules(text, rules=None):
6
+ if rules is None:
7
+ rules = CUSTOM_REPLACEMENTS
8
+
9
+ for key, value in rules.items():
10
+ text = text.replace(key, value)
8
11
 
9
- def apply_custom_rules(text, rules=CUSTOM_REPLACEMENTS):
10
- for src, tgt in rules.items():
11
- text = text.replace(src, tgt)
12
12
  return text
@@ -1,10 +1,7 @@
1
1
  import json
2
- from pathlib import Path
2
+ from importlib import resources
3
3
 
4
- RULES_FILE = Path(__file__).parent / "rules" / "custom.rules.json"
5
4
 
6
- def load_rules():
7
- if RULES_FILE.exists():
8
- with open(RULES_FILE, "r", encoding="utf-8") as f:
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smart-translate
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Rule-based and selective smart translation library
5
5
  Author-email: Onkar Nanavare <onkarnanavare007@gmail.com>
6
6
  License: MIT
@@ -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=RI547JR9fAZWzsvtMs9aoMrfMZ9RewSJ1tVmxs0-B7c,354
5
- smart_translate/rules_loader.py,sha256=LCU3HU7I7VqOaSli_IQcDSPnItnxrVdJFH0mXwM8axQ,267
4
+ smart_translate/rules.py,sha256=gKVJuV8sqtmCYu_hLv2Anb2cS5D4NFinNvKc0wZUusU,261
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.0.dist-info/METADATA,sha256=T_W4BBuNX_CPtMLDxmj5aPXyyyVpr8K9_HK7FjuPk34,314
9
- smart_translate-0.1.0.dist-info/WHEEL,sha256=WnJ8fYhv8N4SYVK2lLYNI6N0kVATA7b0piVUNvqIIJE,91
10
- smart_translate-0.1.0.dist-info/top_level.txt,sha256=_rsLKFGg25xW6sAKnNBl1ZOUvimEK7DcCNTU-W1s6NY,16
11
- smart_translate-0.1.0.dist-info/RECORD,,
8
+ smart_translate-0.1.2.dist-info/METADATA,sha256=sDUcAvwg85o_A8RoaG8tSi3Yl8nSs0VBHpMFURG5fAE,314
9
+ smart_translate-0.1.2.dist-info/WHEEL,sha256=WnJ8fYhv8N4SYVK2lLYNI6N0kVATA7b0piVUNvqIIJE,91
10
+ smart_translate-0.1.2.dist-info/top_level.txt,sha256=_rsLKFGg25xW6sAKnNBl1ZOUvimEK7DcCNTU-W1s6NY,16
11
+ smart_translate-0.1.2.dist-info/RECORD,,