def process_modules_and_forms_sheet(rows, app):
    """
    Modify the translations and media references for the modules and forms in
    the given app as per the data provided in rows.
    This does not save the changes to the database.
    :param rows:
    :param app:
    :return:  Returns a list of message tuples. The first item in each tuple is
    a function like django.contrib.messages.error, and the second is a string.
    """
    msgs = []

    for row in rows:
        identifying_text = row.get('sheet_name', '').split('_')

        if len(identifying_text) not in (1, 2):
            msgs.append((
                messages.error,
                'Invalid sheet_name "%s", skipping row.' % row.get(
                    'sheet_name', ''
                )
            ))
            continue

        module_index = int(identifying_text[0].replace("module", "")) - 1
        try:
            document = app.get_module(module_index)
        except ModuleNotFoundException:
            msgs.append((
                messages.error,
                'Invalid module in row "%s", skipping row.' % row.get(
                    'sheet_name'
                )
            ))
            continue
        if len(identifying_text) == 2:
            form_index = int(identifying_text[1].replace("form", "")) - 1
            try:
                document = document.get_form(form_index)
            except FormNotFoundException:
                msgs.append((
                    messages.error,
                    'Invalid form in row "%s", skipping row.' % row.get(
                        'sheet_name'
                    )
                ))
                continue

        for lang in app.langs:
            translation = row['default_%s' % lang]
            if translation:
                document.name[lang] = translation
            else:
                if lang in document.name:
                    del document.name[lang]

        if (has_at_least_one_translation(row, 'label_for_cases', app.langs)
                and hasattr(document, 'case_label')):
            for lang in app.langs:
                translation = row['label_for_cases_%s' % lang]
                if translation:
                    document.case_label[lang] = translation
                else:
                    if lang in document.case_label:
                        del document.case_label[lang]

        for lang in app.langs:
            document.set_icon(lang, row.get('icon_filepath_%s' % lang, ''))
            document.set_audio(lang, row.get('audio_filepath_%s' % lang, ''))

    return msgs
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/app_manager/translations.py/process_modules_and_forms_sheet/original