def get_languages_list(): gamelangs = [(code.split("_", 1)[0], code) for code in i18n.available_languages()] langcount = {} for language, _ in gamelangs: #language++ langcount[language] = langcount.get(language, 0) + 1 #Load languages data with open(dirs.get_readable_file_in_dirs("languages.json", "i18n")) as langdata: languages = json.load(langdata) output = [] for language, code in gamelangs: if langcount[language] > 1: # There are more countries with this base language. # Use full language+country locale name name = languages.get(code, code) else: #This is the only country using that base language. #Use the (shorter) base language name name = languages.get(language, language) #Choose native or english name output.append((code, name[1] or name[0])) return sorted(output)
def get_languages_list(): gamelangs = [(code.split("_", 1)[0], code) for code in i18n.available_languages()] langcount = {} for language, _ in gamelangs: #language++ langcount[language] = langcount.get(language, 0) + 1 #Load languages data with open(dirs.get_readable_file_in_dirs("languages.json", "i18n")) as langdata: languages = json.load(langdata) output = [] for language, code in gamelangs: if langcount[language] > 1: # There are more countries with this base language. # Use full language+country locale name name = languages.get(code, code) else: #This is the only country using that base language. #Use the (shorter) base language name name = languages.get(language, language) #Choose native or english name output.append((code, name[1] or name[0])) return sorted(output)
def load_significant_numbers(): significant_numbers = g.significant_numbers = [] numbers_file = dirs.get_readable_file_in_dirs("numbers.dat", "data") if numbers_file is None: sys.stderr.write("WARNING: Cannot read file: numbers.dat\n") return with open(numbers_file, 'r', encoding='utf-8') as file: for index, line in enumerate(file): value = line.split("#")[0].strip() if len(value) == 0: continue try: number = int(value) significant_numbers.append(number) except ValueError: sys.stderr.write("WARNING: Invalid number in 'numbers.dat' line: %d\n" % index)
def load_internal_id(): internal_id_file = dirs.get_readable_file_in_dirs("internal_id.dat", "data") g.internal_id_forward = {} g.internal_id_backward = {} with open(internal_id_file, 'r', encoding='utf-8') as file: for index, line in enumerate(file): line = line.strip() if len(line) == 0 or line[0] == "#": continue try: obj, internal_id = line.split("=") obj_type, obj_id = obj.split("|") internal_id = internal_id.strip() obj_type = obj_type.strip() obj_id = obj_id.strip() if not obj_type in g.internal_id_forward: g.internal_id_forward[obj_type] = {} g.internal_id_backward[obj_type] = {} if obj_id in g.internal_id_forward[obj_type]: sys.stderr.write( "WARNING: Overwrite internal ID in 'internal_id.dat' line: %d\n" % index + 1) sys.exit(1) g.internal_id_forward[obj_type][obj_id] = internal_id g.internal_id_backward[obj_type][internal_id] = obj_id except ValueError: sys.stderr.write( "WARNING: Invalid internal ID in 'internal_id.dat' line: %d\n" % index + 1) sys.exit(1)
try: logging.getLogger().addHandler(logging.FileHandler(g.logfile, delay=True)) except TypeError: # Python < 2.6, delay not supported yet. try: logging.getLogger().addHandler(logging.FileHandler(g.logfile)) except IOError: # Probably access denied with --singledir. That's ok g.logfile = None # keep g's defaults intact so we can compare after parsing options and prefs from code import mixer, warning desired_soundbuf = mixer.soundbuf desired_set_grab = None #load prefs from file: save_loc = dirs.get_readable_file_in_dirs("prefs.dat", "pref") if save_loc is not None: prefs = SafeConfigParser() try: with open(save_loc, "r", encoding='utf-8') as savefile: prefs.read_file(savefile) except Exception as reason: sys.stderr.write("Cannot load preferences file %s! (%s)\n" % (save_loc, reason)) sys.exit(1) if prefs.has_section("Preferences"): try: desired_language = prefs.get("Preferences", "lang") if desired_language in i18n.available_languages():