Beispiel #1
0
def get_bulk_app_single_sheet_by_name(app,
                                      lang,
                                      eligible_for_transifex_only=False):
    checker = EligibleForTransifexChecker(app)

    rows = []
    for module in app.get_modules():
        if eligible_for_transifex_only and checker.exclude_module(module):
            continue
        sheet_name = get_module_sheet_name(module)
        rows.append(get_name_menu_media_row(module, sheet_name, lang))
        for module_row in get_module_rows([lang], module):
            if eligible_for_transifex_only:
                field_name, field_type, translation = module_row
                if checker.is_blacklisted(module.unique_id, field_type,
                                          field_name, [translation]):
                    continue
            rows.append(
                get_list_detail_case_property_row(module_row, sheet_name))

        for form in module.get_forms():
            if eligible_for_transifex_only and checker.exclude_form(form):
                continue
            sheet_name = get_form_sheet_name(form)
            rows.append(get_name_menu_media_row(form, sheet_name, lang))
            for label_name_media in get_form_question_label_name_media([lang],
                                                                       form):
                if (eligible_for_transifex_only and checker.is_label_to_skip(
                        form.unique_id, label_name_media[0])):
                    continue
                rows.append(get_question_row(label_name_media, sheet_name))

    return OrderedDict({SINGLE_SHEET_NAME: rows})
Beispiel #2
0
def get_bulk_app_sheets_by_name(app, lang=None, eligible_for_transifex_only=False):
    """
    Data rows for bulk app translation download

    If `eligible_for_transifex_only` is True, sheets will omit
    translations that would not be sent to Transifex.
    """
    checker = EligibleForTransifexChecker(app)

    # keys are the names of sheets, values are lists of tuples representing rows
    rows = OrderedDict({MODULES_AND_FORMS_SHEET_NAME: []})

    for module in app.get_modules():
        if eligible_for_transifex_only and checker.exclude_module(module):
            continue

        langs = [lang] if lang else app.langs

        module_sheet_name = get_module_sheet_name(module)
        rows[MODULES_AND_FORMS_SHEET_NAME].append(get_modules_and_forms_row(
            row_type="Menu",
            sheet_name=module_sheet_name,
            languages=[module.name.get(lang) for lang in langs],
            media_image=[module.icon_by_language(lang) for lang in langs],
            media_audio=[module.audio_by_language(lang) for lang in langs],
            unique_id=module.unique_id,
        ))

        rows[module_sheet_name] = []
        for module_row in get_module_rows(langs, module):
            if eligible_for_transifex_only:
                field_name, field_type, *translations = module_row
                if checker.is_blacklisted(module.unique_id, field_type, field_name, translations):
                    continue
            rows[module_sheet_name].append(module_row)

        for form in module.get_forms():
            if eligible_for_transifex_only and checker.exclude_form(form):
                continue

            form_sheet_name = get_form_sheet_name(form)
            rows[MODULES_AND_FORMS_SHEET_NAME].append(get_modules_and_forms_row(
                row_type="Form",
                sheet_name=form_sheet_name,
                languages=[form.name.get(lang) for lang in langs],
                media_image=[form.icon_by_language(lang) for lang in langs],
                media_audio=[form.audio_by_language(lang) for lang in langs],
                unique_id=form.unique_id
            ))

            rows[form_sheet_name] = []
            for label_name_media in get_form_question_label_name_media(langs, form):
                if (
                    eligible_for_transifex_only and
                    checker.is_label_to_skip(form.unique_id, label_name_media[0])
                ):
                    continue
                rows[form_sheet_name].append(label_name_media)

    return rows
Beispiel #3
0
def get_bulk_app_sheet_headers(app,
                               single_sheet=False,
                               lang=None,
                               eligible_for_transifex_only=False,
                               by_id=False):
    '''
    Returns lists representing the expected structure of bulk app translation
    Excel file uploads and downloads.

    The list will be in the form:
    [
        ["sheetname", ["column name1", "column name 2"]],
        ["sheet2 name", [...]],
        ...
    ]

    `eligible_for_transifex_only` will skip modules and forms that have "SKIP
    TRANSIFEX" in their comment.
    '''
    langs = [lang] if lang else app.langs

    default_lang_list = ['default_' + l for l in langs]
    audio_lang_list = ['audio_' + l for l in langs]
    image_lang_list = ['image_' + l for l in langs]
    video_lang_list = ['video_' + l for l in langs]
    lang_list = default_lang_list + image_lang_list + audio_lang_list + video_lang_list

    if single_sheet:
        return ((SINGLE_SHEET_NAME, tuple(SINGLE_SHEET_STATIC_HEADERS) +
                 tuple(lang_list) + ('unique_id', )), )

    headers = []

    # Add headers for the first sheet
    headers.append([
        MODULES_AND_FORMS_SHEET_NAME,
        get_modules_and_forms_row(
            row_type='Type',
            sheet_name='menu_or_form',
            languages=default_lang_list,
            media_image=['image_%s' % l for l in langs],
            media_audio=['audio_%s' % l for l in langs],
            unique_id='unique_id',
        )
    ])

    for module in app.get_modules():
        if eligible_for_transifex_only and EligibleForTransifexChecker.exclude_module(
                module):
            continue

        sheet_name = module.unique_id if by_id else get_module_sheet_name(
            module)
        headers.append([
            sheet_name, ['case_property', 'list_or_detail'] + default_lang_list
        ])

        for form in module.get_forms():
            if form.form_type == 'shadow_form':
                continue
            if eligible_for_transifex_only and EligibleForTransifexChecker.exclude_form(
                    form):
                continue

            sheet_name = form.unique_id if by_id else get_form_sheet_name(form)
            headers.append([sheet_name, ["label"] + lang_list])
    return headers