class_docstr: `FeatureConnector` for translations with variable languages per example.
  Here for compatiblity with tfds.
  
  Args:
      languages (`dict`):
          A dictionary for each example mapping string language codes to one or more string translations.
          The languages present may vary from example to example.
  
  Returns:
      - `language` or `translation` (variable-length 1D `tf.Tensor` of `tf.string`):
          Language codes sorted in ascending order or plain text translations, sorted to align with language codes.
  
  Example:
  
  ```python
  >>> # At construction time:
  >>> datasets.features.TranslationVariableLanguages(languages=['en', 'fr', 'de'])
  >>> # During data generation:
  >>> yield {
  ...         'en': 'the cat',
  ...         'fr': ['le chat', 'la chatte,']
  ...         'de': 'die katze'
  ... }
  >>> # Tensor returned :
  >>> {
  ...         'language': ['en', 'de', 'fr', 'fr'],
  ...         'translation': ['the cat', 'die katze', 'la chatte', 'le chat'],
  ... }
  ```
class_docstr_tok: ["`","FeatureConnector","`","for","translations","with","variable","languages","per","example",".","Here","for","compatiblity","with","tfds",".","Args",":","languages","(","`","dict","`",")",":","A","dictionary","for","each","example","mapping","string","language","codes","to","one","or","more","string","translations",".","The","languages","present","may","vary","from","example","to","example",".","Returns",":","-","`","language","`","or","`","translation","`","(","variable-length","1D","`","tf.Tensor","`","of","`","tf.string","`",")",":","Language","codes","sorted","in","ascending","order","or","plain","text","translations",",","sorted","to","align","with","language","codes",".","Example",":","``","`","python",">",">",">","#","At","construction","time",":",">",">",">","datasets.features.TranslationVariableLanguages","(","languages=","[","'en","'",",","'fr","'",",","'de","'","]",")",">",">",">","#","During","data","generation",":",">",">",">","yield","{","...","'en","'",":","'the","cat","'",",","...","'fr","'",":","[","'le","chat","'",",","'la","chatte",",","'","]","...","'de","'",":","'die","katze'","...","}",">",">",">","#","Tensor","returned",":",">",">",">","{","...","'language","'",":","[","'en","'",",","'de","'",",","'fr","'",",","'fr","'","]",",","...","'translation","'",":","[","'the","cat","'",",","'die","katze","'",",","'la","chatte","'",",","'le","chat","'","]",",","...","}","``","`"]
code: def encode_example(self, translation_dict):
      lang_set = set(self.languages)
      if set(translation_dict) == {"language", "translation"}:
          return translation_dict
      elif self.languages and set(translation_dict) - lang_set:
          raise ValueError(
              f'Some languages in example ({", ".join(sorted(set(translation_dict) - lang_set))}) are not in valid set ({", ".join(lang_set)}).'
          )
  
      # Convert dictionary into tuples, splitting out cases where there are
      # multiple translations for a single language.
      translation_tuples = []
      for lang, text in translation_dict.items():
          if isinstance(text, str):
              translation_tuples.append((lang, text))
          else:
              translation_tuples.extend([(lang, el) for el in text])
  
      # Ensure translations are in ascending order by language code.
      languages, translations = zip(*sorted(translation_tuples))
  
      return {"language": languages, "translation": translations}
  
file_path: datasets/src/datasets/features/translation.py
imports: from dataclasses import dataclass, field
  from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union
  import pyarrow
label_desc: Use image node_id 3 for calling the TranslationVariableLanguages obj's underlying member method code with example usage: obj.encode_example(translation_dict) and returns: dict, translation_dict