Skip to content

Commit 29819f7

Browse files
committed
Add languages, and print excetion with details
1 parent 941ddda commit 29819f7

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

googletrans/conversion.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""A conversion module for googletrans"""
2+
from __future__ import print_function
23
import re
4+
import traceback
35
import json
46

5-
def format_json(text):
7+
def format_json(original):
68
# save state
79
states = []
10+
text = original
811
for i, pos in enumerate(re.finditer('"', text)):
912
p = pos.start() + 1
1013
if i % 2 == 0:
@@ -27,5 +30,66 @@ def format_json(text):
2730
# use slicing to extract those parts of the original string to be kept
2831
text = text[:p] + states[j][1] + text[nxt:]
2932

30-
converted = json.loads(text)
33+
try:
34+
converted = json.loads(text)
35+
except ValueError as e:
36+
print('original text: ', original, ' => ', text)
37+
traceback.print_exc()
3138
return converted
39+
40+
LANGUAGES = {
41+
'af': 'afrikaans',
42+
'sq': 'albanian',
43+
'ar': 'arabic',
44+
'be': 'belarusian',
45+
'bg': 'bulgarian',
46+
'ca': 'catalan',
47+
'zh-CN': 'chinese_simplified',
48+
'zh-TW': 'chinese_traditional',
49+
'hr': 'croatian',
50+
'cs': 'czech',
51+
'da': 'danish',
52+
'nl': 'dutch',
53+
'en': 'english',
54+
'eo': 'esperanto',
55+
'et': 'estonian',
56+
'tl': 'filipino',
57+
'fi': 'finnish',
58+
'fr': 'french',
59+
'gl': 'galician',
60+
'de': 'german',
61+
'el': 'greek',
62+
'iw': 'hebrew',
63+
'hi': 'hindi',
64+
'hu': 'hungarian',
65+
'is': 'icelandic',
66+
'id': 'indonesian',
67+
'ga': 'irish',
68+
'it': 'italian',
69+
'ja': 'japanese',
70+
'ko': 'korean',
71+
'la': 'latin',
72+
'lv': 'latvian',
73+
'lt': 'lithuanian',
74+
'mk': 'macedonian',
75+
'ms': 'malay',
76+
'mt': 'maltese',
77+
'no': 'norwegian',
78+
'fa': 'persian',
79+
'pl': 'polish',
80+
'pt': 'portuguese',
81+
'ro': 'romanian',
82+
'ru': 'russian',
83+
'sr': 'serbian',
84+
'sk': 'slovak',
85+
'sl': 'slovenian',
86+
'es': 'spanish',
87+
'sw': 'swahili',
88+
'sv': 'swedish',
89+
'th': 'thai',
90+
'tr': 'turkish',
91+
'uk': 'ukrainian',
92+
'vi': 'vietnamese',
93+
'cy': 'welsh',
94+
'yi': 'yiddish',
95+
}

0 commit comments

Comments
 (0)