subaligner.translator module

class subaligner.translator.Translator(*args, **kwargs)[source]

Bases: object

Translate subtitles.

static get_iso_639_alpha_2(language_code: str) → str[source]

Find the alpha 2 language code based on an alpha 3 one.

Parameters

{string} -- An alpha 3 language code derived from ISO 639-3. (language_code) –

Returns

string – The alpha 2 language code if exists otherwise the alpha 3 one.

Raises

ValueError -- Thrown when the input language code cannot be recognised.

static normalise_pair(src_language: str, tgt_language: str) → List[str][source]

Normalise a pair of language codes.

Parameters
  • {string} -- The source language code derived from ISO 639-3. (src_language) –

  • {string} -- The target language code derived from ISO 639-3. (tgt_language) –

Returns

list – The language code pair understood by the language model.

static normalise_single(language_code: str) → str[source]

Normalise a single language code.

Parameters

{string} -- A language code derived from ISO 639-3. (language_code) –

Returns

string – The language code understood by the language model.

translate(subs: List[pysrt.SubRipItem]) → List[pysrt.SubRipItem][source]

Translate a list of subtitle cues.

Parameters

{list} -- A list of SubRipItems. (subs) –

Returns

{list} – A list of new SubRipItems holding the translation results.