def get_translation(self): """Get translations from API or database.""" existing_translation = Translation.get_by_source_word( self.source_code, self.translate_code, self.source_word) if existing_translation == None: api_translation = query_translation_api(self.source_word, self.source_code, self.translate_code) new_translation = Translation.add_translation( self.source_code, self.translate_code, self.source_word, api_translation) print(f"NEW: {new_translation}", file=sys.stderr) return new_translation.translated_word else: print(f"EXISTING: {existing_translation}", file=sys.stderr) return existing_translation.translated_word