def testLoadFile(self): manager = MockManager() Translator(manager, self.getFolder('i18n.js')) # Verify the call to save self.assertTrue(manager.called) self.assertEqual("en", Translator.locale()) manager.called = False # Change to an existing language Translator.set("fr") self.assertTrue(manager.called) self.assertEqual("fr", Translator.locale()) # Test unkown key self.assertEqual("BOUZOUF", Translator.get("BOUZOUF")) # Test fallback self.assertEqual("Fallback", Translator.get("FALLBACK")) manager.called = False # Try to switch to bad language self.assertRaises(Exception, Translator.set, "de") self.assertEqual("fr", Translator.locale()) self.assertFalse(manager.called) self.assertRaises(Exception, Translator.set, "es") self.assertEqual("fr", Translator.locale()) # Nothing should be saved self.assertFalse(manager.called) # Go back to an existing one Translator.set("en") self.assertTrue(manager.called) self.assertEqual("en", Translator.locale()) self.assertEqual("BOUZOUF", Translator.get("BOUZOUF"))
def set_language(self, locale): try: Translator.set(str(locale)) except Exception as e: log.exception(e)
def set_language(self, locale): try: Translator.set(str(locale)) except RuntimeError as e: log.exception(repr(e))