Beispiel #1
0
def build_ui_translation_download_file(app):

    properties = tuple(["property"] + app.langs + ["platform"])
    temp = StringIO()
    headers = (("translations", properties), )

    row_dict = {}
    for i, lang in enumerate(app.langs):
        index = i + 1
        trans_dict = app.translations.get(lang, {})
        for prop, trans in six.iteritems(trans_dict):
            if prop not in row_dict:
                row_dict[prop] = [prop]
            num_to_fill = index - len(row_dict[prop])
            row_dict[prop].extend(
                ["" for i in range(num_to_fill)] if num_to_fill > 0 else [])
            row_dict[prop].append(trans)

    rows = list(row_dict.values())
    try:
        commcare_version = str(StrictVersion(app.build_version.vstring))
    except ValueError:
        commcare_version = None

    all_prop_trans = get_default_translations_for_download(
        app, commcare_version)
    rows.extend([[t] for t in sorted(all_prop_trans.keys())
                 if t not in row_dict])

    def fillrow(row):
        num_to_fill = len(properties) - len(row)
        row.extend(["" for i in range(num_to_fill)] if num_to_fill > 0 else [])
        return row

    def add_default(row):
        row_index = get_index_for_defaults(app.langs) + 1
        if not row[row_index]:
            # If no custom translation exists, replace it.
            row[row_index] = all_prop_trans.get(row[0], "")
        return row

    def add_sources(row):
        platform_map = {
            "CommCareAndroid": "Android",
            "CommCareJava": "Java",
            "ODK": "Android",
            "JavaRosa": "Java",
        }
        source = system_text_sources.SOURCES.get(row[0], "")
        row[-1] = platform_map.get(source, "")
        return row

    rows = [add_sources(add_default(fillrow(row))) for row in rows]

    data = (("translations", tuple(rows)), )
    with export_raw_to_writer(headers, data, temp) as writer:
        set_commcare_version_in_workbook(writer.book, commcare_version)
    return temp
Beispiel #2
0
def build_ui_translation_download_file(app):
    blacklist = _get_ui_blacklist(app)
    properties = tuple(["property"] + app.langs)
    temp = io.BytesIO()
    headers = (("translations", properties), )

    row_dict = {}
    for i, lang in enumerate(app.langs):
        index = i + 1
        trans_dict = app.translations.get(lang, {})
        for prop, trans in trans_dict.items():
            if prop in blacklist:
                continue
            if prop not in row_dict:
                row_dict[prop] = [prop]
            num_to_fill = index - len(row_dict[prop])
            row_dict[prop].extend(
                ["" for i in range(num_to_fill)] if num_to_fill > 0 else [])
            row_dict[prop].append(trans)

    rows = list(row_dict.values())
    try:
        commcare_version = str(StrictVersion(app.build_version.vstring))
    except ValueError:
        commcare_version = None

    all_prop_trans = get_default_translations_for_download(
        app, commcare_version)
    rows.extend([[t] for t in sorted(all_prop_trans.keys())
                 if t not in row_dict and t not in blacklist])

    def fillrow(row):
        num_to_fill = len(properties) - len(row)
        row.extend(["" for i in range(num_to_fill)] if num_to_fill > 0 else [])
        return row

    def add_default(row):
        row_index = get_index_for_defaults(app.langs) + 1
        if not row[row_index]:
            # If no custom translation exists, replace it.
            row[row_index] = all_prop_trans.get(row[0], "")
        return row

    rows = [add_default(fillrow(row)) for row in rows]

    data = (("translations", tuple(rows)), )
    with export_raw_to_writer(headers, data, temp) as writer:
        set_commcare_version_in_workbook(writer.book, commcare_version)
    return temp
Beispiel #3
0
def build_ui_translation_download_file(app):

    properties = tuple(["property"] + app.langs)
    temp = io.BytesIO()
    headers = (("translations", properties),)

    row_dict = {}
    for i, lang in enumerate(app.langs):
        index = i + 1
        trans_dict = app.translations.get(lang, {})
        for prop, trans in six.iteritems(trans_dict):
            if prop not in row_dict:
                row_dict[prop] = [prop]
            num_to_fill = index - len(row_dict[prop])
            row_dict[prop].extend(["" for i in range(num_to_fill)] if num_to_fill > 0 else [])
            row_dict[prop].append(trans)

    rows = list(row_dict.values())
    try:
        commcare_version = str(StrictVersion(app.build_version.vstring))
    except ValueError:
        commcare_version = None

    all_prop_trans = get_default_translations_for_download(app, commcare_version)
    rows.extend([[t] for t in sorted(all_prop_trans.keys()) if t not in row_dict])

    def fillrow(row):
        num_to_fill = len(properties) - len(row)
        row.extend(["" for i in range(num_to_fill)] if num_to_fill > 0 else [])
        return row

    def add_default(row):
        row_index = get_index_for_defaults(app.langs) + 1
        if not row[row_index]:
            # If no custom translation exists, replace it.
            row[row_index] = all_prop_trans.get(row[0], "")
        return row

    rows = [add_default(fillrow(row)) for row in rows]

    data = (("translations", tuple(rows)),)
    with export_raw_to_writer(headers, data, temp) as writer:
        set_commcare_version_in_workbook(writer.book, commcare_version)
    return temp