Esempio n. 1
0
def _create_custom_app_strings(app, lang):

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version >= '2.8':
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    # include language code names
    for lc in app.langs:
        name = langcodes.get_name(lc) or lc
        if name:
            yield lc, name

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            else:
                label = trans(module.referral_label)
            yield id_strings.detail_title_locale(module, detail_type), label

            for column in detail.get_columns():
                if not is_sort_only_column(column):
                    yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(module, detail_type, column, item.key), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(module, detail_type, column, index), trans(item.values)
                    for property, values in column.graph_configuration.locale_specific_config.iteritems():
                        yield id_strings.graph_configuration(module, detail_type, column, property), trans(values)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(module, detail_type, tab), trans(tab.header)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))
        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)
Esempio n. 2
0
def _create_custom_app_strings(app, lang, for_default=False):
    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version and app.build_version >= LooseVersion('2.8'):
            numeric_nav_on = app.profile.get(
                'properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features',
                               {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text, ) if not (
                    text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    for id, value in id_strings.REGEX_DEFAULT_VALUES.items():
        yield id, value

    if for_default:
        # include language code names and current language
        for lc in app.langs:
            name = langcodes.get_name(lc) or lc
            if not name:
                continue
            with localize(convert_to_two_letter_code(lc)):
                name = ugettext(name)
            yield lc, name

    yield id_strings.current_language(), lang

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            for column in detail.get_columns():
                yield id_strings.detail_column_header_locale(
                    module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image', 'conditional-enum'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(
                            module, detail_type, column,
                            item.key_as_variable), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(
                            column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(
                            module, detail_type, column,
                            index), trans(item.values)
                    for property, values in six.iteritems(
                            column.graph_configuration.locale_specific_config):
                        yield id_strings.graph_configuration(
                            module, detail_type, column,
                            property), trans(values)
                    for index, item in enumerate(
                            column.graph_configuration.series):
                        for property, values in six.iteritems(
                                item.locale_specific_config):
                            yield id_strings.graph_series_configuration(
                                module, detail_type, column, index,
                                property), trans(values)

            # To list app strings for properties used as sorting properties only
            if detail.sort_elements:
                sort_only, sort_columns = get_sort_and_sort_only_columns(
                    detail, detail.sort_elements)
                for field, sort_element, order in sort_only:
                    if sort_element.has_display_values():
                        column = create_temp_sort_column(sort_element, order)
                        yield id_strings.detail_column_header_locale(module, detail_type, column), \
                            trans(column.header)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(
                    module, detail_type, tab), trans(tab.header)

            if getattr(detail, 'lookup_display_results'):
                yield id_strings.callout_header_locale(module), trans(
                    detail.lookup_field_header)

        yield id_strings.module_locale(module), maybe_add_index(
            trans(module.name))

        icon = module.icon_app_string(lang, for_default=for_default)
        audio = module.audio_app_string(lang, for_default=for_default)
        custom_icon_form, custom_icon_text = module.custom_icon_form_and_text_by_language(
            lang)
        if icon:
            yield id_strings.module_icon_locale(module), icon
        if audio:
            yield id_strings.module_audio_locale(module), audio
        if custom_icon_form and custom_icon_text:
            yield _get_custom_icon_app_locale_and_value(custom_icon_form,
                                                        custom_icon_text,
                                                        module=module)

        if hasattr(module, 'report_configs'):
            for config in module.report_configs:
                yield id_strings.report_command(config.uuid), trans(
                    config.header)
                yield id_strings.report_name(config.uuid), trans(config.header)
                yield id_strings.report_description(config.uuid), trans(
                    config.localized_description)
                for column in config.report(app.domain).report_columns:
                    yield (id_strings.report_column_header(
                        config.uuid,
                        column.column_id), column.get_header(lang))
                for chart_id, graph_config in six.iteritems(
                        config.complete_graph_configs):
                    for index, item in enumerate(graph_config.annotations):
                        yield id_strings.mobile_ucr_annotation(
                            module, config.uuid, index), trans(item.values)
                    for property, values in six.iteritems(
                            graph_config.locale_specific_config):
                        yield id_strings.mobile_ucr_configuration(
                            module, config.uuid, property), trans(values)
                    for index, item in enumerate(graph_config.series):
                        for property, values in six.iteritems(
                                item.locale_specific_config):
                            yield id_strings.mobile_ucr_series_configuration(
                                module, config.uuid, index,
                                property), trans(values)

        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(
                    module.case_list.label) or "Case List"
                icon = module.case_list.icon_app_string(
                    lang, for_default=for_default)
                audio = module.case_list.audio_app_string(
                    lang, for_default=for_default)
                if icon:
                    yield id_strings.case_list_icon_locale(module), icon
                if audio:
                    yield id_strings.case_list_audio_locale(module), audio

        if module_offers_search(module):
            yield id_strings.case_search_locale(module), trans(
                module.search_config.command_label)
            # icon and audio not yet available
            for prop in module.search_config.properties:
                yield id_strings.search_property_locale(
                    module, prop.name), trans(prop.label)

        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(
                    module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)

            icon = form.icon_app_string(lang, for_default=for_default)
            audio = form.audio_app_string(lang, for_default=for_default)
            custom_icon_form, custom_icon_text = form.custom_icon_form_and_text_by_language(
                lang)
            if icon:
                yield id_strings.form_icon_locale(form), icon
            if audio:
                yield id_strings.form_audio_locale(form), audio
            if custom_icon_form and custom_icon_text:
                yield _get_custom_icon_app_locale_and_value(custom_icon_form,
                                                            custom_icon_text,
                                                            form=form)

        if hasattr(module, 'case_list_form') and module.case_list_form.form_id:
            yield (id_strings.case_list_form_locale(module),
                   trans(module.case_list_form.label) or "Create a new Case")
            icon = module.case_list_form.icon_app_string(
                lang, for_default=for_default)
            audio = module.case_list_form.audio_app_string(
                lang, for_default=for_default)
            if icon:
                yield id_strings.case_list_form_icon_locale(module), icon
            if audio:
                yield id_strings.case_list_form_audio_locale(module), audio
Esempio n. 3
0
def _create_custom_app_strings(app, lang, for_default=False):

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version and app.build_version >= LooseVersion('2.8'):
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    for id, value in id_strings.REGEX_DEFAULT_VALUES.items():
        yield id, value

    if for_default:
        # include language code names and current language
        for lc in app.langs:
            name = langcodes.get_name(lc) or lc
            if not name:
                continue
            with localize(convert_to_two_letter_code(lc)):
                name = ugettext(name)
            yield lc, name

    yield id_strings.current_language(), lang

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            for column in detail.get_columns():
                yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image', 'conditional-enum'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(
                            module, detail_type, column, item.key_as_variable
                        ), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(module, detail_type, column, index), trans(item.values)
                    for property, values in six.iteritems(column.graph_configuration.locale_specific_config):
                        yield id_strings.graph_configuration(module, detail_type, column, property), trans(values)
                    for index, item in enumerate(column.graph_configuration.series):
                        for property, values in six.iteritems(item.locale_specific_config):
                            yield id_strings.graph_series_configuration(
                                module, detail_type, column, index, property
                            ), trans(values)

            # To list app strings for properties used as sorting properties only
            if detail.sort_elements:
                sort_only, sort_columns = get_sort_and_sort_only_columns(detail, detail.sort_elements)
                for field, sort_element, order in sort_only:
                    if sort_element.has_display_values():
                        column = create_temp_sort_column(sort_element, order)
                        yield id_strings.detail_column_header_locale(module, detail_type, column), \
                            trans(column.header)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(module, detail_type, tab), trans(tab.header)

            if getattr(detail, 'lookup_display_results'):
                yield id_strings.callout_header_locale(module), trans(detail.lookup_field_header)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))

        icon = module.icon_app_string(lang, for_default=for_default)
        audio = module.audio_app_string(lang, for_default=for_default)
        custom_icon_form, custom_icon_text = module.custom_icon_form_and_text_by_language(lang)
        if icon:
            yield id_strings.module_icon_locale(module), icon
        if audio:
            yield id_strings.module_audio_locale(module), audio
        if custom_icon_form and custom_icon_text:
            yield _get_custom_icon_app_locale_and_value(custom_icon_form, custom_icon_text, module=module)

        if hasattr(module, 'report_configs'):
            for config in module.report_configs:
                yield id_strings.report_command(config.uuid), trans(config.header)
                yield id_strings.report_name(config.uuid), trans(config.header)
                yield id_strings.report_description(config.uuid), trans(config.localized_description)
                for column in config.report(app.domain).report_columns:
                    yield (
                        id_strings.report_column_header(config.uuid, column.column_id),
                        column.get_header(lang)
                    )
                for chart_id, graph_config in six.iteritems(config.complete_graph_configs):
                    for index, item in enumerate(graph_config.annotations):
                        yield id_strings.mobile_ucr_annotation(module, config.uuid, index), trans(item.values)
                    for property, values in six.iteritems(graph_config.locale_specific_config):
                        yield id_strings.mobile_ucr_configuration(module, config.uuid, property), trans(values)
                    for index, item in enumerate(graph_config.series):
                        for property, values in six.iteritems(item.locale_specific_config):
                            yield id_strings.mobile_ucr_series_configuration(
                                module, config.uuid, index, property
                            ), trans(values)

        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
                icon = module.case_list.icon_app_string(lang, for_default=for_default)
                audio = module.case_list.audio_app_string(lang, for_default=for_default)
                if icon:
                    yield id_strings.case_list_icon_locale(module), icon
                if audio:
                    yield id_strings.case_list_audio_locale(module), audio

        if module_offers_search(module):
            yield id_strings.case_search_locale(module), trans(module.search_config.command_label)
            # icon and audio not yet available
            for prop in module.search_config.properties:
                yield id_strings.search_property_locale(module, prop.name), trans(prop.label)

        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)

            icon = form.icon_app_string(lang, for_default=for_default)
            audio = form.audio_app_string(lang, for_default=for_default)
            custom_icon_form, custom_icon_text = form.custom_icon_form_and_text_by_language(lang)
            if icon:
                yield id_strings.form_icon_locale(form), icon
            if audio:
                yield id_strings.form_audio_locale(form), audio
            if custom_icon_form and custom_icon_text:
                yield _get_custom_icon_app_locale_and_value(custom_icon_form, custom_icon_text, form=form)

            for id, custom_assertion in enumerate(form.custom_assertions):
                yield id_strings.custom_assertion_locale(module, form, id), trans(custom_assertion.text)

        if hasattr(module, 'case_list_form') and module.case_list_form.form_id:
            yield (
                id_strings.case_list_form_locale(module),
                trans(module.case_list_form.label) or "Create a new Case"
            )
            icon = module.case_list_form.icon_app_string(lang, for_default=for_default)
            audio = module.case_list_form.audio_app_string(lang, for_default=for_default)
            if icon:
                yield id_strings.case_list_form_icon_locale(module), icon
            if audio:
                yield id_strings.case_list_form_audio_locale(module), audio
