Skip to content

Commit

Permalink
Merge pull request #4 from niskala5570/rapatkan-di-ke
Browse files Browse the repository at this point in the history
Rapatkan di ke
  • Loading branch information
niskala5570 authored May 21, 2023
2 parents d41e7b6 + 758d3aa commit cee4be3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 11 additions & 4 deletions alih-kata-tanpa-penyahtaksa.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def gantikan_tanda(padanan):

return ayat_diterjemah

def baiki_ejaan(teks):
# Cari dan ganti 'د ' dan 'ک ' yang berjarak untuk membetulkan perkataan cthnya 'د سکوله'
teks = re.sub(r'\bد\s', 'د', teks)
teks = re.sub(r'\bک\s', 'ک', teks)

return teks

def alih_kata_sarikata(file_path, translations, padanan_tanda, padanan_tanggaman_akhiran, padanan_tanggaman_awalan):
sarikata = pysubs2.load(file_path)
tidak_teralih = {}
Expand All @@ -63,7 +70,7 @@ def alih_kata_sarikata(file_path, translations, padanan_tanda, padanan_tanggaman
extracted_content[placeholder] = '{' + extract + '}'
teks_dialog = teks_dialog.replace('{' + extract + '}', placeholder)

dialog_terjemah = alih_ayat(teks_dialog, translations, padanan_tanda)
dialog_terjemah = baiki_ejaan(alih_ayat(teks_dialog, translations, padanan_tanda))
dialog_terjemah = "{\\fe-1}" + dialog_terjemah

for placeholder, content in extracted_content.items():
Expand Down Expand Up @@ -106,7 +113,7 @@ def alih_kata_sarikata(file_path, translations, padanan_tanda, padanan_tanggaman

padanan_tanda = {"?": "؟", ";": "⁏", ",": "⹁", ".": "."}
padanan_tanggaman_akhiran = {"lah": "له", "kah": "که", "nya": "ڽ", "kan": "کن", "i": "ي", "ku": "کو", "mu": "مو"}
padanan_tanggaman_awalan = {"ber": "بر", "mem": "س", "se": "س", "tak": "تق", "per": "ڤر"}
padanan_tanggaman_awalan = {"ber": "بر", "mem": "مم", "meng": "مڠ", "se": "س", "tak": "تق", "per": "ڤر"}

files_untranslated = {}

Expand All @@ -122,9 +129,9 @@ def alih_kata_sarikata(file_path, translations, padanan_tanda, padanan_tanggaman
print(f"Perkataan yang tidak teralih dalam \"{fail}\":")
for i, dialog_index in enumerate(tidak_teralih):
dialog = files_untranslated[fail][dialog_index]
print(f"Dialog {dialog_index + 1}: {dialog}")
print(f"Baris {dialog_index + 1}: {dialog}")
print()

print(
"Perlu diingatkan bahawa tidak semua perkataan berimbuhan dapat dialihkan dan perlu ditambah sendiri di dalam kamus.\n\nKata sendi seperti \"di\" \"ke\" dan \"se\" dalam jawi dieja rapat.\nRAPATKAN SENDIRI, JANGAN TAK RAPATKAN"
"Pengalih tulisan ini tidaklah sempurna, sentuhan manusia tetap juga diperlukan."
)
13 changes: 10 additions & 3 deletions alih-kata.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def gantikan_tanda(padanan):

return ayat_diterjemah

def baiki_ejaan(teks):
# Cari dan ganti 'د ' dan 'ک ' yang berjarak untuk membetulkan perkataan cthnya 'د سکوله'
teks = re.sub(r'\bد\s', 'د', teks)
teks = re.sub(r'\bک\s', 'ک', teks)

return teks

def alih_kata_sarikata(file_path, translations, padanan_tanda, padanan_tanggaman_akhiran, padanan_tanggaman_awalan):
sarikata = pysubs2.load(file_path)
tidak_teralih = []
Expand All @@ -77,7 +84,7 @@ def alih_kata_sarikata(file_path, translations, padanan_tanda, padanan_tanggaman
extracted_content[placeholder] = '{' + extract + '}'
teks_dialog = teks_dialog.replace('{' + extract + '}', placeholder)

dialog_terjemah = alih_ayat(teks_dialog, translations, padanan_tanda, chosen_translations)
dialog_terjemah = baiki_ejaan(alih_ayat(teks_dialog, translations, padanan_tanda, chosen_translations))
dialog_terjemah = "{\\fe-1}" + dialog_terjemah

for placeholder, content in extracted_content.items():
Expand Down Expand Up @@ -120,7 +127,7 @@ def alih_kata_sarikata(file_path, translations, padanan_tanda, padanan_tanggaman

padanan_tanda = {"?": "؟", ";": "⁏", ",": "⹁", ".": "."}
padanan_tanggaman_akhiran = {"lah": "له", "kah": "که", "nya": "ڽ", "kan": "کن", "i": "ي", "ku": "کو", "mu": "مو"}
padanan_tanggaman_awalan = {"ber": "بر", "mem": "س", "se": "س", "tak": "تق", "per": "ڤر"}
padanan_tanggaman_awalan = {"ber": "بر", "mem": "مم", "meng": "مڠ", "se": "س", "tak": "تق", "per": "ڤر"}

select_translation = True

Expand Down Expand Up @@ -150,5 +157,5 @@ def alih_kata_sarikata(file_path, translations, padanan_tanda, padanan_tanggaman
print()

print(
"Perlu diingatkan bahawa tidak semua perkataan berimbuhan dapat dialihkan dan perlu ditambah sendiri di dalam kamus.\n\nKata sendi seperti \"di\" \"ke\" dan \"se\" dalam jawi dieja rapat.\nRAPATKAN SENDIRI, JANGAN TAK RAPATKAN"
"Pengalih tulisan ini tidaklah sempurna, sentuhan manusia tetap juga diperlukan."
)

0 comments on commit cee4be3

Please sign in to comment.