dwani 0.1.11__py3-none-any.whl → 0.1.12__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.
- dwani/translate.py +12 -6
- {dwani-0.1.11.dist-info → dwani-0.1.12.dist-info}/METADATA +1 -1
- {dwani-0.1.11.dist-info → dwani-0.1.12.dist-info}/RECORD +6 -6
- {dwani-0.1.11.dist-info → dwani-0.1.12.dist-info}/WHEEL +0 -0
- {dwani-0.1.11.dist-info → dwani-0.1.12.dist-info}/licenses/LICENSE +0 -0
- {dwani-0.1.11.dist-info → dwani-0.1.12.dist-info}/top_level.txt +0 -0
dwani/translate.py
CHANGED
@@ -25,21 +25,27 @@ lang_code_to_code = {code: code for _, code in language_options}
|
|
25
25
|
def normalize_language(lang):
|
26
26
|
"""Convert language input (name or code) to language code."""
|
27
27
|
lang = lang.strip()
|
28
|
-
# Check if input is a language name (case-insensitive)
|
29
28
|
lang_lower = lang.lower()
|
30
29
|
if lang_lower in lang_name_to_code:
|
31
30
|
return lang_name_to_code[lang_lower]
|
32
|
-
# Check if input is a language code
|
33
31
|
if lang in lang_code_to_code:
|
34
32
|
return lang_code_to_code[lang]
|
35
|
-
# Raise error if language is not supported
|
36
33
|
supported_langs = list(lang_name_to_code.keys()) + list(lang_code_to_code.keys())
|
37
34
|
raise ValueError(f"Unsupported language: {lang}. Supported languages: {supported_langs}")
|
38
35
|
|
36
|
+
def split_into_sentences(text):
|
37
|
+
"""Split a string into sentences based on full stops."""
|
38
|
+
if not text.strip():
|
39
|
+
return []
|
40
|
+
# Split on full stops, preserving non-empty sentences
|
41
|
+
sentences = [s.strip() for s in text.split('.') if s.strip()]
|
42
|
+
return sentences
|
43
|
+
|
39
44
|
def run_translate(client, sentences, src_lang, tgt_lang):
|
40
|
-
|
45
|
+
"""Translate sentences in a single API call."""
|
46
|
+
# Convert single string to list of sentences if necessary
|
41
47
|
if isinstance(sentences, str):
|
42
|
-
sentences =
|
48
|
+
sentences = split_into_sentences(sentences)
|
43
49
|
elif not isinstance(sentences, list):
|
44
50
|
raise ValueError("sentences must be a string or a list of strings")
|
45
51
|
|
@@ -70,4 +76,4 @@ class Translate:
|
|
70
76
|
@staticmethod
|
71
77
|
def run_translate(sentences, src_lang, tgt_lang):
|
72
78
|
from . import _get_client
|
73
|
-
return _get_client()
|
79
|
+
return run_translate(_get_client(), sentences, src_lang, tgt_lang)
|
@@ -5,10 +5,10 @@ dwani/chat.py,sha256=Tui52XBhUyDyN2rOFoLme4oB0Q8fkD9_0tFDAnRzoaU,2979
|
|
5
5
|
dwani/client.py,sha256=VG7MFCF4yLAWyD037YcI3QTUMxRfJZrWTDK-JAurTnY,3356
|
6
6
|
dwani/docs.py,sha256=Cp0Gtudug79GH25toB-Npl35ZFA0TM32oZF2xH1VmNY,10598
|
7
7
|
dwani/exceptions.py,sha256=n06dPmR20rS4T3sJBWHQhGxzg4SJKzird9Hx0YTwwo0,226
|
8
|
-
dwani/translate.py,sha256
|
8
|
+
dwani/translate.py,sha256=c03N8-tN49IBcTA6GMOkrJ3MaVzZ12RnYdLQwRbEeoQ,2794
|
9
9
|
dwani/vision.py,sha256=sjkudW2Jb_PEbRcoZy_S1Wno6K5icZz42pHcpD1FMGs,3607
|
10
|
-
dwani-0.1.
|
11
|
-
dwani-0.1.
|
12
|
-
dwani-0.1.
|
13
|
-
dwani-0.1.
|
14
|
-
dwani-0.1.
|
10
|
+
dwani-0.1.12.dist-info/licenses/LICENSE,sha256=IAD8tbwWZbPWHXgYjabHoMv0aaUzZUYzYiEbfhTCisY,1070
|
11
|
+
dwani-0.1.12.dist-info/METADATA,sha256=aj_vKOlWgfznm_c_RqT82VYKl8FBia0CDQLbf40ZoJU,5791
|
12
|
+
dwani-0.1.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
13
|
+
dwani-0.1.12.dist-info/top_level.txt,sha256=AM5EhkyuO_EXQFR9JIxEV6tAYMCCyc-a1dLifpCGBUk,6
|
14
|
+
dwani-0.1.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|