smart-translate 0.1.0__tar.gz → 0.1.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smart-translate
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Rule-based and selective smart translation library
5
5
  Author-email: Onkar Nanavare <onkarnanavare007@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "smart-translate"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "Rule-based and selective smart translation library"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -0,0 +1,14 @@
1
+ from .rules_loader import load_custom_rules
2
+
3
+ # Load rules ONCE at import time
4
+ CUSTOM_REPLACEMENTS = load_custom_rules()
5
+
6
+
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
+
14
+ return text
@@ -0,0 +1,7 @@
1
+ import json
2
+ from importlib import resources
3
+
4
+
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.1
4
4
  Summary: Rule-based and selective smart translation library
5
5
  Author-email: Onkar Nanavare <onkarnanavare007@gmail.com>
6
6
  License: MIT
@@ -1,12 +0,0 @@
1
- from importlib import resources
2
- import json
3
-
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)
7
-
8
-
9
- def apply_custom_rules(text, rules=CUSTOM_REPLACEMENTS):
10
- for src, tgt in rules.items():
11
- text = text.replace(src, tgt)
12
- return text
@@ -1,10 +0,0 @@
1
- import json
2
- from pathlib import Path
3
-
4
- RULES_FILE = Path(__file__).parent / "rules" / "custom.rules.json"
5
-
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 {}