Localize search

This commit is contained in:
Kiril Kovachev 2024-10-14 12:46:16 +01:00
parent 45c263602b
commit 2100a324df
2 changed files with 17 additions and 6 deletions

View File

@ -4,11 +4,15 @@ EXISTING_STRINGS = {
"log_in", "log_in",
"register", "register",
"log_out", "log_out",
"kanji",
"forum",
"main_page", "main_page",
"username", "username",
"password", "password",
"search", "search",
"search_placeholder" "search_placeholder",
"include_kanji",
"include_kotoba"
} }
ENGLISH = { ENGLISH = {
@ -23,7 +27,9 @@ ENGLISH = {
"username": "Username", "username": "Username",
"password": "Password", "password": "Password",
"search": "Search", "search": "Search",
"search_placeholder": "Enter kanji or word" "search_placeholder": "Enter kanji or word",
"include_kanji": "Include kanji",
"include_kotoba": "Include kotoba"
} }
JAPANESE = { JAPANESE = {
@ -38,7 +44,9 @@ JAPANESE = {
"username": "ユーザー名", "username": "ユーザー名",
"password": "パスワード", "password": "パスワード",
"search": "検索", "search": "検索",
"search_placeholder": "漢字・言葉を入力" "search_placeholder": "漢字・言葉を入力",
"include_kanji": "漢字を含む",
"include_kotoba": "言葉を含む",
} }
LANGUAGES = [ LANGUAGES = [
@ -47,6 +55,9 @@ LANGUAGES = [
] ]
assert all(all(key in lang for key in EXISTING_STRINGS) for lang in LANGUAGES) # Ensure all strings are mapped for all existing languages assert all(all(key in lang for key in EXISTING_STRINGS) for lang in LANGUAGES) # Ensure all strings are mapped for all existing languages
assert not [key for lang in LANGUAGES for key in lang if ((key in lang) and (key not in EXISTING_STRINGS))]
# 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]) -> str: def localize(text_id: str, language: dict[str, str]) -> str:
return language[text_id] return language[text_id]

View File

@ -6,11 +6,11 @@
{% block content %} {% block content %}
<form method="get"> <form method="get">
<label for="search_bar">Search</label> <label for="search_bar">{{ localize("search") }}</label>
<input type="text" id="search_bar" name="keywords" placeholder="{{ localize("search_placeholder") }}" value="{{value}}"> <input type="text" id="search_bar" name="keywords" placeholder="{{ localize("search_placeholder") }}" value="{{value}}">
<label for="include_kanji">Include kanji</label> <label for="include_kanji">{{ localize("include_kanji") }}</label>
<input type="checkbox" id="include_kanji" checked> <input type="checkbox" id="include_kanji" checked>
<label for="include_kanji">Include kotoba</label> <label for="include_kanji">{{ localize("include_kotoba") }}</label>
<input type="checkbox" id="include_kanji" checked> <input type="checkbox" id="include_kanji" checked>
</form> </form>
{% block results %} {% block results %}