File size: 10,694 Bytes
28db5c0
 
9ad4148
28db5c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad4148
28db5c0
 
 
 
9ad4148
28db5c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad4148
 
 
28db5c0
 
9ad4148
 
28db5c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad4148
 
28db5c0
 
 
 
9ad4148
28db5c0
9ad4148
28db5c0
 
 
9ad4148
28db5c0
9ad4148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28db5c0
 
 
 
 
 
 
9ad4148
 
28db5c0
9ad4148
28db5c0
 
 
 
 
 
9ad4148
 
 
 
 
 
28db5c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad4148
28db5c0
9ad4148
28db5c0
9ad4148
28db5c0
 
 
 
9ad4148
28db5c0
 
 
 
 
9ad4148
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import streamlit as st
from deep_translator import GoogleTranslator
import time

# ================================
# PAGE CONFIGURATION
# ================================
st.set_page_config(
    page_title="Urdu to Pashto Translator",
    page_icon="🌐",
    layout="wide",
    initial_sidebar_state="collapsed"
)

# ================================
# CUSTOM CSS - GLASSMORPHISM THEME
# ================================
def load_css():
    st.markdown("""
    <style>
    @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&family=Righteous&display=swap');
    
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    
    /* Main Background */
    .stApp {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
        background-size: 400% 400%;
        animation: gradientShift 15s ease infinite;
        font-family: 'Poppins', sans-serif;
    }
    
    @keyframes gradientShift {
        0% { background-position: 0% 50%; }
        50% { background-position: 100% 50%; }
        100% { background-position: 0% 50%; }
    }
    
    /* Hide Streamlit Branding */
    #MainMenu {visibility: hidden;}
    footer {visibility: hidden;}
    header {visibility: hidden;}
    
    /* Glass Container */
    .glass-container {
        background: rgba(255, 255, 255, 0.15);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-radius: 25px;
        border: 2px solid rgba(255, 255, 255, 0.3);
        box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
        padding: 40px;
        margin: 20px auto;
        max-width: 1200px;
    }
    
    /* Title Styling */
    .main-title {
        font-family: 'Righteous', cursive;
        font-size: 3.5rem;
        text-align: center;
        background: linear-gradient(135deg, #ffffff 0%, #e0e7ff 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        margin-bottom: 10px;
        text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
        animation: titleGlow 3s ease-in-out infinite;
    }
    
    @keyframes titleGlow {
        0%, 100% { filter: drop-shadow(0 0 10px rgba(255,255,255,0.5)); }
        50% { filter: drop-shadow(0 0 20px rgba(255,255,255,0.8)); }
    }
    
    .subtitle {
        text-align: center;
        color: rgba(255, 255, 255, 0.9);
        font-size: 1.2rem;
        margin-bottom: 40px;
        font-weight: 300;
    }
    
    /* Text Areas */
    .stTextArea textarea {
        background: rgba(255, 255, 255, 0.2) !important;
        backdrop-filter: blur(10px);
        border: 2px solid rgba(255, 255, 255, 0.4) !important;
        border-radius: 15px !important;
        color: #ffffff !important;
        font-size: 1.1rem !important;
        padding: 15px !important;
        font-family: 'Poppins', sans-serif !important;
        transition: all 0.3s ease;
    }
    
    .stTextArea textarea:focus {
        border-color: rgba(255, 255, 255, 0.8) !important;
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.4) !important;
        transform: scale(1.02);
    }
    
    .stTextArea textarea::placeholder {
        color: rgba(255, 255, 255, 0.6) !important;
    }
    
    /* Labels */
    .stTextArea label {
        color: #ffffff !important;
        font-weight: 600 !important;
        font-size: 1.1rem !important;
        margin-bottom: 10px !important;
    }
    
    /* 3D Button Styling */
    .stButton button {
        background: linear-gradient(145deg, #667eea, #764ba2);
        color: white;
        border: none;
        border-radius: 15px;
        padding: 15px 40px;
        font-size: 1.2rem;
        font-weight: 600;
        font-family: 'Poppins', sans-serif;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4),
                    inset 0 -3px 10px rgba(0, 0, 0, 0.2),
                    inset 0 3px 10px rgba(255, 255, 255, 0.2);
        position: relative;
        overflow: hidden;
        width: 100%;
    }
    
    .stButton button:before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
        transition: left 0.5s;
    }
    
    .stButton button:hover:before {
        left: 100%;
    }
    
    .stButton button:hover {
        transform: translateY(-3px) scale(1.05);
        box-shadow: 0 15px 35px rgba(102, 126, 234, 0.6),
                    inset 0 -3px 10px rgba(0, 0, 0, 0.2),
                    inset 0 3px 10px rgba(255, 255, 255, 0.3);
    }
    
    .stButton button:active {
        transform: translateY(0px) scale(1);
        box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
    }
    
    /* Clear Button */
    div[data-testid="column"]:last-child .stButton button {
        background: linear-gradient(145deg, #f093fb, #f5576c);
        box-shadow: 0 10px 25px rgba(245, 87, 108, 0.4);
    }
    
    div[data-testid="column"]:last-child .stButton button:hover {
        box-shadow: 0 15px 35px rgba(245, 87, 108, 0.6);
    }
    
    /* Info Box */
    .info-box {
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(10px);
        border-radius: 15px;
        border: 1px solid rgba(255, 255, 255, 0.3);
        padding: 20px;
        margin: 20px 0;
        color: white;
    }
    
    .info-box h3 {
        color: #ffffff;
        font-weight: 600;
        margin-bottom: 10px;
    }
    
    .info-box p {
        color: rgba(255, 255, 255, 0.8);
        line-height: 1.6;
    }
    
    /* Loading Animation */
    .stSpinner > div {
        border-top-color: #ffffff !important;
    }
    
    /* Success/Warning Messages */
    .stSuccess, .stWarning, .stError {
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(10px);
        border-radius: 10px;
        border: 1px solid rgba(255, 255, 255, 0.4);
        color: white !important;
    }
    
    /* Footer */
    .footer {
        text-align: center;
        color: rgba(255, 255, 255, 0.7);
        margin-top: 50px;
        padding: 20px;
        font-size: 0.9rem;
    }
    
    /* Responsive Design */
    @media (max-width: 768px) {
        .main-title {
            font-size: 2rem;
        }
        
        .subtitle {
            font-size: 1rem;
        }
        
        .glass-container {
            padding: 20px;
        }
    }
    </style>
    """, unsafe_allow_html=True)

