예제 #1
0
    def test_33_register_unregister(self):
        """
        Testing register/unregister.
        """
        from transliterate.contrib.languages.hy.translit_language_pack import ArmenianLanguagePack

        class A(TranslitLanguagePack):
            language_code = "ru"
            language_name = "Example"
            mapping = (
                u"abcdefghij",
                u"1234567890",
            )
        # Since key `ru` already exists in the registry it can't be replaced (without force-register).
        res = registry.register(A)
        self.assertTrue(not res)

        # Now with force-register it can.
        res = registry.register(A, force=True)
        self.assertTrue(res)

        # Once we have it there and it's forced, we can't register another.
        res = registry.register(A, force=True)
        self.assertTrue(not res)

        # Unregister non-forced language pack.
        res = registry.unregister(ArmenianLanguagePack)
        self.assertTrue(res and not ArmenianLanguagePack.language_code in get_available_language_codes())

        res = registry.unregister(A)
        self.assertTrue(not res and A.language_code in get_available_language_codes())
예제 #2
0
    def test_33_register_unregister(self):
        """
        Testing register/unregister.
        """
        from transliterate.contrib.languages.hy.translit_language_pack import ArmenianLanguagePack

        class A(TranslitLanguagePack):
            language_code = "ru"
            language_name = "Example"
            mapping = (
                u"abcdefghij",
                u"1234567890",
            )

        # Since key `ru` already exists in the registry it can't be replaced (without force-register).
        res = registry.register(A)
        self.assertTrue(not res)

        # Now with force-register it can.
        res = registry.register(A, force=True)
        self.assertTrue(res)

        # Once we have it there and it's forced, we can't register another.
        res = registry.register(A, force=True)
        self.assertTrue(not res)

        # Unregister non-forced language pack.
        res = registry.unregister(ArmenianLanguagePack)
        self.assertTrue(res and not ArmenianLanguagePack.language_code
                        in get_available_language_codes())

        res = registry.unregister(A)
        self.assertTrue(not res
                        and A.language_code in get_available_language_codes())
예제 #3
0
 def test_01_get_available_language_codes(self):
     """
     Test ``autodiscover`` and ``get_available_language_codes``.
     """
     res = get_available_language_codes()
     res.sort()
     c = ['el', 'hy', 'ka', 'ru'] #'he', 
     c.sort()
     self.assertEqual(res, c)
     return res
예제 #4
0
 def test_01_get_available_language_codes(self):
     """
     Test ``autodiscover`` and ``get_available_language_codes``.
     """
     res = get_available_language_codes()
     res.sort()
     c = ['el', 'hy', 'ka', 'ru']  #'he',
     c.sort()
     self.assertEqual(res, c)
     return res
예제 #5
0
    def test_15_register_custom_language_pack(self):
        """
        Testing registering of a custom language pack.
        """
        class ExampleLanguagePack(TranslitLanguagePack):
            """
            Example language pack.
            """
            language_code = "example"
            language_name = "Example"
            mapping = (
                u"abcdefghij",
                u"1234567890",
            )

        registry.register(ExampleLanguagePack)

        assert 'example' in get_available_language_codes()
        res = translit(self.latin_text, 'example')
        self.assertEqual(res, 'Lor5m 9psum 4olor s9t 1m5t')
        return res
예제 #6
0
    def test_15_register_custom_language_pack(self):
        """
        Testing registering of a custom language pack.
        """
        class ExampleLanguagePack(TranslitLanguagePack):
            """
            Example language pack.
            """
            language_code = "example"
            language_name = "Example"
            mapping = (
                u"abcdefghij",
                u"1234567890",
            )

        registry.register(ExampleLanguagePack)

        assert 'example' in get_available_language_codes()
        res = translit(self.latin_text, 'example')
        self.assertEqual(res, 'Lor5m 9psum 4olor s9t 1m5t')
        return res
예제 #7
0
# Autodiscover available language packs
autodiscover()

print '\nOriginal text\n---------------------------------------'
text = "Lorem ipsum dolor sit amet"
print text

print '\nTransliteration to Armenian\n---------------------------------------'
print translit(text, 'hy')

print '\nTransliteration to Russian\n---------------------------------------'
print translit(text, 'ru')

print '\nList of available (registered) languages\n---------------------------------------'
print get_available_language_codes()

print '\nReversed transliteration from Armenian\n---------------------------------------'
print translit(u'Լօրեմ իպսում դoլoր սիտ ամետ', 'hy', reversed=True)

print '\nReversed transliteration from Russian\n---------------------------------------'
print translit(u'Лорем ипсум долор сит амет', 'ru', reversed=True)

print '\nTesting the function decorator\n---------------------------------------'
from transliterate.decorators import transliterate_function

@transliterate_function(language_code='hy')
def decorator_test_armenian(text):
    return text

print decorator_test_armenian(u"Lorem ipsum dolor sit amet")