-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from jpavonabian/traductor
Refactorización de código
- Loading branch information
Showing
4 changed files
with
20 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
from googletrans import Translator, LANGUAGES | ||
|
||
class TranslatorWrapper: | ||
def __init__(self): | ||
self.translator = Translator() | ||
|
||
# create a single translator instance | ||
# see https://github.com/ssut/py-googletrans/issues/234 | ||
t = None | ||
def translate(self, text="", target="en"): | ||
return self.translator.translate(text, dest=target).text | ||
|
||
def translate(text="", target="en"): | ||
global t | ||
if t == None: | ||
t = Translator() | ||
vars = dict(text=text, dest=target) | ||
return t.translate(**vars).text | ||
@property | ||
def LANGUAGES(self): | ||
return LANGUAGES |