File size: 3,039 Bytes
1cfbccf
 
9d6bb51
 
 
 
 
 
 
 
 
 
f0a3b15
9d6bb51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
08167d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import streamlit as st

# --- Page Configuration ---
st.set_page_config(
    page_title="Keyboard Layout Fixer",
    page_icon="⌨️",
    layout="centered",
)

# --- Image and Title ---
# Display the keyboard image you provided
st.image(
    "https://pcshop.ua/image/catalog/FotoOpis/Apple/MK2A3U%2001.jpg",
    caption="Apple Magic Keyboard with Ukrainian/English Layout"
)

# Provided Ukrainian to English layout map
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', 'Б': '<', 'Ю': '>',
    "'": '`', '₴': '~', '.': '/', ',': '?'
}

# Create the reverse map for English to Ukrainian
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.
    """
    # Use a list comprehension and join for a more efficient implementation
    return "".join([layout_map.get(char, char) for char in text])

# --- Sidebar for Options ---
st.sidebar.header("Settings")
direction = st.sidebar.radio(
    "Choose conversion direction:",
    ("🇺🇦 Ukrainian → 🇬🇧 English", "🇬🇧 English → 🇺🇦 Ukrainian"),
    key="direction_radio"
)

# --- Main App Interface ---
st.header("Input")

# Choose the appropriate label and placeholder based on the direction
if direction == "🇺🇦 Ukrainian → 🇬🇧 English":
    input_label = "Enter text typed in Ukrainian layout (that was meant to be English):"
    placeholder_text = "руддщ, цщкдв!"  # Intended: "hello, world!"
    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!"  # Intended: "привіт, світ!"
    layout_map = eng_to_ukr_keyboard_layout

# Text area for user input
original_text = st.text_area(
    label=input_label,
    value="",
    placeholder=f"e.g., '{placeholder_text}'",
    height=150,
    key="input_text_area"
)

# --- Translation Logic and Output ---
if original_text:
    translated_text = fix_layout(original_text, layout_map)
    
    st.header("Result")
    st.code(translated_text, language=None)
    
    # Simple copy "instruction"
    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.")