def METHOD_NAME(
    tr_doc: Document, rd: str, rp: str | None = None, ra: str | None = None
) -> tuple[Document | None, str | None]:
    """
    Find document and paragraph id from cited source Translation whose language matches
    the Translation we are currently creating.
    Note some elements of the return value may be None.
    :param rd: source document id
    :param rp: source document paragraph id
    :param ra: source document paragraph area name
    :param tr_doc: Translation that is citing the source document
    :return: the matched source Translation and paragraph id as a tuple.
    """
    matched_doc = None
    par_id = None
    source_docinfo = DocEntry.find_by_id(int(rd)) if rd else None
    if source_docinfo:
        for source_tr in source_docinfo.translations:
            # Documents might be missing a lang_id, or even a DocInfo
            if (
                source_tr.lang_id
                and tr_doc.docinfo
                and source_tr.lang_id == tr_doc.docinfo.lang_id
            ):
                matched_doc = source_tr
                # Find matching paragraph hash for translated citation par
                for p in source_tr.document:
                    if (rp and p.get_attr("rp") == rp) or (
                        ra and p.get_attr("area") == ra
                    ):
                        par_id = p.id
                        break
                break
        if not matched_doc:
            matched_doc = source_docinfo.document
            par_id = rp
    return matched_doc, par_id