Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eccb52e

Browse filesBrowse files
josteinlengelke
authored andcommitted
Update main.py (GoogleCloudPlatform#1810)
* Update main.py Fix crash if no translation is needed. Change so that detect_text(), save_result() and translate_text() all use 'lang' in message. Add check for 'und' (undefined) language. Then don't try to translate. * Fix test for change so that detect_text(), save_result() and translate_text() all use 'lang' in message.
1 parent adbdaa8 commit eccb52e
Copy full SHA for eccb52e

File tree

Expand file treeCollapse file tree

2 files changed

+4
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+4
-4
lines changed

‎functions/ocr/app/main.py

Copy file name to clipboardExpand all lines: functions/ocr/app/main.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ def detect_text(bucket, filename):
5757
# Submit a message to the bus for each target language
5858
for target_lang in config.get('TO_LANG', []):
5959
topic_name = config['TRANSLATE_TOPIC']
60-
if src_lang == target_lang:
60+
if src_lang == target_lang or src_lang == 'und':
6161
topic_name = config['RESULT_TOPIC']
6262
message = {
6363
'text': text,
6464
'filename': filename,
65-
'target_lang': target_lang,
65+
'lang': target_lang,
6666
'src_lang': src_lang
6767
}
6868
message_data = json.dumps(message).encode('utf-8')
@@ -113,7 +113,7 @@ def translate_text(event, context):
113113

114114
text = validate_message(message, 'text')
115115
filename = validate_message(message, 'filename')
116-
target_lang = validate_message(message, 'target_lang')
116+
target_lang = validate_message(message, 'lang')
117117
src_lang = validate_message(message, 'src_lang')
118118

119119
print('Translating text into {}.'.format(target_lang))

‎functions/ocr/app/main_test.py

Copy file name to clipboardExpand all lines: functions/ocr/app/main_test.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_translate_text(self, mock_translate_client, mock_publisher):
6262
data = base64.b64encode(json.dumps({
6363
'text': 'menu',
6464
'filename': 'sample-file',
65-
'target_lang': 'es',
65+
'lang': 'es',
6666
'src_lang': 'en'
6767
}).encode('utf-8'))
6868
event = {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.