id_translation.Translator.fetch#

Translator.fetch(translatable=None, names=None, *, ignore_names=None, override_function=None, max_fails=1.0, fmt=None, io_kwargs=None)[source]#

Fetch translations.

Calling fetch without arguments will perform a Fetcher.fetch_all() -operation, without going offline.

The returned TranslationMap may be converted to native types with TranslationMap.to_dicts().

Parameters:
  • translatable – A data structure to translate.

  • names – Explicit names to translate. Derive from translatable if None. Alternatively, you may pass a dict on the form {name_in_translatable: source_to_use}.

  • ignore_names – Names not to translate, or a predicate (NameType) -> bool.

  • override_function – A callable (name, sources, ids) -> Source | None. See Mapper.apply() for details.

  • max_fails – The maximum fraction of IDs for which translation may fail. 1=disabled.

  • fmt – A format string such as ‘{id}:{name}’ use. Default is Translator.fmt.

  • io_kwargs – Keyword arguments for the IO class (e.g. PandasIO).

Returns:

A TranslationMap.

Raises:

ConnectionStatusError – If disconnected from the fetcher, i.e. not online.

Examples

Using the returned TranslationMap class.

>>> translation_map = translator.fetch()
>>> translation_map
TranslationMap('animals': 3 IDs, 'people': 2 IDs)

Convert to finished translations.

>>> people = translation_map.to_translations()["people"]
>>> people
{1999: '1999:Sofia', 1991: '1991:Richard'}

Warning

The MagicDict class is used internally and has a few important differences from the built-in type. Please refer to the MagicDict class documentation for details.

To convert to a MagicDict to a regular dict, simply use the dict constructor:

>>> dict(people)
{1999: '1999:Sofia', 1991: '1991:Richard'}

Convert to raw translation data.

>>> translation_map.to_dicts()["people"]
{'id': [1999, 1991], 'name': ['Sofia', 'Richard']}