docs: def translate_item_ids(self, item_ids, language, is_nested=None):
          """
          Translate a list of item ids to JSON objects which reference them.
  
          Args:
              item_ids (list[int]): item ids
              language (str): language used for further filtering (some objects
                  for different languages share the same item)
              is_nested (function): mapping from item ids to booleans, where the
                  boolean value indicates whether the item is nested
  
          Returns:
              dict: item id -> JSON object
          """
          if is_nested is None:
              def is_nested_fun(x):
                  return True
          elif isinstance(is_nested, bool):
              def is_nested_fun(x):
                  return is_nested
          else:
              is_nested_fun = is_nested
          all_item_type_ids = ItemType.objects.get_all_item_type_ids()
          groupped = proso.list.group_by(item_ids, by=lambda item_id: all_item_type_ids[item_id])
          result = {}
          for item_type_id, items in groupped.items():
              with timeit('translating item type {}'.format(item_type_id)):
                  item_type = ItemType.objects.get_all_types()[item_type_id]
                  model = ItemType.objects.get_model(item_type_id)
                  kwargs = {'{}__in'.format(item_type['foreign_key']): items}
                  if 'language' in item_type:
                      kwargs[item_type['language']] = language
                  if any([not is_nested_fun(item_id) for item_id in items]) and hasattr(model.objects, 'prepare_related'):
                      objs = model.objects.prepare_related()
                  elif hasattr(model.objects, 'prepare'):
                      objs = model.objects.prepare()
                  else:
                      objs = model.objects
                  for obj in objs.filter(**kwargs):
                      item_id = getattr(obj, item_type['foreign_key'])
                      result[item_id] = obj.to_json(nested=is_nested_fun(item_id))
          return result