A php library to translate subtitle srt format with google translate.
It's recomended to install this library by Composer :
composer require hsnfirdaus/subtitle-google-translator
You can just manually download this repository as zip and extract to your project directory and include the src/SubtitleTranslator.php
file.
You can call this sdk class like this :
require __DIR__ . '/vendor/autoload.php';
$translator = new Hsnfirdaus\SubtitleTranslator($source_lang,$target_lang);
Parameter | Type | Default Value | Details |
---|---|---|---|
$source_lang |
string |
auto | The source language code (en,id,da, e.t.c) |
$target_lang |
string |
id | The target language code (en,id,da, e.t.c) |
The response of method on this class is raw srt.
Input subtitle type must be srt and output type will be srt to.
$translator = new Hsnfirdaus\SubtitleTranslator($source_lang,$target_lang);
$translated = $translator->fromRaw($raw_subtitle);
echo $translated;
Parameter | Type | Default Value | Details |
---|---|---|---|
$raw_subtitle |
string |
null | The raw text from subtitle. |
$translator = new Hsnfirdaus\SubtitleTranslator($source_lang,$target_lang);
$translated = $translator->fromFile($file_path);
echo $translated;
Parameter | Type | Default Value | Details |
---|---|---|---|
$file_path |
string |
null | The realpath of subtitle file. |