Skip to content

Commit

Permalink
add source and destination lang
Browse files Browse the repository at this point in the history
  • Loading branch information
emregeldegul committed Jan 1, 2022
1 parent 1afbb9b commit 1ae826e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ venv.bak/

# mypy
.mypy_cache/
.idea/
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ Download and install the project.
~$ git clone https://github.com/emregeldegul/tfc && cd tfc
~$ pip install -r requirements.txt
~$ python setup.py install
~$ sudo apt-get install xclip
```

That's it. You can now run the program from the terminal by writing `tfc`.

```bash
~$ tfc
~$ tfc -h
~$ tfc --dest en --src de
```

# Project Idea

I was learning English and every time I encountered with a word that was strange to me, I was looking to its meaning from dictionaries. It was difficult, repetitive and unnecessary. Because of my own necessity and problem I developed this project.

Previously, Ömer Faruk Bayram had written a similar project. But he deleted the project. So I wrote it from scratch.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
certifi==2019.9.11
chardet==3.0.4
idna==2.8
googletrans==3.0.0
googletrans==3.1.0a0
urllib3==1.26.5
xerox==0.4.1
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3

import tfc

from setuptools import setup

setup(name='tfc',
Expand Down
11 changes: 10 additions & 1 deletion tfc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from argparse import ArgumentParser

from .tfc import Translation


def main():
parser = ArgumentParser(description="Simple Translate App From The Clipboard")
parser.add_argument("--dest", help="destination language", default="tr")
parser.add_argument("--src", help="source language", default="auto")
options = parser.parse_args()

print('TFC listens To Your Clipboard For Translation.')
print('='*50)

translation = Translation()
translation = Translation(options.dest, options.src)
translation.start()


if __name__ == '__main__':
main()
10 changes: 6 additions & 4 deletions tfc/tfc.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from .notify import Notify
from googletrans import Translator

from json import loads
from time import sleep
from xerox import paste

class Translation():
def __init__(self):

class Translation:
def __init__(self, dest, src):
self.translate = Translator()
self.notify = Notify()
self.dest = dest
self.src = src

def start(self):
temp_value = ''
Expand All @@ -17,7 +19,7 @@ def start(self):
recent_value = paste()
if recent_value != temp_value:
try:
result = self.translate.translate(recent_value, dest='tr')
result = self.translate.translate(recent_value, dest=self.dest, src=self.src)
self.notify.send(recent_value, result.text)
except Exception as e:
self.notify.send('A Problem Occurred', str(e))
Expand Down

0 comments on commit 1ae826e

Please sign in to comment.