Skip to content

Commit e7f1d90

Browse files
authored
feat: make translate_to_language_code optional (#309)
1 parent 84910c0 commit e7f1d90

5 files changed

Lines changed: 35 additions & 4 deletions

File tree

pyrogram/methods/messages/compose_text_with_ai.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ComposeTextWithAI:
2626
async def compose_text_with_ai(
2727
self: "pyrogram.Client",
2828
text: Union[str, "types.FormattedText"],
29-
translate_to_language_code: Optional[str],
29+
translate_to_language_code: Optional[str] = None,
3030
style_name: Optional[str] = None,
3131
add_emojis: Optional[bool] = None,
3232
) -> "types.FormattedText":
@@ -44,6 +44,7 @@ async def compose_text_with_ai(
4444
"fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "he", "iw", "hi", "hmn", "hu", "is", "ig", "id", "in", "ga", "it", "ja", "jv", "kn", "kk", "km", "rw", "ko",
4545
"ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "ny", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr",
4646
"st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tl", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "ji", "yo", "zu"
47+
Defaults to the client's language code.
4748
4849
style_name (``str``, *optional*):
4950
Name of the style of the resulted text.
@@ -53,14 +54,24 @@ async def compose_text_with_ai(
5354
5455
Returns:
5556
:obj:`~pyrogram.types.FormattedText`: On success, information about the composed text is returned.
57+
58+
Example:
59+
.. code-block:: python
60+
61+
await app.compose_text_with_ai(
62+
"hello, how are you?",
63+
translate_to_language_code="ru",
64+
style_name="formal",
65+
add_emojis=True
66+
)
5667
"""
5768
if isinstance(text, str):
5869
text = types.FormattedText(text=text)
5970

6071
r = await self.invoke(
6172
raw.functions.messages.ComposeMessageWithAI(
6273
text=await text.write(self),
63-
translate_to_lang=translate_to_language_code,
74+
translate_to_lang=translate_to_language_code or self.lang_code,
6475
tone=raw.types.InputAiComposeToneDefault(tone=style_name) if style_name else None,
6576
emojify=add_emojis,
6677
)

pyrogram/methods/messages/fix_text_with_ai.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ async def fix_text_with_ai(
3636
3737
Returns:
3838
:obj:`~pyrogram.types.FormattedText`: On success, information about the fixed text is returned.
39+
40+
Example:
41+
.. code-block:: python
42+
43+
app.fix_text_with_ai(
44+
"This statement maay havve feew mistakes"
45+
)
3946
"""
4047
if isinstance(text, str):
4148
text = types.FormattedText(text=text)

pyrogram/methods/messages/summarize_message.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ async def summarize_message(
5757
5858
Returns:
5959
:obj:`~pyrogram.types.FormattedText`: On success, information about the summarized text is returned.
60+
61+
Example:
62+
.. code-block:: python
63+
64+
await app.summarize_message(
65+
chat_id,
66+
message_id,
67+
translate_to_language_code="ru",
68+
tone="neutral"
69+
)
70+
6071
"""
6172
r = await self.invoke(
6273
raw.functions.messages.SummarizeText(

pyrogram/methods/messages/translate_message_text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ async def translate_message_text(
5151
"fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "he", "iw", "hi", "hmn", "hu", "is", "ig", "id", "in", "ga", "it", "ja", "jv", "kn", "kk", "km", "rw", "ko",
5252
"ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "ny", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr",
5353
"st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tl", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "ji", "yo", "zu"
54+
Defaults to the client's language code.
5455
5556
tone (``str``, *optional*):
5657
Tone of the translation.
@@ -66,7 +67,7 @@ async def translate_message_text(
6667
"""
6768
r = await self.invoke(
6869
raw.functions.messages.TranslateText(
69-
to_lang=to_language_code,
70+
to_lang=to_language_code or self.lang_code,
7071
peer=await self.resolve_peer(chat_id),
7172
id=[message_id],
7273
tone=tone

pyrogram/methods/messages/translate_text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async def translate_text(
4545
"fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "he", "iw", "hi", "hmn", "hu", "is", "ig", "id", "in", "ga", "it", "ja", "jv", "kn", "kk", "km", "rw", "ko",
4646
"ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "ny", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr",
4747
"st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tl", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "ji", "yo", "zu"
48+
Defaults to the client's language code.
4849
4950
tone (``str``, *optional*):
5051
Tone of the translation.
@@ -63,7 +64,7 @@ async def translate_text(
6364

6465
r = await self.invoke(
6566
raw.functions.messages.TranslateText(
66-
to_lang=to_language_code,
67+
to_lang=to_language_code or self.lang_code,
6768
text=[await text.write(self)],
6869
tone=tone
6970
)

0 commit comments

Comments
 (0)