def generate_translation_output(output_map, show_files, show_lines):
    """
    Generate translation output.

    :param output_map   Output translation map (dict)
    :param show_files:  Show file names (bool)
    :param show_lines:  Show lines (bool)
    :return Translation output (str)
    """
    output = ""

    keys = output_map.keys()
    keys_len = len(keys)

    for i, k in enumerate(sorted(keys)):
        origins = output_map[k]
        if show_files:
            known_filenames = set()
            for origin in origins:
                filename, position = origin

                # Handle file repetitions
                if not show_lines and filename in known_filenames:
                    continue
                known_filenames.add(filename)

                output += "  // {0}".format(filename)
                if show_lines:
                    output += ":{0}".format(position)
                output += "\n"

        output += '  "{0}": "{{% trans "{0}" %}}"'.format(k)

        if i != keys_len - 1:
            output += ",\n"
            if show_files:
                output += "\n"

    return output