All Projects → mepeichun → Subtitletranslate

mepeichun / Subtitletranslate

Licence: gpl-3.0
Translate the subtitle file into other language

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Subtitletranslate

Webfactoryicutranslationbundle
Enables ICU message formatting for translations in Symfony applications.
Stars: ✭ 27 (-40%)
Mutual labels:  translation
Python Parallel Programming Cookbook Cn
📖《Python Parallel Programming Cookbook》中文版
Stars: ✭ 978 (+2073.33%)
Mutual labels:  translation
Mkvtoolnix Batch
Windows Batch script to automate batch processing using mkvtoolnix.
Stars: ✭ 42 (-6.67%)
Mutual labels:  subtitles
Localization Helper
🎌 Laravel Localization Helper :: Easily add translation variables from Blade templates.
Stars: ✭ 31 (-31.11%)
Mutual labels:  translation
Openapi To Graphql
Translate APIs described by OpenAPI Specifications (OAS) into GraphQL
Stars: ✭ 973 (+2062.22%)
Mutual labels:  translation
Mod Translation Styleguide
Simplified Chinese Minecraft Mod translation standards and guidelines.
Stars: ✭ 37 (-17.78%)
Mutual labels:  translation
Pgstosrt
PGS to Srt converter
Stars: ✭ 21 (-53.33%)
Mutual labels:  subtitles
Bubblesub
Simple extensible ASS subtitle editor for Linux
Stars: ✭ 45 (+0%)
Mutual labels:  subtitles
Pontoon
Mozilla's Localization Platform
Stars: ✭ 976 (+2068.89%)
Mutual labels:  translation
Teachyourselfcs Cn
TeachYourselfCS 的中文翻译 | A Chinese translation of TeachYourselfCS
Stars: ✭ 11,772 (+26060%)
Mutual labels:  translation
Yomichan Import
External dictionary importer for Yomichan.
Stars: ✭ 30 (-33.33%)
Mutual labels:  translation
Parrot
Self-hosted Localization Management Platform built with Go and Angular
Stars: ✭ 967 (+2048.89%)
Mutual labels:  translation
Sockeye
Sequence-to-sequence framework with a focus on Neural Machine Translation based on Apache MXNet
Stars: ✭ 990 (+2100%)
Mutual labels:  translation
Mlkit
A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Stars: ✭ 949 (+2008.89%)
Mutual labels:  translation
Docusaurus Docs Zh cn
facebook Docusaurus 文档的中文版本 , 目标版本 1.0.5
Stars: ✭ 43 (-4.44%)
Mutual labels:  translation
Gold Miner
🥇掘金翻译计划,可能是世界最大最好的英译中技术社区,最懂读者和译者的翻译平台:
Stars: ✭ 29,872 (+66282.22%)
Mutual labels:  translation
Django Modeltranslation
Translates Django models using a registration approach.
Stars: ✭ 977 (+2071.11%)
Mutual labels:  translation
Serina
GUI for create translation files for i18next
Stars: ✭ 45 (+0%)
Mutual labels:  translation
Addic7ed Ruby
Ruby script to fetch subtitles on Addic7ed (auto-downloader)
Stars: ✭ 43 (-4.44%)
Mutual labels:  subtitles
Google Cpp Style Guide Zh Tw
Google C++ Style Guide 的繁體中文版
Stars: ✭ 41 (-8.89%)
Mutual labels:  translation

SubtitleTranslate

Translate English subtilte into other language. Only support *.srt file currently. (Please forgive me for my poor English T_T)

Prerequisite

pip install pyexecjs
pip install srt

if you are from China, please install jieba

pip install jieba

How does it work

  • parse *.srt file into subtitle by third party library srt
  • split subtitle into sentences.
  • translate sentences by Google Translate.
  • split sentences into dialogues.
  • merge original subtitle and translated subtitle

How to use

clone or download util_trans.py, util_srt.py, utils.py into your working dictionary.

from utils import translate_and_compose

input_file = "sample.en.srt"

# Translate the subtitle into Chinese, save both English and Chinese to the output srt file
# translate_and_compose(input_file, output_file, src_lang, target_lang, encoding='UTF-8', mode='split', both=True, space=False)
translate_and_compose(input_file, 'sample_en_cn_both.srt', 'en', 'zh-CN')
# translate_and_compose(input_file, 'sample_en_cn_both.srt', 'en', 'zh-CN', encoding='UTF-8-sig')


# Translate the subtitle into Chinese, save only Chinese subtitle to the output srt file
translate_and_compose(input_file, 'sample_cn_only.srt', 'en', 'zh-CN', both=False)

