Skip to content

Commit

Permalink
Various fixes ...
Browse files Browse the repository at this point in the history
- enable recursive src/dest
- fix console entry point
- googletrans vrm++ to address zcribe#7
- update readme for these
  • Loading branch information
arkadianriver committed Oct 23, 2022
1 parent f0f128f commit 7212be9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ Installation
pip install translate-po
```

Usage
Script usage
```python
from translate_po.main import run

run(fro="en" to="et" src="./untranslated" dest="./translated")
run(fro="en", to="et", src="./untranslated", dest="./translated", recursive=True)
```

Command-line usage
```bash
translate-po --fro="en" --to="et" --src="./untranslated" --dest="./translated" --recursive
```

### Changelog
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
},
entry_points={
'console_scripts': [
'sample=sample:main',
'translate-po=translate_po.main:run',
],
},
install_requires=[
'polib>=1.1.0',
'googletrans>=3.0.0'
'googletrans==4.0.0rc1'
],
setup_requires=[
'polib>=1.1.0',
'googletrans>=3.0.0'
'googletrans==4.0.0rc1'
],
)
23 changes: 18 additions & 5 deletions translate_po/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import polib
from googletrans import Translator

from .utilities.constants import UNTRANSLATED_PATH, TRANSLATED_PATH, LANGUAGE_SOURCE, LANGUAGE_DESTINATION
from .utilities.constants import UNTRANSLATED_PATH, TRANSLATED_PATH, LANGUAGE_SOURCE, LANGUAGE_DESTINATION, RECURSIVE
from .utilities.io import read_lines, save_lines
from .utilities.match import recognize_po_file

Expand Down Expand Up @@ -47,12 +47,25 @@ def run(**kwargs):
default=kwargs.get('src', UNTRANSLATED_PATH))
parser.add_argument('--dest', type=str, help='Destination directory you want to translated files to end up in',
default=kwargs.get('dest', TRANSLATED_PATH))
parser.add_argument('--recursive', action='store_true', help='If provided, treat src and dest as directory hierarchies',
default=kwargs.get('recursive', RECURSIVE))
arguments = parser.parse_args()

for file in os.listdir(arguments.src):
if recognize_po_file(file):
found_files = True
solve(os.path.join(arguments.dest, file), os.path.join(arguments.src, file), arguments)
print(arguments)

if arguments.recursive == True:
for root, _, files in os.walk(arguments.src):
for file in files:
if recognize_po_file(file):
found_files = True
relative_path = os.path.relpath(root, arguments.src)
if relative_path == '.': relative_path = ''
solve(os.path.join(arguments.dest, relative_path, file), os.path.join(root, file), arguments)
else:
for file in os.listdir(arguments.src):
if recognize_po_file(file):
found_files = True
solve(os.path.join(arguments.dest, file), os.path.join(arguments.src, file), arguments)

if not found_files:
raise Exception(f"Couldn't find any .po files at: '{arguments.src}'")
Expand Down
1 change: 1 addition & 0 deletions translate_po/utilities/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
TRANSLATED_PATH = "."
LANGUAGE_SOURCE = "en"
LANGUAGE_DESTINATION = "et"
RECURSIVE = False

0 comments on commit 7212be9

Please sign in to comment.