Add languages, and print excetion with details
This commit is contained in:
parent
941dddaa9a
commit
29819f703c
@ -1,10 +1,13 @@
|
||||
"""A conversion module for googletrans"""
|
||||
from __future__ import print_function
|
||||
import re
|
||||
import traceback
|
||||
import json
|
||||
|
||||
def format_json(text):
|
||||
def format_json(original):
|
||||
# save state
|
||||
states = []
|
||||
text = original
|
||||
for i, pos in enumerate(re.finditer('"', text)):
|
||||
p = pos.start() + 1
|
||||
if i % 2 == 0:
|
||||
@ -27,5 +30,66 @@ def format_json(text):
|
||||
# use slicing to extract those parts of the original string to be kept
|
||||
text = text[:p] + states[j][1] + text[nxt:]
|
||||
|
||||
converted = json.loads(text)
|
||||
try:
|
||||
converted = json.loads(text)
|
||||
except ValueError as e:
|
||||
print('original text: ', original, ' => ', text)
|
||||
traceback.print_exc()
|
||||
return converted
|
||||
|
||||
LANGUAGES = {
|
||||
'af': 'afrikaans',
|
||||
'sq': 'albanian',
|
||||
'ar': 'arabic',
|
||||
'be': 'belarusian',
|
||||
'bg': 'bulgarian',
|
||||
'ca': 'catalan',
|
||||
'zh-CN': 'chinese_simplified',
|
||||
'zh-TW': 'chinese_traditional',
|
||||
'hr': 'croatian',
|
||||
'cs': 'czech',
|
||||
'da': 'danish',
|
||||
'nl': 'dutch',
|
||||
'en': 'english',
|
||||
'eo': 'esperanto',
|
||||
'et': 'estonian',
|
||||
'tl': 'filipino',
|
||||
'fi': 'finnish',
|
||||
'fr': 'french',
|
||||
'gl': 'galician',
|
||||
'de': 'german',
|
||||
'el': 'greek',
|
||||
'iw': 'hebrew',
|
||||
'hi': 'hindi',
|
||||
'hu': 'hungarian',
|
||||
'is': 'icelandic',
|
||||
'id': 'indonesian',
|
||||
'ga': 'irish',
|
||||
'it': 'italian',
|
||||
'ja': 'japanese',
|
||||
'ko': 'korean',
|
||||
'la': 'latin',
|
||||
'lv': 'latvian',
|
||||
'lt': 'lithuanian',
|
||||
'mk': 'macedonian',
|
||||
'ms': 'malay',
|
||||
'mt': 'maltese',
|
||||
'no': 'norwegian',
|
||||
'fa': 'persian',
|
||||
'pl': 'polish',
|
||||
'pt': 'portuguese',
|
||||
'ro': 'romanian',
|
||||
'ru': 'russian',
|
||||
'sr': 'serbian',
|
||||
'sk': 'slovak',
|
||||
'sl': 'slovenian',
|
||||
'es': 'spanish',
|
||||
'sw': 'swahili',
|
||||
'sv': 'swedish',
|
||||
'th': 'thai',
|
||||
'tr': 'turkish',
|
||||
'uk': 'ukrainian',
|
||||
'vi': 'vietnamese',
|
||||
'cy': 'welsh',
|
||||
'yi': 'yiddish',
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user