class_docstr: Translates text from one language to another.
class_docstr_tok: ["Translates","text","from","one","language","to","another","."]
docstr: :param generator:
      The sequence-to-sequence generator.
  :param tokenizer:
      The text tokenizer.
  :param source_lang:
      The source language.
  :param target_lang:
      The target language.
docstr_tok: [":","param","generator",":","The","sequence-to-sequence","generator",".",":","param","tokenizer",":","The","text","tokenizer",".",":","param","source_lang",":","The","source","language",".",":","param","target_lang",":","The","target","language","."]
code: def __init__(
      self,
      generator: Seq2SeqGenerator,
      tokenizer: TextTokenizer,
      source_lang: Optional[str] = None,
      target_lang: Optional[str] = None,
  ) -> None:
      """
      :param generator:
          The sequence-to-sequence generator.
      :param tokenizer:
          The text tokenizer.
      :param source_lang:
          The source language.
      :param target_lang:
          The target language.
      """
      super().__init__(generator, tokenizer, "translation", target_lang)
  
      pad_idx = tokenizer.vocab_info.pad_idx
      if pad_idx is None:
          raise ValueError(
              "``vocab_info` of `tokenizer` must have a PAD symbol defined."
          )
  
      self.pad_idx = pad_idx
  
      device = infer_device(generator.model)
  
      self.source_text_encoder = tokenizer.create_encoder(
          task="translation",
          lang=source_lang,
          mode="source",
          device=device,
      )
  
imports: from abc import ABC
  from typing import List, Optional, Sequence, Tuple, final
  from torch import Tensor
  from fairseq2.data import StringLike
  from fairseq2.data.text import TextTokenDecoder, TextTokenEncoder, TextTokenizer
  from fairseq2.generation.generator import Seq2SeqGenerator, Seq2SeqGeneratorOutput, SequenceGenerator, SequenceGeneratorOutput
  from fairseq2.nn.padding import PaddingMask, pad_seqs
  from fairseq2.nn.utils.module import infer_device
label_desc: Use image node_id 1 to create a new TextTranslator object from inherited base classes: SequenceToTextConverterBase with example: obj = TextTranslator(generator, tokenizer, source_lang, target_lang)