id_translation.transform.types#

Classes used for ID and translation transformation.

Module Attributes

Transformers

A dict {source: transformer} of initialized Transformer instances.

Classes

Transformer(*args, **kwargs)

Transformation API type.

class Transformer(*args, **kwargs)[source]#

Bases: Protocol[IdType]

Transformation API type.

Transformers are persistent entities owned by a single Translator instance. See the BitmaskTransformer for a concrete example.

try_add_missing_key(key, /, *, translations)[source]#

Attempt to create and add a translation for an unknown ID.

Callback function used by MagicDict whenever an unknown ID is requested.

Parameters:
  • key – An ID which is not present in the translations.

  • translations – A mutable mapping of translations. Typically, the MagicDict caller itself.

update_ids(ids, /)[source]#

Transform a source-to-ids mapping dict.

Called just before IDs are fetched from the source.

Note

Not called when the Translator is working offline.

Parameters:

ids – A collection of IDs from the source.

update_translations(translations, /)[source]#

Update real translations.

Called by the MagicDict during initialization.

Parameters:

translations – A dict of real translations {id: translation_string}.

Transformers#

A dict {source: transformer} of initialized Transformer instances.

alias of dict[SourceType, Transformer[IdType]]