|
import streamlit as st |
|
|
|
|
|
st.set_page_config( |
|
page_title="Keyboard Layout Fixer", |
|
page_icon="⌨️", |
|
layout="centered", |
|
) |
|
|
|
|
|
|
|
st.image( |
|
"https://pcshop.ua/image/catalog/FotoOpis/Apple/MK2A3U%2001.jpg", |
|
caption="Apple Magic Keyboard with Ukrainian/English Layout" |
|
) |
|
|
|
|
|
ukr_to_eng_keyboard_layout = { |
|
'й': 'q', 'ц': 'w', 'у': 'e', 'к': 'r', 'е': 't', 'н': 'y', 'г': 'u', 'ш': 'i', 'щ': 'o', 'з': 'p', 'х': '[', 'ї': ']', 'ф': 'a', 'і': 's', 'в': 'd', 'а': 'f', 'п': 'g', 'р': 'h', 'о': 'j', 'л': 'k', 'д': 'l', 'ж': ';', 'є': "'", 'я': 'z', 'ч': 'x', 'с': 'c', 'м': 'v', 'и': 'b', 'т': 'n', 'ь': 'm', 'б': ',', 'ю': '.', |
|
'Й': 'Q', 'Ц': 'W', 'У': 'E', 'К': 'R', 'Е': 'T', 'Н': 'Y', 'Г': 'U', 'Ш': 'I', 'Щ': 'O', 'З': 'P', 'Х': '{', 'Ї': '}', 'Ф': 'A', 'І': 'S', 'В': 'D', 'А': 'F', 'П': 'G', 'Р': 'H', 'О': 'J', 'Л': 'K', 'Д': 'L', 'Ж': ':', 'Є': '"', 'Я': 'Z', 'Ч': 'X', 'С': 'C', 'М': 'V', 'И': 'B', 'Т': 'N', 'Ь': 'M', 'Б': '<', 'Ю': '>', |
|
"'": '`', '₴': '~', '.': '/', ',': '?' |
|
} |
|
|
|
|
|
eng_to_ukr_keyboard_layout = {v: k for k, v in ukr_to_eng_keyboard_layout.items()} |
|
|
|
def fix_layout(text, layout_map): |
|
""" |
|
Translates text from one keyboard layout to another using a dictionary. |
|
""" |
|
|
|
return "".join([layout_map.get(char, char) for char in text]) |
|
|
|
|
|
st.sidebar.header("Settings") |
|
direction = st.sidebar.radio( |
|
"Choose conversion direction:", |
|
("🇺🇦 Ukrainian → 🇬🇧 English", "🇬🇧 English → 🇺🇦 Ukrainian"), |
|
key="direction_radio" |
|
) |
|
|
|
|
|
st.header("Input") |
|
|
|
|
|
if direction == "🇺🇦 Ukrainian → 🇬🇧 English": |
|
input_label = "Enter text typed in Ukrainian layout (that was meant to be English):" |
|
placeholder_text = "руддщ, цщкдв!" |
|
layout_map = ukr_to_eng_keyboard_layout |
|
else: |
|
input_label = "Enter text typed in English layout (that was meant to be Ukrainian):" |
|
placeholder_text = "ghbdsn, cdsn!" |
|
layout_map = eng_to_ukr_keyboard_layout |
|
|
|
|
|
original_text = st.text_area( |
|
label=input_label, |
|
value="", |
|
placeholder=f"e.g., '{placeholder_text}'", |
|
height=150, |
|
key="input_text_area" |
|
) |
|
|
|
|
|
if original_text: |
|
translated_text = fix_layout(original_text, layout_map) |
|
|
|
st.header("Result") |
|
st.code(translated_text, language=None) |
|
|
|
|
|
st.info("The result text is displayed in the box above for easy copying.") |
|
|
|
else: |
|
st.info("Enter some text in the box above to see the conversion.") |