Conversion_Kitchen_Code/kitchen_counter/conversion/subtitling/translate.py

176 lines
4.3 KiB
Python
Raw Permalink Normal View History

2024-04-27 09:33:09 +00:00
import sys
import os
from .base import make_directory
from .translation import translate_sub
# ppt = sys.argv[1]
# doc = sys.argv[2]
# mp4 = sys.argv[1]
def translate_subtitle(sub, src, tar, folder):
# lang = {
# 'Arabic': 'ar',
# 'Bengali': 'bn',
# 'Catalan': 'ca',
# 'English': 'en',
# 'French': 'fr',
# 'Gujarati': 'gr',
# 'Hindi': 'hi',
# 'Kannada': 'kn',
# 'Marathi': 'mr',
# 'Spanish': 'es',
# 'Tamil': 'ta',
# 'Telugu': 'te'
# }
lang = {
"Hindi": "hi",
"English": "en",
"Urdu": "ur",
"Arabic": "ar",
"Bengali": "bn",
"Kannada": "kn",
"Tamil": "ta",
"Bulgarian": "bg",
"Bangla": "bn",
"Malayalam": "ml",
"Russian": "ru",
"Serbian": "sr",
"Ukranian": "uk",
"Croatian": "hr",
"Irish": "ga",
"Albanian": "sq",
"Marathi": "mr",
"Persian": "fa",
"Telugu": "te",
"Turkish": "tr",
"Hungarian": "hu",
"Italian": "it",
"Romanian": "ro",
"Punjabi": "pa",
"Gujrati": "gu",
"Odia": "or",
"Chinese": "zh",
"Nepali": "ne",
"French": "fr",
"Spanish": "es",
"Indonesian": "id",
"Greek": "el",
"Japanese": "ja",
"Javanese": "jv",
"Korean": "ko",
"Belarusian": "be",
"Uzbek": "uz",
"Sindhi": "sd",
"Afrikaans": "af",
"German": "de",
"Icelandic": "is",
"Igbo": "ig",
"Latin": "la",
"Portugese": "pt",
"Myanmar": "my",
"Thai": "th",
"Sundanese": "su",
"lo": "Lao",
"amharic": "am",
"Sinhala": "si",
"Azerbaijani": "az",
"Kazak": "kk",
"Macedonian": "mk",
"Bosnian": "bs",
"Pashto": "ps",
"Malagasy": "mg",
"Malay": "ms",
"Yoruba": "yo",
"Czech": "cs",
"Danish": "da",
"Dutch": "nl",
"Tagalog": "tl",
"Norwegian": "no",
"Slovenian": "sl",
" Swedish": "sv",
"Vietnamese": "vi",
"Welsh": "cy",
"Hebrew": "he",
"Armenian": "hy",
"Khmer": "km",
"Georgian": "ka",
"Mongolian": "mn",
"Kurdish": "ku",
"Kyrgyz": "ky",
"Turkmen": "tk",
"Finnish": "fi",
"Haitian Creole": "ht",
"Hawaiian": "haw",
"Lithuanian": "lt",
"Luxembourgish": "lb",
"Maltese": "mt",
"Polish": "pl",
"Esperanto": "eo",
"Tatar": "tt",
"Uyghur": "ug",
"Hausa": "ha",
"Somali": "so",
"Swahili": "sw",
"Yiddish": "yi",
"Basque": "eu",
"Catalan": "ca",
"Cebuano": "ceb",
"Corsican": "co",
"Estonian": "et",
"Frisian": "fy",
"Galician": "gl",
"Hmong": "hmn",
"Kinyarwanda": "rw",
"Latvian": "lv",
"Maori": "mi",
"Samoan": "sm",
"Scots Gaelic": "gd",
"Sesotho": "st",
"Shona": "sn",
"Slovak": "sk",
"Xhosa": "xh",
"Zulu": "zu",
}
# tar_lang = []
# for i in tar:
# tar_lang.append(lang[tar[i]])
src_lang = lang[src]
tar_lang = lang[tar]
sub_file_path = os.path.splitext(folder)[0]
sub_path = make_directory(sub_file_path)
print(sub_path)
print("Ready to translate subtitles")
trans_path = translate_sub(sub, src_lang, tar_lang, sub_path)
return str(trans_path)
# for i in tar:
# os.system("python translation.py " + src_lang +
# " " + tar_lang + " " + sub + " " + folder)
print("-" * 30)
print("Translation successful", tar_lang)
# srt = sys.argv[1]
# src_lang_code = sys.argv[2]
# tar_lang_code = []
# # total arguments
# n = len(sys.argv)
# for i in range(3, n):
# tar_lang_code.append(sys.argv[i])
# # print(tar_lang_code)
# final = os.path.splitext(srt)[0]
# #final = final + "_overlay.mp4"
# translate_subtitle(src_lang_code, tar_lang_code, srt, final)
# save translations in appropriate folder