Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

translate file from one lang to another

i am facing trouble with translating file from one lang to another. kindly please help me to complete it
I gotchu my dude

PHP Code

<?php 
import requests

with open
("file.txt", "r") as f:
    
text = f.readlines()
    
translate = requests.get("https://translate.google.com/#view=home&op=translate&sl=auto&tl=en&text={}".format(text))
    print(
translate.text) 
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn
Could use https://pythonhosted.org/goslate/ , above post won't work, 1 it doesn't try to extract translated text from the form, 2 the form gets it's text set by javascript, so you'd need to use a browser (like selenium) then extract the text from the form, and 3 there is a limit (2000 I believe) on how many characters you can use in a url so you'd have to chunk the text you want to translate
i like python lua js
(Feb 14, 2020 06:31 AM)Riԁdle Wrote:  Could use https://pythonhosted.org/goslate/ , above post won't work, 1 it doesn't try to extract translated text from the form, 2 the form gets it's text set by javascript, so you'd need to use a browser (like selenium) then extract the text from the form, and 3 there is a limit (2000 I believe) on how many characters you can use in a url so you'd have to chunk the text you want to translate


Getting this error🤦‍♂️

translated_line = gs.translate(line)
TypeError: translate() missing 1 required positional argument: 'target_language'
The basic usage is simple:

Code
>>> import goslate
>>> gs = goslate.Goslate()
>>> print(gs.translate('hello world', 'de'))
hallo welt

Example code from link above, you forgot the second parameter, which is the target_language, which looks like it takes abbreviated language name as a string
i like python lua js
(Feb 15, 2020 06:14 AM)Riԁdle Wrote:  The basic usage is simple:

Code
>>> import goslate
>>> gs = goslate.Goslate()
>>> print(gs.translate('hello world', 'de'))
hallo welt

Example code from link above, you forgot the second parameter, which is the target_language, which looks like it takes abbreviated language name as a string

i am getting that but unable to translate whole document at a time🤦‍♂️...... i am trying whatever i can do i am doing but not able to do on complete document
(Feb 15, 2020 08:52 AM)Mr.7 Wrote:  i am getting that but unable to translate whole document at a time🤦‍♂️...... i am trying whatever i can do i am doing but not able to do on complete document

PHP Code

<?php 
import goslate

gs 
= goslate.Goslate()
inputFileName = "my_file.txt"
lang = "de"
with open(inputFileName, "r") as inputf:
 
   outputFileName = f"{inputFileName[-4:}_translate_{lang}.txt"
 
   with open(outputFileName, "w") as outputf:
 
       for line in inputf.readlines():
        
text = inputf.readlines()
        
outputf.write(gs.translate(line, lang)) 
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn
(Feb 15, 2020 12:43 PM)lockhead Wrote:  
PHP Code

<?php 
import goslate

gs 
= goslate.Goslate()
inputFileName = "my_file.txt"
lang = "de"
with open(inputFileName, "r") as inputf:
 
   outputFileName = f"{inputFileName[-4:}_translate_{lang}.txt"
 
   with open(outputFileName, "w") as outputf:
 
       for line in inputf.readlines():
 
       text = inputf.readlines()
 
       outputf.write(gs.translate(line, lang)) 


its working but how to write lines in new line.....
its wrtting whole document in single line only
My dude do you have any idea what you're doing? You really shouldn't just ask people to do all the work for you if you don't have the slightest clue of what's going on.

PHP Code

<?php 
for line in inputf.readlines():
    
#if you remove the "#" a newline character will be added at the end of each line
    #line += "\n"
    
outputf.write(gs.translate(line, lang)) 
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn
(Feb 16, 2020 02:38 AM)lockhead Wrote:  My dude do you have any idea what you're doing? You really shouldn't just ask people to do all the work for you if you don't have the slightest clue of what's going on.

PHP Code

<?php 
for line in inputf.readlines():
 
   #if you remove the "#" a newline character will be added at the end of each line
 
   #line += "\n"
 
   outputf.write(gs.translate(line, lang)) 

this is code

import goslate

gs = goslate.Goslate()
inputFileName = "data1.txt"
lang = "hi"
with open(inputFileName, "r" , encoding="utf8") as inputf:
outputFileName = f"{inputFileName[-4:]}_translate_{lang}.txt"

with open(outputFileName, "w", encoding="UTF-8") as outputf:
for line in inputf.readlines():

text = inputf.readlines()
line += "\n"
outputf.write(gs.translate(line, lang))

getting error like this
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 429: Too Many Requests
(Feb 16, 2020 02:44 AM)Mr.7 Wrote:  this is code

import goslate

gs = goslate.Goslate()
inputFileName = "data1.txt"
lang = "hi"
with open(inputFileName, "r" , encoding="utf8") as inputf:
   outputFileName = f"{inputFileName[-4:]}_translate_{lang}.txt"

   with open(outputFileName, "w", encoding="UTF-8") as outputf:
       for line in inputf.readlines():

           text = inputf.readlines()
           line += "\n"
           outputf.write(gs.translate(line, lang))

gettingerror like this
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib._error_.HTTPError: HTTPerror 429: Too Many Requests
PHP Code

<?php 
import goslate

gs 
= goslate.Goslate()
inputFileName = "my_file.txt"
lang = "de"
with open(inputFileName, "r") as inputf:
    
outputFileName = f"{inputFileName[-4:}_translate_{lang}.txt"
    
with open(outputFileName, "w") as outputf:
        
text = ""
        
for line in inputf.readlines():
            if 
line[-1] != "\n":
                
line += "\n"
            
text += line
        outputf
.write(gs.translate(text, lang)) 
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by simmerFeb 12, 2021 12:07 AM 0 101 Feb 12, 2021 12:07 AM
Last Post: simmer
[C] by N00b_n00bJun 7, 2020 11:47 PM 5 229 Jun 7, 2020 11:47 PM
Last Post: Sajuuk
[Java] by Nemo2478Jun 7, 2020 02:08 AM 3 171 Jun 7, 2020 02:08 AM
Last Post: HFDone