# Translate the subtitle into German, save both English and German to the output srt file
# In German language, each words separated by space, so space=True
translate_and_compose(input_file, 'sample_en_de_both.srt', 'en', 'de', space=True)

# Translate the subtitle into Japanese, save both English and Japanese to the output srt file
# In Japanese(Chinese, Korean), words are characters which are NOT separated by space, so space=False (default)
translate_and_compose(input_file, 'sample_en_ja_both.srt', 'en', 'ja')

More

Original subtitle:

1
00:00:00,000 --> 00:00:02,430
Coding has been
the bread and butter for
2
00:00:02,430 --> 00:00:04,290
developers since
the dawn of computing.

Translate into Chinese:

1
00:00:00,000 --> 00:00:02,430
自计算机开始以来,编码
Coding has been the bread and butter for 
2
00:00:02,430 --> 00:00:04,290
一直是开发人员的必需品。
developers since the dawn of computing. 

Translate into Japanese:

 1
00:00:00,000 --> 00:00:02,430
コーディングは、コンピューティングの夜
Coding has been the bread and butter for 
2
00:00:02,430 --> 00:00:04,290
明け以来、開発者にとって重要な要素です。
developers since the dawn of computing. 

Adavance

If you meet some problems in srt.parse()

Try another encoding method, like encoding='UTF-8-sig'

translate_and_compose(input_file, 'sample_en_cn_both.srt', 'en', 'zh-CN', encoding='UTF-8-sig')

There two tanslation modes.

If your srt file is well-splitted like:

1
00:00:00,000 --> 00:00:04,290
Coding has been the bread and butter for developers since the dawn of computing.

Well-splitted means each line in the srt file is a complete sentence. (This would perform better.)

So, you should use:

from utils import translate_and_compose

input_file = "sample.en.srt"

# Translate the subtitle into Chinese, save both English and Chinese to the output srt file
# translate_and_compose(input_file, output_file, src_lang, target_lang, encoding='UTF-8', mode='split', both=True, space=False)
translate_and_compose(input_file, 'sample_en_cn_both.srt', 'en', 'zh-CN', mode='naive')

If one sentence may be splitted into multiple lines in the srt file. Please use mode='split'. The code will first try to translate as many subtitles as possible, and then try to re-split the subtitles in target language.

About the target language

Explore more google translate supported language please visit: https://cloud.google.com/translate/docs/languages

    Afrikaans	af      Albanian	sq      Amharic	am      Arabic	ar      Armenian	hy      Azerbaijani	az
    Basque	eu          Belarusian	be      Bengali	bn      Bosnian	bs      Bulgarian	bg      Catalan	ca
    Cebuano	ceb         Chinese(Simplified)	zh-CN           Chinese (Traditional)	zh-TW
    Corsican	co      Croatian	hr      Czech	cs      Danish	da      Dutch	nl          English	en
    Esperanto	eo      Estonian	et      Finnish	fi      French	fr      Frisian	fy          Galician	gl
    Georgian	ka      German	de          Greek	el      Gujarati	gu  Haitian Creole	ht  Hausa	ha
    Hawaiian	haw     Hebrew	he          Hindi	hi      Hmong	hmn     Hungarian	hu      Icelandic	is
    Igbo	ig          Indonesian	id      Irish	ga      Italian	it      Japanese	ja      Javanese	jw
    ...
English, French, German ... are the language that split each word in a sentence by space
Chinese, Japanese are NOT the language that split each word in a sentence by space

README in Chinese

字幕翻译,目前仅支持*.srt 文件

Python第三方库

pip install pyexecjs
pip install srt

同时请安装中文分词库“结巴”

pip install jieba

工作原理

  • 利用谷歌翻译实现,使用前请安装pyexecjs库,使用pip install pyexecjs进行安装即可
  • 根据英文字幕的句号、感叹号、问号进行断句,再切割翻译得来的中文
  • 若文件太大,则将文件切割成若干部分进行翻译(谷歌翻译限制字数)

使用方法

下载 util_trans.py, util_srt.py, utils.py 到你的工作路径

from utils import translate_and_compose

input_file = "sample.en.srt"

# 把英文字幕翻译为 中英双语字幕
# translate_and_compose(input_file, output_file, src_lang, target_lang, encoding='UTF-8', mode='split', both=True, space=False)
translate_and_compose(input_file, 'sample_en_cn_both.srt', 'en', 'zh-CN')
# translate_and_compose(input_file, 'sample_en_cn_both.srt', 'en', 'zh-CN', encoding='UTF-8-sig')
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].