Skip to content

Commit

Permalink
Add languages, and print excetion with details
Browse files Browse the repository at this point in the history
  • Loading branch information
ssut committed Jul 6, 2015
1 parent 941ddda commit 29819f7
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions googletrans/conversion.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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',
}

0 comments on commit 29819f7

Please # to comment.