File tree Expand file tree Collapse file tree 1 file changed +66
-2
lines changed Expand file tree Collapse file tree 1 file changed +66
-2
lines changed Original file line number Diff line number Diff line change 1
1
"""A conversion module for googletrans"""
2
+ from __future__ import print_function
2
3
import re
4
+ import traceback
3
5
import json
4
6
5
- def format_json (text ):
7
+ def format_json (original ):
6
8
# save state
7
9
states = []
10
+ text = original
8
11
for i , pos in enumerate (re .finditer ('"' , text )):
9
12
p = pos .start () + 1
10
13
if i % 2 == 0 :
@@ -27,5 +30,66 @@ def format_json(text):
27
30
# use slicing to extract those parts of the original string to be kept
28
31
text = text [:p ] + states [j ][1 ] + text [nxt :]
29
32
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 ()
31
38
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
+ }
You can’t perform that action at this time.
0 commit comments