Esempio n. 4
0
def _create_custom_app_strings(app, lang, for_default=False):

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version >= '2.8':
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    # include language code names and current language
    for lc in app.langs:
        name = langcodes.get_name(lc) or lc
        if name:
            yield lc, name
    yield id_strings.current_language(), lang

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            elif detail_type.startswith('referral'):
                label = trans(module.referral_label)
            elif detail_type in ('product_short', 'product_long'):
                label = ''
            else:
                label = None
            if label is not None:
                yield id_strings.detail_title_locale(module, detail_type), label

            for column in detail.get_columns():
                if not is_sort_only_column(column):
                    yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(
                            module, detail_type, column, item.key_as_variable
                        ), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(module, detail_type, column, index), trans(item.values)
                    for property, values in column.graph_configuration.locale_specific_config.iteritems():
                        yield id_strings.graph_configuration(module, detail_type, column, property), trans(values)
                    for index, item in enumerate(column.graph_configuration.series):
                        for property, values in item.locale_specific_config.iteritems():
                            yield id_strings.graph_series_configuration(
                                module, detail_type, column, index, property
                            ), trans(values)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(module, detail_type, tab), trans(tab.header)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))

        icon = module.icon_app_string(lang, for_default=for_default)
        audio = module.audio_app_string(lang, for_default=for_default)
        if icon:
            yield id_strings.module_icon_locale(module), icon
        if audio:
            yield id_strings.module_audio_locale(module), audio

        if hasattr(module, 'report_configs'):
            yield id_strings.report_menu(), 'Reports'
            yield id_strings.report_name_header(), 'Report Name'
            yield id_strings.report_description_header(), 'Report Description'
            yield id_strings.report_last_sync(), 'Last Sync'
            yield id_strings.report_data_table(), 'Data Table'
            for config in module.report_configs:
                yield id_strings.report_command(config.uuid), trans(config.header)
                yield id_strings.report_name(config.uuid), trans(config.header)
                yield id_strings.report_description(config.uuid), trans(config.localized_description)
                for column in config.report.report_columns:
                    yield (
                        id_strings.report_column_header(config.uuid, column.column_id),
                        column.get_header(lang)
                    )

        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
                icon = module.case_list.icon_app_string(lang, for_default=for_default)
                audio = module.case_list.audio_app_string(lang, for_default=for_default)
                if icon:
                    yield id_strings.case_list_icon_locale(module), icon
                if audio:
                    yield id_strings.case_list_audio_locale(module), audio

        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)

            icon = form.icon_app_string(lang, for_default=for_default)
            audio = form.audio_app_string(lang, for_default=for_default)
            if icon:
                yield id_strings.form_icon_locale(form), icon
            if audio:
                yield id_strings.form_audio_locale(form), audio

        if hasattr(module, 'case_list_form') and module.case_list_form.form_id:
            yield (
                id_strings.case_list_form_locale(module),
                trans(module.case_list_form.label) or "Create a new Case"
            )
            icon = module.case_list_form.icon_app_string(lang, for_default=for_default)
            audio = module.case_list_form.audio_app_string(lang, for_default=for_default)
            if icon:
                yield id_strings.case_list_form_icon_locale(module), icon
            if audio:
                yield id_strings.case_list_form_audio_locale(module), audio
