Alejandro Cremades commited on
Commit
59718b5
1 Parent(s): 28fccb4

Localize card search page

Browse files
Middle_School_Card_Search.py CHANGED
@@ -2,28 +2,30 @@ import streamlit as st
2
  import pandas as pd
3
  import streamlit_common.footer
4
  import streamlit_common.lib as lib
 
5
 
6
  mslist_path = "output/middleschool.csv"
7
  number_shown_results = 20
 
8
 
9
  st.set_page_config(
10
  page_title="Middle School | Card Search",
11
  page_icon="🃏",
12
  layout="wide",
13
  )
14
- st.write(
15
- """
16
- # Middle School Card Search
17
-
18
- Enter any English or Japanese text to find all Middle School legal card titles which include it.
19
- """
20
  )
 
 
21
 
22
  mslist_df = pd.read_csv(mslist_path)
23
  mslist_df.fillna("", inplace=True)
24
- st.write(mslist_df.shape[0], "cards are legal")
25
 
26
- name_input = st.text_input(f"Search by card name").strip()
27
  exact_match = lib.get_legal_cardnames(name_input, mslist_df)
28
  results_en_df = mslist_df[
29
  mslist_df["name"].str.contains(name_input.lower(), case=False)
@@ -38,11 +40,11 @@ if name_input:
38
  if exact_match[2] is not None:
39
  cardname = f"{cardname} / {exact_match[2]}"
40
  st.write(
41
- f"✅ [{cardname}]({lib.compose_scryfall_url(exact_match[1])}) is an exact match"
42
  )
43
- st.write(results_df.shape[0], f'cards found by "{name_input}"')
44
  if results_df.shape[0] > number_shown_results:
45
- st.write(f"Top {number_shown_results} results:")
46
  results_df["link"] = results_df["name"].apply(lib.compose_scryfall_url)
47
  results_df[:number_shown_results].transpose().apply(lib.row_to_link)
48
 
 
2
  import pandas as pd
3
  import streamlit_common.footer
4
  import streamlit_common.lib as lib
5
+ import streamlit_common.locale
6
 
7
  mslist_path = "output/middleschool.csv"
8
  number_shown_results = 20
9
+ _ = streamlit_common.locale.get_locale()
10
 
11
  st.set_page_config(
12
  page_title="Middle School | Card Search",
13
  page_icon="🃏",
14
  layout="wide",
15
  )
16
+ l = st.sidebar.radio(
17
+ label="luage / 言語",
18
+ options=["en", "ja"],
19
+ captions=["English", "日本語"],
 
 
20
  )
21
+ st.write(f'# {_["search"]["title"][l]}')
22
+ st.write(_["search"]["instructions"][l])
23
 
24
  mslist_df = pd.read_csv(mslist_path)
25
  mslist_df.fillna("", inplace=True)
26
+ st.write(f'**{mslist_df.shape[0]}**{_["search"]["cards_are_legal"][l]}')
27
 
28
+ name_input = st.text_input(_["search"]["search_by_card_name"][l]).strip()
29
  exact_match = lib.get_legal_cardnames(name_input, mslist_df)
30
  results_en_df = mslist_df[
31
  mslist_df["name"].str.contains(name_input.lower(), case=False)
 
40
  if exact_match[2] is not None:
41
  cardname = f"{cardname} / {exact_match[2]}"
42
  st.write(
43
+ f'✅ [{cardname}]({lib.compose_scryfall_url(exact_match[1])}) {_["search"]["exact_match"][l]}'
44
  )
45
+ st.write(f'**{results_df.shape[0]}**{_["search"]["cards_found"][l]}')
46
  if results_df.shape[0] > number_shown_results:
47
+ st.write(_["search"]["top_results"][l])
48
  results_df["link"] = results_df["name"].apply(lib.compose_scryfall_url)
49
  results_df[:number_shown_results].transpose().apply(lib.row_to_link)
50
 
streamlit_common/locale.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def get_locale():
2
+ return {
3
+ "search": {
4
+ "title": {"en": "Middle School Card Search", "ja": "ミドルスクール カード検索"},
5
+ "instructions": {
6
+ "en": "Enter any English or Japanese text to find all [Middle School legal](https://www.eternalcentral.com/middleschoolrules/) card titles which include it.",
7
+ "ja": "カードの英語名か日本語名を入力し始めると[ミドルスクールで使用可能](https://www.eternalcentral.com/middleschoolrules/)なカード名が引っかかります。",
8
+ },
9
+ "cards_are_legal": {
10
+ "en": " cards are legal.",
11
+ "ja": "枚 のカードが使用可能です。",
12
+ },
13
+ "search_by_card_name": {
14
+ "en": "Search by card name:",
15
+ "ja": "カード名で検索してください:",
16
+ },
17
+ "exact_match": {
18
+ "en": "is an exact match.",
19
+ "ja": "が完全一致します。",
20
+ },
21
+ "cards_found": {
22
+ "en": " cards were found.",
23
+ "ja": "枚 のカードが見つかりました。",
24
+ },
25
+ "top_results": {
26
+ "en": "Top results:",
27
+ "ja": "上位の検索結果:",
28
+ },
29
+ },
30
+ }