Package: pypi-python-translator
PYPI PYTHON TRANSLATORThis is a translation package that allows you to translate text from one language to another using the Google Translate service. The program provides a user-friendly interface that automatically translates itself into the selected language.Getting StartedTo use this program, you need to install the following libraries:googletrans==4.0.0-rc1fuzzywuzzyYou can install them by running the following command:pipinstallgoogletrans==4.0.0-rc1
pipinstallfuzzywuzzyAnd ofc you need the download package library:pipinstallpypi_python_translatorServicesThe program requires access to Google services for translation. You don't need to write the available Google services into theservices.txtfile. it writes them for just information, if you are interested about services you can usewriteservices()function in your code.Language ExamplesThis file contains a list of languages that can be used with the translation application. Each language entry is in the format"<language code> - <country>". You can refer to this file when using theinit()function.For example:init("en")for Englishinit("tr")for TurkishMake sure to use the appropriate language code when initializing the translation application.Function Referencewriteservices()Writes all Google services to theservices.txtfile for using the transcript.TRnslte(text: str, languages: str) -> strThis is a self-translate function. It translates the giventextinto the specifiedlanguages.writeusage(num)This code will write the given example with the value of "num" as file "example_num.py".init(langg: str) -> anyThis is the main function to start the translation application. It adjusts the interface based on the selected language and prompts the user for the desired exit language. After that, it performs the translations.Please note that this program only runs with a validlanggvalue. If the value is not found in theLanguage_Examplesfile, the code will crash. Make sure to check the examples file for valid language codes.UsageAfter setting up the necessary files and libraries, you can use theinit("language-code")function to start the translation application. The program will guide you through the translation process, displaying the input and output languages, the translated text, and the translation accuracy.Please make sure to enter valid languages and follow the instructions provided by the program.ExamplesExample usages for this package. you can also write those examples by using code:fromtranslatorimport*writeusage(example_number)#for ex -> writeusage(1) writes the first example.Example Usage (1): Using init() function to start program.In this example we are going to use init() function to start main program in given<language code>, no need to much talk this is the easiest.fromtranslatorimport*init("<language code>")#For ex -> init("en") start code in english GUI.NOTE: This code will start program for "1" times, and won't repeat himself.Example Usage (2): Using TRnslte() functionIn this example we are using TRnslte() function to translateyour_messagefromtranslatorimport*your_message="Hello world"translated_message=TRnslte(your_message,"<language code>")print(translated_message)This code will translateyour_messageto the given<language code>and prints.Example Usage (3): Using this program for full file translating;I have to warn you: in this examplewithfunction only supports utf-8 characters. if you want to use any other encoding you can change it by editingencoding=""part.I should note that complex or ambiguous sentences in long files directly affect the accuracy of the translation. If your file is too long (>50 lines) or (>1000 characters), it is recommended to resort to other translation methods.fromtranslatorimport*filecontent=[]withopen("<your_file>.txt","r",encoding="utf-8")asfile:#read the file for translation.#The .txt extension is not mandatory, it can be any extension. The important thing is that you specify the encoding of the file correctly.forlineinfile:line=line.strip()# Remove spaces and empty linesifline:# If line has charactersfilecontent.append(line)withopen("<output_file>.txt","w",encoding="utf-8")asfile:#output file writing, it has to be same encoding with reading fileforlineinfilecontent:#Every line in our list;translated_line=TRnslte(line,"<language_code>")#translate line to the "your language code"file.write(translated_line+"\n")#write the translated line to the file.LICENSESForces/PyPi_Python_Translator is licensed under the
GNU General Public License v2.0