My Pygame Game Engine
at main 807 B view raw
1## Imports 2 3import json, os 4 5## Class 6 7class Language_Handler: 8 9 ## Current language 10 11 current_language_id = "en_US" 12 13 ## Initialize 14 15 def __init__(self, game): 16 self.game = game 17 18 ## Load language file 19 20 with open(os.path.join("src", "resources", self.game.current_assetpack, "data", "lang", self.current_language_id + ".json"), "r") as lang_file: 21 self.lang_json = json.load(lang_file) 22 23 ## Return the translated text taken from the link 24 ## If no text is found translated in the current language the id will be given 25 26 def translatable_text(self, lang_file_link): 27 if lang_file_link in self.lang_json: 28 text = self.lang_json[lang_file_link] 29 return text 30 else: 31 return lang_file_link 32 33 34 35