Esempio n. 5
0
def _create_custom_app_strings(app, lang):

    def trans(d):
        return clean_trans(d, langs)

    def maybe_add_index(text):
        if app.build_version >= '2.8':
            numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    # include language code names
    for lc in app.langs:
        name = langcodes.get_name(lc) or lc
        if name:
            yield lc, name

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            if detail_type.startswith('case'):
                label = trans(module.case_label)
            elif detail_type.startswith('referral'):
                label = trans(module.referral_label)
            elif detail_type in ('product_short', 'product_long'):
                label = ''
            else:
                label = None
            if label is not None:
                yield id_strings.detail_title_locale(module, detail_type), label

            for column in detail.get_columns():
                if not is_sort_only_column(column):
                    yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(module, detail_type, column, item.key_as_variable), trans(item.value)
                elif column.format == "graph":
                    for index, item in enumerate(column.graph_configuration.annotations):
                        yield id_strings.graph_annotation(module, detail_type, column, index), trans(item.values)
                    for property, values in column.graph_configuration.locale_specific_config.iteritems():
                        yield id_strings.graph_configuration(module, detail_type, column, property), trans(values)

            for tab in detail.get_tabs():
                yield id_strings.detail_tab_title_locale(module, detail_type, tab), trans(tab.header)

        yield id_strings.module_locale(module), maybe_add_index(trans(module.name))
        if hasattr(module, 'report_configs'):
            for config in module.report_configs:
                yield id_strings.report_command(config.report_id), trans(config.header)
                yield id_strings.report_name(config.report_id), config.report.title
                yield id_strings.report_menu(), 'Reports'
                yield id_strings.report_name_header(), 'Report Name'
                yield id_strings.report_description_header(), 'Report Description'
                for column in config.report.report_columns:
                    yield (
                        id_strings.report_column_header(config.report_id, column.column_id),
                        column.get_header(lang)
                    )

        if hasattr(module, 'case_list'):
            if module.case_list.show:
                yield id_strings.case_list_locale(module), trans(module.case_list.label) or "Case List"
        if hasattr(module, 'referral_list'):
            if module.referral_list.show:
                yield id_strings.referral_list_locale(module), trans(module.referral_list.label)
        for form in module.get_forms():
            form_name = trans(form.name) + ('${0}' if form.show_count else '')
            yield id_strings.form_locale(form), maybe_add_index(form_name)

        if hasattr(module, 'case_list_form') and module.case_list_form.form_id:
            yield (
                id_strings.case_list_form_locale(module),
                trans(module.case_list_form.label) or "Create a new Case"
            )