# ================================
# TRANSLATION FUNCTIONS
# ================================

def urdu_to_pashto_roman(urdu_text):
    """
    Translate Urdu to Pashto and romanize it
    """
    if not urdu_text.strip():
        return ""
    
    try:
        # Step 1: Translate Urdu to Pashto using Google Translator
        translator_to_pashto = GoogleTranslator(source='ur', target='ps')
        pashto_text = translator_to_pashto.translate(urdu_text)
        
        # Step 2: Create Roman representation
        romanized = create_roman_representation(pashto_text)
        
        return romanized
    
    except Exception as e:
        return f"Translation error: {str(e)}"

def create_roman_representation(pashto_text):
    """
    Create a Roman Urdu representation of Pashto text
    """
    # Comprehensive Pashto to Roman Urdu character mapping (phonetic)
    pashto_to_roman = {
        # Vowels
        'ا': 'a', 'آ': 'aa', 'ع': 'a', 'ء': '',
        # Consonants
        'ب': 'b', 'پ': 'p', 'ت': 't', 'ټ': 't', 'ث': 's',
        'ج': 'j', 'چ': 'ch', 'ح': 'h', 'خ': 'kh',
        'د': 'd', 'ډ': 'd', 'ذ': 'z', 'ر': 'r', 'ړ': 'r',
        'ز': 'z', 'ژ': 'zh', 'ږ': 'g', 'س': 's', 'ش': 'sh',
        'ښ': 'x', 'ص': 's', 'ض': 'z', 'ط': 't', 'ظ': 'z',
        'غ': 'gh', 'ف': 'f', 'ق': 'q', 'ک': 'k', 'ګ': 'g',
        'ل': 'l', 'م': 'm', 'ن': 'n', 'ڼ': 'n',
        'و': 'w', 'ؤ': 'o', 'ه': 'h', 'ۀ': 'a', 'ة': 'a',
        'ي': 'y', 'ې': 'e', 'ی': 'i', 'ئ': 'y', 'ى': 'a',
        # Diacritics and special marks
        'َ': 'a', 'ُ': 'u', 'ِ': 'i', 'ً': 'an', 'ٌ': 'un', 'ٍ': 'in',
        'ّ': '', 'ْ': '', 'ٔ': '', 'ٰ': 'a',
        # Punctuation
        ' ': ' ', '،': ',', '؛': ';', '؟': '?', '۔': '.', '!': '!',
        '(': '(', ')': ')', '[': '[', ']': ']', '{': '{', '}': '}',
        '-': '-', '_': '_', '«': '"', '»': '"', '"': '"', '"': '"',
        # Numbers (Pashto/Arabic numerals to Roman)
        '۰': '0', '۱': '1', '۲': '2', '۳': '3', '۴': '4',
        '۵': '5', '۶': '6', '۷': '7', '۸': '8', '۹': '9',
        '٠': '0', '١': '1', '٢': '2', '٣': '3', '٤': '4',
        '٥': '5', '٦': '6', '٧': '7', '٨': '8', '٩': '9',
    }
    
    # Transliterate Pashto to Roman
    roman_text = ''
    for char in pashto_text:
        roman_text += pashto_to_roman.get(char, char)
    
    # Clean up extra spaces and formatting
    roman_text = ' '.join(roman_text.split())
    
    return roman_text if roman_text.strip() else pashto_text

# ================================
# MAIN APPLICATION
# ================================

def main():
    # Initialize session state
    if 'translation_output' not in st.session_state:
        st.session_state.translation_output = ""
    if 'urdu_input' not in st.session_state:
        st.session_state.urdu_input = ""
    
    # Load custom CSS
    load_css()
    
    # Header
    st.markdown('<h1 class="main-title">🌐 Urdu to Pashto Translator</h1>', unsafe_allow_html=True)
    st.markdown('<p class="subtitle">Convert Urdu sentences to Pashto in Roman script</p>', unsafe_allow_html=True)
    
    # Main container
    st.markdown('<div class="glass-container">', unsafe_allow_html=True)
    
    # Create two columns for input and output
    col1, col2 = st.columns(2)
    
    with col1:
        st.markdown("### 📝 Input (Urdu)")
        urdu_input = st.text_area(
            "Enter Urdu text",
            value=st.session_state.urdu_input,
            height=250,
            placeholder="یہاں اردو متن درج کریں... (Enter Urdu text here...)",
            label_visibility="collapsed",
            key="urdu_input_area"
        )
    
    with col2:
        st.markdown("### 🔤 Output (Pashto in Roman)")
        st.text_area(
            "Pashto translation in Roman script",
            value=st.session_state.translation_output,
            height=250,
            placeholder="Translation will appear here...",
            label_visibility="collapsed",
            key="output_