-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPPT cyril to latin.py
77 lines (68 loc) · 2.65 KB
/
PPT cyril to latin.py
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
from pptx import Presentation
from transliterate import translit
import re
import os
def transliterate_word(word):
translit_rules = {
"ю" : "yu", "Ю" : "Yu",
"ў" : "o'", "Ў" : "O'",
"ё" : "yo", "Ё" : "Yo",
"ғ" : "g'", "Ғ" : "G'",
"қ" : "q", "Қ" : "Q",
"ҳ" : "h", "Ҳ" : "H",
"х" : "x", "Х" : "X",
"ж" : "j", "Ж" : "J",
"й" : "y", "Й" : "Y",
"я" : "ya", "Я" : "Ya",
"ц" : "s", "Ц" : "S",
"ы" : "i",
# Agar kerak bo'lsa, boshqa almashtirishlarni qo'shishingiz mumkin
}
# So'zdagi belgilarni qoidalarga muvofiq almashtiramiz
for cyrillic_char, latin_char in translit_rules.items():
word = word.replace(cyrillic_char, latin_char)
# So'z boshida "e" ni va "ye" bilan almashtiramiz
if word.startswith("е"):
if len(word) > 1:
word = "ye" + word[1:]
else:
word = "ye"
elif word.startswith("Е"):
if len(word) > 1:
word = "Ye" + word[1:]
else:
word = "Ye"
return word
pass
def transliterate_presentation(presentation_file):
prs = Presentation(presentation_file)
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
text_frame = shape.text_frame
for paragraph in text_frame.paragraphs:
for run in paragraph.runs:
cyrillic_text = run.text
words = re.split(r"(\s+)", cyrillic_text)
latin_words = [transliterate_word(word) for word in words]
latin_text = "".join(latin_words)
run.text = translit(latin_text, "ru", reversed=True)
prs.save(presentation_file)
def process_presentation_file(file_path):
try:
transliterate_presentation(file_path)
print(f"Fayl muvafaqqiyatli o'zgartirildi ✅: {file_path}")
return True # Muvaffaqiyatli bo'lsa, True qaytaradi
except Exception as e:
print(f"Fayl o'zgartirishida xatolik ❌: {file_path}. Sabab: {str(e)}")
return False # Muvaffaqiyatli bo'lmasa, False qaytaradi
def process_folder(folder_path):
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith('.pptx'):
file_path = os.path.join(root, file)
process_presentation_file(file_path)
# Natija:
presentation_folder = input("Iltimos, PPTX fayllar joylashgan papkani manzilini kiriting: ")
process_folder(presentation_folder)
print("✅✅✅ PPTX fayl kirilchadan lotinchaga muvafaqqiyatli o'girildi ✅✅✅")