def test_sms_language_fallback(self):
        message_dict = {
            '*': 'non-translated message',
            'en': 'english message',            # project default
            'hin': 'hindi message',             # schedule default
            'es': 'spanish message',            # user's preferred language
            'kan': 'kannada message',           # arbitrary language to test untranslated case
        }
        user_lang = self.user.get_language_code()
        content = Content()
        content.set_context(
            schedule_instance=Mock(memoized_schedule=Schedule(domain=self.domain, default_language_code='hin'))
        )

        self.domain_obj.sms_language_fallback = LANGUAGE_FALLBACK_NONE
        self.assertEqual(
            content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
            message_dict['es']
        )
        message_dict.pop('es')
        self.assertEqual(
            content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
            ''
        )

        self.domain_obj.sms_language_fallback = LANGUAGE_FALLBACK_SCHEDULE
        self.assertEqual(
            content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
            message_dict['hin']
        )
        message_dict.pop('hin')
        self.assertEqual(
            content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
            ''
        )

        self.domain_obj.sms_language_fallback = LANGUAGE_FALLBACK_DOMAIN
        self.assertEqual(
            content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
            message_dict['en']
        )
        message_dict.pop('en')
        self.assertEqual(
            content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
            ''
        )

        self.domain_obj.sms_language_fallback = LANGUAGE_FALLBACK_UNTRANSLATED
        self.assertEqual(
            content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
            message_dict['*']
        )
        message_dict.pop('kan')

        # Default: same as LANGUAGE_FALLBACK_UNTRANSLATED
        self.domain_obj.sms_language_fallback = None
        self.assertEqual(
            content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
            message_dict['*']
        )
Beispiel #2
0
    def test_get_translation_empty_message(self):
        message_dict = {}
        content = Content()
        content.set_context(schedule_instance=Mock(memoized_schedule=Schedule(
            domain=self.domain)))

        self.assertEqual(
            content.get_translation_from_message_dict(
                self.domain, message_dict, self.user.get_language_code()), '')
Beispiel #3
0
    def test_get_translation_general_default(self):
        message_dict = {
            '*': 'non-translated message',
        }
        content = Content()
        content.set_context(schedule_instance=Mock(memoized_schedule=Schedule(
            domain=self.domain)))

        self.assertEqual(
            content.get_translation_from_message_dict(
                self.domain_obj, message_dict, self.user.get_language_code()),
            message_dict['*'])
Beispiel #4
0
    def test_get_translation_empty_message(self):
        message_dict = {}
        content = Content()
        content.set_context(schedule_instance=Mock(memoized_schedule=Schedule(domain=self.domain)))

        self.assertEqual(
            content.get_translation_from_message_dict(
                self.domain,
                message_dict,
                self.user.get_language_code()
            ),
            ''
        )
Beispiel #5
0
    def test_get_translation_schedule_default(self):
        message_dict = {
            '*': 'non-translated message',
            'en': 'english message',
            'hin': 'hindi message',
        }
        content = Content()
        content.set_context(schedule_instance=Mock(memoized_schedule=Schedule(
            domain=self.domain, default_language_code='hin')))

        self.assertEqual(
            content.get_translation_from_message_dict(
                self.domain, message_dict, self.user.get_language_code()),
            message_dict['hin'])
Beispiel #6
0
    def test_get_translation_general_default(self):
        message_dict = {
            '*': 'non-translated message',
        }
        content = Content()
        content.set_context(schedule_instance=Mock(memoized_schedule=Schedule(domain=self.domain)))

        self.assertEqual(
            content.get_translation_from_message_dict(
                self.domain,
                message_dict,
                self.user.get_language_code()
            ),
            message_dict['*']
        )
Beispiel #7
0
    def test_get_translation_user_preferred(self):
        message_dict = {
            '*': 'non-translated message',
            'en': 'english message',
            'hin': 'hindi message',
            'es': 'spanish message',
        }
        content = Content()
        content.set_context(
            schedule_instance=Mock(memoized_schedule=Schedule(domain=self.domain, default_language_code='hin'))
        )

        self.assertEqual(
            content.get_translation_from_message_dict(
                self.domain,
                message_dict,
                self.user.get_language_code()
            ),
            message_dict['es']
        )