diff --git a/kanken_online/lang.py b/kanken_online/lang.py index 386b236..7fe81ea 100644 --- a/kanken_online/lang.py +++ b/kanken_online/lang.py @@ -1,10 +1,11 @@ import json import os from pathlib import Path +from typing import Dict, Optional import click from flask import Flask, session, current_app -LanguageMapping = dict[str, str] +LanguageMapping = Dict[str, str] def load_language(lang_code: str) -> LanguageMapping: with open(Path("kanken_online/static/lang", f"{lang_code}.json")) as f: @@ -29,11 +30,12 @@ update_languages() # assert not any((((key in lang) and (key not in EXISTING_STRINGS)) for key in lang) for lang in LANGUAGES) # Ensure no languages have strings not specified by the main index -def localize(text_id: str, language: dict[str, str] = None) -> str: +def localize(text_id: str, language: Optional[Dict[str, str]] = None) -> str: if language is None: preference = session.get("language", "ja") language = LANGUAGES.get(preference) - return language[text_id] + assert language is not None + return language.get(text_id, text_id) @click.command("add-string")