Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 8, 2024
1 parent 81424be commit 5e9b7a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 4 additions & 3 deletions hedy_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
from googletrans import Translator



# Holds the token that needs to be translated, its line number, start and
# end indexes and its value (e.g. ", ").
Rule = namedtuple("Rule", "keyword line start end value")

# stores the connection to Google Translate
translator = Translator()


def keywords_to_dict(lang="nl"):
""" "Return a dictionary of keywords from language of choice. Key is english value is lang of choice"""
base = path.abspath(path.dirname(__file__))
Expand Down Expand Up @@ -81,6 +82,7 @@ def translate_string(string, from_lang, to_lang):
result = translator.translate(string, src=from_lang, dest=to_lang)
return result.text


def translate_keywords(input_string, from_lang="en", to_lang="nl", level=1, translate_strings=False):
""" "Return code with keywords translated to language of choice in level of choice"""

Expand Down Expand Up @@ -247,15 +249,14 @@ def print(self, tree):
if type(argument) is Tree and argument.data == 'text':
self.add_rule("text", "text", argument) # this of course only support 1 string


def print_empty_brackets(self, tree):
self.print(tree)

def ask(self, tree):
self.add_rule("_IS", "is", tree)
self.add_rule("_ASK", "ask", tree)

if self.translate_strings: #it'd be nicer of course if this was not copy-paste from PRINT!
if self.translate_strings: # it'd be nicer of course if this was not copy-paste from PRINT!
# in addition to keywords, we are now also adding plain text strings
# like ask arguments to the list of things that need to be translated
if len(tree.children) > 1:
Expand Down
1 change: 0 additions & 1 deletion tests/test_translation_level/test_translation_level_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def test_print_var_text(self):

self.assertEqual(expected, result)


def test_ask_kewords(self):
code = "hedy is vraag print ask echo"

Expand Down

0 comments on commit 5e9b7a3

Please sign in to comment.