Class for translating texts and detecting language (based on Google Translator).
Get text translation:
from google_translator_simplified import Translator
Translator.get_translation('pl', 'text for translation', 'en')
Translator.get_translation('de', 'tekst do przetłumaczenia', 'pl')
Translator.get_translation('pl', 'text for translation')
Translator.get_translation('de', 'tekst do przetłumaczenia')
Detect language:
from google_translator_simplified import Translator
Translator.detect_lang('text for translation')
Translator.detect_lang('Mittwoch')
Translator.detect_lang('inny przykład')
Get language abbreviation:
from google_translator_simplified import Translator
Translator.get_abbreviation('english')
Translator.get_abbreviation('polish')
Translator.get_abbreviation('german')
Get language full name:
from google_translator_simplified import Translator
Translator.get_name('en')
Translator.get_name('pl')
Translator.get_name('de')
names list:
from google_translator_simplified import Translator
Translator.names_list[:7]
abbreviation list:
from google_translator_simplified import Translator
Translator.abbreviation_list[:7]
Errors:
from google_translator_simplified import Translator
import unittest
class TestTranslator(unittest.TestCase):
def test_untranslatableError(self):
self.assertRaises(Translator.TranslatorUntranslatableError,
Translator.detect_lang, '')
self.assertRaises(Translator.TranslatorUntranslatableError,
Translator.detect_lang, '``2564&&')
self.assertRaises(Translator.TranslatorUntranslatableError,
Translator.detect_lang, ' ')
self.assertRaises(Translator.TranslatorUntranslatableError,
Translator.detect_lang, ' \t\n')
def test_IncorrectAbbreviation(self):
self.assertRaises(Translator.TranslatorIncorrectAbbreviation,
Translator.get_translation, '', 'text for translation')
self.assertRaises(Translator.TranslatorIncorrectAbbreviation,
Translator.get_translation, 'd', 'text for translation')
self.assertRaises(Translator.TranslatorIncorrectAbbreviation,
Translator.get_translation, 'de', 'text for translation', 'e')