Skip to content

Commit 0052447

Browse files
committed
added translator
1 parent 2717a2c commit 0052447

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

Language Translator/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Translation Script
2+
3+
This Python script allows you to translate a string of text into the language of your choice using the Google Translate service.
4+
5+
## Prerequisites
6+
7+
- Python 3.x
8+
- `googletrans` library (version 4.0.0-rc1 or later)
9+
10+
## Installation
11+
12+
1. Clone the repository or download the script file `translate.py`.
13+
14+
2. Install the required dependencies using the following command:
15+
16+
```shell
17+
pip install googletrans==4.0.0-rc1
18+
19+
## Usage
20+
21+
1. Open a terminal or command prompt.
22+
23+
2. Navigate to the directory where the script is located.
24+
25+
3. Run the script using the following command:
26+
27+
```shell
28+
python language_translator.py
29+
30+
4. Enter the text you want to translate when prompted.
31+
32+
5. Enter the target language code (e.g., 'fr' for French, 'es' for Spanish) when prompted. You can refer to the Google Translate language codes for a list of supported languages.
33+
34+
6. The script will output the translated text.
35+
36+
## Example
37+
38+
Here's an example of how to use the translation script:
39+
40+
```shell
41+
Enter the text you want to translate: Hello, how are you?
42+
Enter the target language (e.g., 'fr' for French, 'es' for Spanish): es
43+
Translated text: ¡Hola, cómo estás?
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from googletrans import Translator
2+
3+
def translate_text(text, target_lang):
4+
translator = Translator()
5+
translated_text = translator.translate(text, dest=target_lang)
6+
return translated_text.text
7+
8+
def main():
9+
text = input("Enter the text you want to translate: ")
10+
target_lang = input("Enter the target language (e.g., 'fr' for French, 'es' for Spanish): ")
11+
translated_text = translate_text(text, target_lang)
12+
print(f"Translated text: {translated_text}")
13+
14+
if __name__ == "__main__":
15+
main()

0 commit comments

Comments
 (0)