Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 138c0e5

Browse files
gguussJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
Unicode for translation
1 parent 54cffe0 commit 138c0e5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

translate/cloud-client/snippets.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env python
2+
# -*- coding: iso-8859-15 -*-
3+
24

35
# Copyright 2016 Google, Inc.
46
#
@@ -22,6 +24,8 @@
2224
"""
2325

2426
import argparse
27+
import os
28+
import sys
2529

2630
from google.cloud import translate
2731

@@ -97,7 +101,7 @@ def translate_text(target, text):
97101
# Text can also be a sequence of strings, in which case this method
98102
# will return a sequence of results for each text.
99103
result = translate_client.translate(
100-
text,
104+
unicode(text, 'utf8'),
101105
target_language=target)
102106

103107
print(u'Text: {}'.format(result['input']))

translate/cloud-client/snippets_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ def test_translate_text(capsys):
4040
snippets.translate_text('is', 'Hello world')
4141
out, _ = capsys.readouterr()
4242
assert u'Halló heimur' in out
43+
44+
def test_translate_utf8(capsys):
45+
text = '나는 파인애플을 좋아한다.'
46+
snippets.translate_text('en', text)

0 commit comments

Comments
 (0)