Improve typing of lang.py, and ensure Python 3.8 compatibility
This commit is contained in:
parent
ba1f8895a4
commit
e7c814932d
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user