def test_load_translation(self): # Load default translation i18n.get_lang(self.mo_dir, 'en_US', 'messages') t = cherrypy.response.i18n.trans l = cherrypy.response.i18n.locale self.assertIsInstance(t, gettext.GNUTranslations) self.assertEqual("en", l.language)
def test_translation_with_en_us(self): # Get trans i18n.get_lang(self.mo_dir, 'en_US', 'messages') t = cherrypy.response.i18n.trans l = cherrypy.response.i18n.locale self.assertIsInstance(t, gettext.GNUTranslations) self.assertEqual("en", l.language) pass
def test_load_translation_with_accept_language_unknown(self): # Mock a header cherrypy.request.headers["Accept-Language"] = "br_CA" # Load default translation i18n.get_lang(self.mo_dir, 'en_US', 'messages') t = cherrypy.response.i18n.trans l = cherrypy.response.i18n.locale self.assertIsInstance(t, gettext.GNUTranslations) self.assertEqual("en", l.language)
def test_translation_with_fr_en(self): # Get trans i18n.get_lang(self.mo_dir, 'fr', 'messages') t = cherrypy.response.i18n.trans l = cherrypy.response.i18n.locale self.assertIsInstance(t, gettext.GNUTranslations) self.assertEqual("fr", l.language) # Test translation object self.assertEqual("Modifier", t.gettext("Edit")) pass
def test_translation_with_en_fr(self): # Get trans i18n.get_lang(self.mo_dir, 'en', 'messages') t = cherrypy.response.i18n.trans l = cherrypy.response.i18n.locale self.assertIsInstance(t, gettext.GNUTranslations) self.assertEqual("en", l.language) # Test translation object self.assertEqual("Edit", t.gettext("Edit")) # Check if the translation fallback self.assertEqual("Invalid String", t.gettext("Invalid String")) pass