p2p / index.html
citoreh's picture
Update index.html
3d71029 verified
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Pinglish ↔ Persian Converter</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
padding: 30px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(10px);
}
.header {
text-align: center;
margin-bottom: 30px;
}
.header h1 {
color: #2d3748;
font-size: 2.5rem;
margin-bottom: 10px;
background: linear-gradient(45deg, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.header p {
color: #718096;
font-size: 1.1rem;
}
.converter-section {
display: grid;
grid-template-columns: 1fr auto 1fr;
gap: 20px;
align-items: center;
margin-bottom: 30px;
}
.input-section, .output-section {
background: #f7fafc;
border-radius: 15px;
padding: 20px;
border: 2px solid #e2e8f0;
transition: all 0.3s ease;
}
.input-section:focus-within, .output-section:focus-within {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.section-title {
font-weight: 600;
color: #2d3748;
margin-bottom: 10px;
font-size: 1.1rem;
}
textarea {
width: 100%;
height: 150px;
border: none;
background: transparent;
resize: vertical;
font-size: 16px;
font-family: inherit;
outline: none;
color: #2d3748;
line-height: 1.5;
}
.persian-text {
direction: rtl;
text-align: right;
font-family: 'B Nazanin', 'Tahoma', serif;
font-size: 18px;
}
.swap-button {
background: linear-gradient(45deg, #667eea, #764ba2);
border: none;
border-radius: 50%;
width: 60px;
height: 60px;
color: white;
font-size: 24px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.swap-button:hover {
transform: rotate(180deg) scale(1.1);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.controls {
display: flex;
justify-content: center;
gap: 15px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 10px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
font-size: 14px;
}
.btn-primary {
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
}
.btn-secondary {
background: #e2e8f0;
color: #4a5568;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.examples {
background: #f0fff4;
border-radius: 15px;
padding: 20px;
margin-top: 20px;
border-left: 4px solid #48bb78;
}
.examples h3 {
color: #2d3748;
margin-bottom: 15px;
font-size: 1.2rem;
}
.example-item {
display: grid;
grid-template-columns: 1fr auto 1fr;
gap: 15px;
margin-bottom: 10px;
padding: 10px;
background: white;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
}
.example-item:hover {
background: #f7fafc;
transform: translateY(-1px);
}
.example-pinglish {
color: #2b6cb0;
font-family: monospace;
}
.example-persian {
color: #2d3748;
direction: rtl;
text-align: right;
font-family: 'B Nazanin', 'Tahoma', serif;
font-size: 16px;
}
.arrow {
color: #718096;
text-align: center;
}
.stats {
display: flex;
justify-content: space-around;
margin-top: 20px;
text-align: center;
}
.stat {
background: rgba(102, 126, 234, 0.1);
padding: 15px;
border-radius: 10px;
flex: 1;
margin: 0 5px;
}
.stat-number {
font-size: 1.5rem;
font-weight: bold;
color: #667eea;
}
.stat-label {
color: #718096;
font-size: 0.9rem;
}
.accuracy-info {
background: #fff3cd;
border: 1px solid #ffeeba;
border-radius: 10px;
padding: 15px;
margin-bottom: 20px;
color: #856404;
}
@media (max-width: 768px) {
.converter-section {
grid-template-columns: 1fr;
gap: 15px;
}
.swap-button {
width: 50px;
height: 50px;
font-size: 20px;
justify-self: center;
}
.header h1 {
font-size: 2rem;
}
.example-item {
grid-template-columns: 1fr;
gap: 5px;
text-align: center;
}
.stats {
flex-direction: column;
gap: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Advanced Pinglish ↔ Persian Converter</h1>
<p>Accurate conversion using Persian linguistics and common patterns</p>
</div>
<div class="accuracy-info">
<strong>🎯 Enhanced Accuracy:</strong> This converter uses advanced Persian language patterns, context-aware rules, and a comprehensive word dictionary for more accurate results.
</div>
<div class="converter-section">
<div class="input-section">
<div class="section-title" id="input-title">Pinglish Input</div>
<textarea
id="input-text"
placeholder="Type your Pinglish text here... (e.g., salam doostam chetori?)"
oninput="convertText()"
></textarea>
</div>
<button class="swap-button" onclick="swapLanguages()" title="Swap languages">
</button>
<div class="output-section">
<div class="section-title" id="output-title">Persian Output</div>
<textarea
id="output-text"
class="persian-text"
placeholder="Your converted text will appear here..."
readonly
></textarea>
</div>
</div>
<div class="controls">
<button class="btn btn-primary" onclick="copyToClipboard()">📋 Copy Result</button>
<button class="btn btn-secondary" onclick="clearAll()">🗑️ Clear All</button>
<button class="btn btn-secondary" onclick="downloadText()">💾 Download</button>
</div>
<div class="stats">
<div class="stat">
<div class="stat-number" id="char-count">0</div>
<div class="stat-label">Characters</div>
</div>
<div class="stat">
<div class="stat-number" id="word-count">0</div>
<div class="stat-label">Words</div>
</div>
<div class="stat">
<div class="stat-number" id="conversion-mode">Smart</div>
<div class="stat-label">Mode</div>
</div>
</div>
<div class="examples">
<h3>💡 Example Conversions (Click to try)</h3>
<div class="example-item" onclick="setExample('salam doostam chetori?', 'سلام دوستم چطوری؟')">
<div class="example-pinglish">salam doostam chetori?</div>
<div class="arrow"></div>
<div class="example-persian">سلام دوستم چطوری؟</div>
</div>
<div class="example-item" onclick="setExample('man irani hastam va farsi harf mizanam', 'من ایرانی هستم و فارسی حرف می‌زنم')">
<div class="example-pinglish">man irani hastam va farsi harf mizanam</div>
<div class="arrow"></div>
<div class="example-persian">من ایرانی هستم و فارسی حرف می‌زنم</div>
</div>
<div class="example-item" onclick="setExample('khosh amadid be khaneh man', 'خوش آمدید به خانه من')">
<div class="example-pinglish">khosh amadid be khaneh man</div>
<div class="arrow"></div>
<div class="example-persian">خوش آمدید به خانه من</div>
</div>
<div class="example-item" onclick="setExample('emrooz havaye tehran che jorieh?', 'امروز هوای تهران چه جوریه؟')">
<div class="example-pinglish">emrooz havaye tehran che jorieh?</div>
<div class="arrow"></div>
<div class="example-persian">امروز هوای تهران چه جوریه؟</div>
</div>
<div class="example-item" onclick="setExample('kheyli mamnoon az shoma', 'خیلی ممنون از شما')">
<div class="example-pinglish">kheyli mamnoon az shoma</div>
<div class="arrow"></div>
<div class="example-persian">خیلی ممنون از شما</div>
</div>
</div>
</div>
<script>
// Comprehensive word dictionary for accurate conversion
const persianDictionary = {
// Common greetings and phrases
'salam': 'سلام',
'doostam': 'دوستم',
'doost': 'دوست',
'chetori': 'چطوری',
'chetor': 'چطور',
'khoobi': 'خوبی',
'khoob': 'خوب',
'bad': 'بد',
'mamnoon': 'ممنون',
'merci': 'مرسی',
'tashakor': 'تشکر',
'khahesh': 'خواهش',
'bebakhshid': 'ببخشید',
'ozr': 'عذر',
// Pronouns
'man': 'من',
'to': 'تو',
'shoma': 'شما',
'oo': 'او',
'un': 'اون',
'ma': 'ما',
'anha': 'آنها',
'unha': 'اونها',
// Common verbs
'hastam': 'هستم',
'hasti': 'هستی',
'hastid': 'هستید',
'hast': 'هست',
'hastand': 'هستند',
'mizanam': 'می‌زنم',
'mizani': 'می‌زنی',
'mizanad': 'می‌زند',
'mizanim': 'می‌زنیم',
'mizanid': 'می‌زنید',
'mizanand': 'می‌زنند',
'miram': 'می‌رم',
'miri': 'می‌ری',
'mirad': 'می‌رود',
'mirim': 'می‌ریم',
'mirid': 'می‌رید',
'mirand': 'می‌روند',
'mikham': 'می‌خوام',
'mikhi': 'می‌خوای',
'mikhad': 'می‌خواد',
'mikhahim': 'می‌خواهیم',
'mikhahid': 'می‌خواهید',
'mikhahand': 'می‌خواهند',
'daram': 'دارم',
'dari': 'داری',
'darad': 'دارد',
'darim': 'داریم',
'darid': 'دارید',
'darand': 'دارند',
// Common adjectives
'kheyli': 'خیلی',
'besyar': 'بسیار',
'kam': 'کم',
'ziad': 'زیاد',
'bozorg': 'بزرگ',
'kochak': 'کوچک',
'jadid': 'جدید',
'ghadimi': 'قدیمی',
'ziba': 'زیبا',
'zesht': 'زشت',
'sard': 'سرد',
'garm': 'گرم',
'khoshgel': 'خوشگل',
// Places and locations
'iran': 'ایران',
'tehran': 'تهران',
'isfahan': 'اصفهان',
'shiraz': 'شیراز',
'mashhad': 'مشهد',
'tabriz': 'تبریز',
'khaneh': 'خانه',
'madreseh': 'مدرسه',
'daneshgah': 'دانشگاه',
'bazar': 'بازار',
'park': 'پارک',
'cinema': 'سینما',
'restaurant': 'رستوران',
// Time and dates
'emrooz': 'امروز',
'diruz': 'دیروز',
'farda': 'فردا',
'hala': 'حالا',
'alan': 'الان',
'vaght': 'وقت',
'saat': 'ساعت',
'rooz': 'روز',
'mah': 'ماه',
'sal': 'سال',
'sobh': 'صبح',
'zohr': 'ظهر',
'asr': 'عصر',
'shab': 'شب',
// Common words
'farsi': 'فارسی',
'inglisi': 'انگلیسی',
'zaban': 'زبان',
'harf': 'حرف',
'kelam': 'کلام',
'ketab': 'کتاب',
'film': 'فیلم',
'musiqi': 'موسیقی',
'aks': 'عکس',
'dokhtaar': 'دختر',
'pesar': 'پسر',
'mard': 'مرد',
'zan': 'زن',
'pedar': 'پدر',
'madar': 'مادر',
'baradar': 'برادر',
'khahar': 'خواهر',
'aziz': 'عزیز',
'jan': 'جان',
// Connectors
'va': 'و',
'ya': 'یا',
'be': 'به',
'az': 'از',
'ba': 'با',
'dar': 'در',
'bar': 'بر',
'ta': 'تا',
'che': 'چه',
'agar': 'اگر',
'vali': 'ولی',
'pas': 'پس',
'yani': 'یعنی',
// Expressions
'khosh': 'خوش',
'amadid': 'آمدید',
'befarmayid': 'بفرمایید',
'lotfan': 'لطفاً',
'hatman': 'حتماً',
'albateh': 'البته',
'shayad': 'شاید',
'hargez': 'هرگز',
'hamisheh': 'همیشه',
'baziha': 'بعضی‌ها',
'hameh': 'همه',
'hich': 'هیچ',
'kasi': 'کسی',
'chizi': 'چیزی',
'jaii': 'جایی',
'khodet': 'خودت',
'khodam': 'خودم',
'khoda': 'خدا',
'hafez': 'حافظ',
'ferdowsi': 'فردوسی',
'saadi': 'سعدی',
'rumi': 'رومی',
// Weather and nature
'hava': 'هوا',
'havaye': 'هوای',
'aftab': 'آفتاب',
'mah': 'ماه',
'setareh': 'ستاره',
'baran': 'باران',
'barf': 'برف',
'bad': 'باد',
'darya': 'دریا',
'koh': 'کوه',
'jangal': 'جنگل',
'gol': 'گل',
'derakht': 'درخت',
// Food and drinks
'ghaza': 'غذا',
'ab': 'آب',
'chai': 'چای',
'ghahveh': 'قهوه',
'shir': 'شیر',
'noon': 'نون',
'berenj': 'برنج',
'gosht': 'گوشت',
'morgh': 'مرغ',
'mahi': 'ماهی',
'sabzi': 'سبزی',
'miveh': 'میوه',
'sib': 'سیب',
'porteghal': 'پرتقال',
'angoor': 'انگور',
'hendevaneh': 'هندوانه',
// Questions
'chi': 'چی',
'chera': 'چرا',
'chetor': 'چطور',
'key': 'کی',
'koja': 'کجا',
'kodum': 'کدوم',
'chand': 'چند',
'kam': 'کم',
'jorieh': 'جوریه',
'jori': 'جوری'
};
// Character mapping for letters not in dictionary
const characterMap = {
// Consonants
'b': 'ب', 'p': 'پ', 't': 'ت', 's': 'س', 'j': 'ج',
'd': 'د', 'z': 'ز', 'r': 'ر', 'f': 'ف', 'k': 'ک',
'g': 'گ', 'l': 'ل', 'm': 'م', 'n': 'ن', 'h': 'ه',
'y': 'ی', 'v': 'و', 'w': 'و',
// Digraphs (order matters - check these first)
'kh': 'خ', 'gh': 'غ', 'ch': 'چ', 'sh': 'ش', 'zh': 'ژ',
'th': 'ث', 'dh': 'ذ', 'ss': 'ص', 'dd': 'ض', 'tt': 'ط',
'zz': 'ظ', 'aa': 'آ',
// Vowels and special
'a': 'ا', 'e': 'ه', 'i': 'ی', 'o': 'و', 'u': 'و',
"'": 'ع', 'q': 'ق', 'x': 'کس'
};
// Reverse mapping for Persian to Pinglish
const persianToRoman = {};
Object.keys(persianDictionary).forEach(key => {
persianToRoman[persianDictionary[key]] = key;
});
let isPinglishToPersian = true;
function convertText() {
const input = document.getElementById('input-text').value;
const output = document.getElementById('output-text');
if (isPinglishToPersian) {
output.value = convertPinglishToPersian(input);
output.className = 'persian-text';
} else {
output.value = convertPersianToPinglish(input);
output.className = '';
}
updateStats(input, output.value);
}
function convertPinglishToPersian(text) {
if (!text) return '';
// Clean and prepare text
let result = text.toLowerCase().trim();
// Split into words while preserving punctuation
const words = result.split(/(\s+|[.!?،؟])/);
const convertedWords = words.map(word => {
// Skip whitespace and punctuation
if (/^\s+$/.test(word) || /^[.!?،؟]+$/.test(word)) {
return word === '?' ? '؟' : word === ',' ? '،' : word;
}
// Clean word for lookup
const cleanWord = word.replace(/[.!?،؟]/g, '');
// Check dictionary first
if (persianDictionary[cleanWord]) {
return persianDictionary[cleanWord];
}
// Fallback to character mapping
return convertCharacterByCharacter(cleanWord);
});
return convertedWords.join('').replace(/\s+/g, ' ').trim();
}
function convertCharacterByCharacter(word) {
let result = '';
let i = 0;
while (i < word.length) {
let found = false;
// Check for digraphs first (2 characters)
if (i < word.length - 1) {
const digraph = word.substr(i, 2);
if (characterMap[digraph]) {
result += characterMap[digraph];
i += 2;
found = true;
}
}
// Check single character
if (!found) {
const char = word[i];
if (characterMap[char]) {
result += characterMap[char];
} else {
result += char; // Keep unknown characters as-is
}
i++;
}
}
return result;
}
function convertPersianToPinglish(text) {
if (!text) return '';
// Split into words
const words = text.split(/(\s+|[.!?،؟])/);
const convertedWords = words.map(word => {
// Handle punctuation
if (word === '؟') return '?';
if (word === '،') return ',';
if (/^\s+$/.test(word) || /^[.!?،؟]+$/.test(word)) {
return word;
}
// Clean word for lookup
const cleanWord = word.replace(/[.!?،؟]/g, '');
// Check reverse dictionary
if (persianToRoman[cleanWord]) {
return persianToRoman[cleanWord];
}
// Character by character conversion
return cleanWord.split('').map(char => {
// Find in character map
for (const [roman, persian] of Object.entries(characterMap)) {
if (persian === char) {
return roman;
}
}
return char; // Keep unknown characters
}).join('');
});
return convertedWords.join('').replace(/\s+/g, ' ').trim();
}
function swapLanguages() {
isPinglishToPersian = !isPinglishToPersian;
const inputTitle = document.getElementById('input-title');
const outputTitle = document.getElementById('output-title');
const inputText = document.getElementById('input-text');
const outputText = document.getElementById('output-text');
if (isPinglishToPersian) {
inputTitle.textContent = 'Pinglish Input';
outputTitle.textContent = 'Persian Output';
inputText.placeholder = 'Type your Pinglish text here... (e.g., salam doostam chetori?)';
inputText.className = '';
outputText.className = 'persian-text';
} else {
inputTitle.textContent = 'Persian Input';
outputTitle.textContent = 'Pinglish Output';
inputText.placeholder = 'متن فارسی خود را اینجا تایپ کنید...';
inputText.className = 'persian-text';
outputText.className = '';
}
// Swap content
const temp = inputText.value;
inputText.value = outputText.value;
outputText.value = temp;
convertText();
}
function updateStats(input, output) {
document.getElementById('char-count').textContent = input.length;
document.getElementById('word-count').textContent = input.trim() ? input.trim().split(/\s+/).length : 0;
}
function setExample(pinglish, persian) {
const inputText = document.getElementById('input-text');
if (isPinglishToPersian) {
inputText.value = pinglish;
} else {
inputText.value = persian;
}
convertText();
}
function copyToClipboard() {
const output = document.getElementById('output-text');
output.select();
document.execCommand('copy');
// Visual feedback
const btn = event.target;
const originalText = btn.textContent;
btn.textContent = '✅ Copied!';
btn.style.background = '#48bb78';
setTimeout(() => {
btn.textContent = originalText;
btn.style.background = '';
}, 2000);
}
function clearAll() {
document.getElementById('input-text').value = '';
document.getElementById('output-text').value = '';
updateStats('', '');
}
function downloadText() {
const output = document.getElementById('output-text').value;
if (!output) return;
const blob = new Blob([output], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = isPinglishToPersian ? 'persian_text.txt' : 'pinglish_text.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// Initialize
convertText();
</script>
</body>
</html>