Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Add support for multiple target languages
Browse files Browse the repository at this point in the history
You can now specify more than one language to translate into by
separating them with a comma - either in the config or at runtime.

Example: `tr to:en,fr,de,sv,fi,no Hello my friend!`
  • Loading branch information
dshoreman committed Jun 21, 2019
1 parent 722924a commit 2335fe8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
* Support for setting path to service key file in config
* Ability to translate into multiple comma-separated languages

### Fixed
* Now fails gracefully is path to key JSON is missing or invalid
* Now fails gracefully if path to key JSON is missing or invalid


## [0.3.0] - 2019-06-20
Expand Down
8 changes: 7 additions & 1 deletion translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ def handleQuery(query):
arg, str = strParts
lang_to = arg.split(':')[1].strip()

return translate(str, lang_to, query)
items = []
for lang in lang_to.split(','):
if lang.strip() == "":
continue
items.append(translate(str, lang, query))

return items

def translate(str, target, query):
try:
Expand Down

0 comments on commit 2335fe8

Please sign in to comment.