Ejemplo n.º 1
0
def make_language_pack(lang, version, sublangargs, filename, ka_domain, no_assessment_items, no_subtitles, no_assessment_resources, no_dubbed_videos):
    node_data, subtitle_data, interface_catalog, content_catalog = retrieve_language_resources(version, sublangargs, ka_domain, no_subtitles, no_dubbed_videos)

    subtitles, subtitle_paths = subtitle_data.keys(), subtitle_data.values()

    node_data = translate_nodes(node_data, content_catalog)
    node_data = list(node_data)
    node_data, dubbed_video_count = apply_dubbed_video_map(node_data, subtitles, sublangargs["video_lang"])

    html_exercise_ids, assessment_exercise_ids, node_data = separate_exercise_types(node_data)
    html_exercise_path, translated_html_exercise_ids = retrieve_html_exercises(html_exercise_ids, lang)

    # now include only the assessment item resources that we need
    all_assessment_data, all_assessment_files = retrieve_all_assessment_item_data(
        no_item_data=no_assessment_items,
        no_item_resources=no_assessment_resources,
        node_data=node_data,
        lang=lang,
        content_catalog=content_catalog,
    )
    all_assessment_data = list(remove_assessment_data_with_empty_widgets(all_assessment_data))
    node_data = remove_nonexistent_assessment_items_from_exercises(node_data, all_assessment_data)

    node_data = clean_node_data_items(node_data)
    assessment_data = list(all_assessment_data)

    node_data = remove_untranslated_exercises(node_data, translated_html_exercise_ids, assessment_data) if lang != "en" else node_data

    pack_metadata = generate_kalite_language_pack_metadata(lang, version, sublangargs, interface_catalog, content_catalog, subtitles,
                                                           dubbed_video_count)

    bundle_language_pack(str(filename), node_data, interface_catalog, interface_catalog,
                         pack_metadata, assessment_data, all_assessment_files, subtitle_paths, html_exercise_path)
def make_language_pack(lang, version, sublangargs, filename, ka_domain,
                       no_assessment_items, no_subtitles,
                       no_assessment_resources, no_dubbed_videos):
    node_data, subtitle_data, content_catalog = retrieve_language_resources(
        version, sublangargs, ka_domain, no_subtitles, no_dubbed_videos)

    node_data = translate_nodes(node_data, content_catalog)
    node_data = list(node_data)
    node_data, dubbed_video_count = apply_dubbed_video_map(
        node_data, subtitle_data, sublangargs["video_lang"])

    # now include only the assessment item resources that we need
    all_assessment_data, all_assessment_files = retrieve_all_assessment_item_data(
        no_item_data=no_assessment_items,
        no_item_resources=no_assessment_resources,
        node_data=node_data,
        lang=lang,
        content_catalog=content_catalog,
    )
    all_assessment_data = list(
        remove_assessment_data_with_empty_widgets(all_assessment_data))
    node_data = remove_nonexistent_assessment_items_from_exercises(
        node_data, all_assessment_data)

    node_data = clean_node_data_items(node_data)
    node_data = remove_untranslated_exercises(
        node_data, all_assessment_data) if lang != "en" else node_data
    node_data = list(node_data)
    node_data = sorted(node_data, key=lambda x: x.get('sort_order'))

    with open('node_data_{0}.pickle'.format(lang), 'wb') as handle:
        pickle.dump(node_data, handle)

    with open('assessment_data_{0}.pickle'.format(lang), 'wb') as handle:
        pickle.dump(all_assessment_data, handle)
def make_language_pack(lang, version, sublangargs, filename, no_assessment_items, no_subtitles, no_assessment_resources):
    node_data, subtitle_data, interface_catalog, content_catalog = retrieve_language_resources(version, sublangargs, no_subtitles)

    subtitles, subtitle_paths = subtitle_data.keys(), subtitle_data.values()

    node_data = translate_nodes(node_data, content_catalog)
    node_data = list(node_data)
    node_data, dubbed_video_count = apply_dubbed_video_map(node_data, subtitles, sublangargs["video_lang"])

    html_exercise_ids, assessment_exercise_ids, node_data = separate_exercise_types(node_data)
    html_exercise_path, translated_html_exercise_ids = retrieve_html_exercises(html_exercise_ids, lang)

    # now include only the assessment item resources that we need
    all_assessment_data, all_assessment_files = retrieve_all_assessment_item_data(
        no_item_data=no_assessment_items,
        no_item_resources=no_assessment_resources
    )

    assessment_data = list(translate_assessment_item_text(all_assessment_data, content_catalog)) if lang != "en" else all_assessment_data

    node_data = remove_untranslated_exercises(node_data, translated_html_exercise_ids, assessment_data) if lang != "en" else node_data

    pack_metadata = generate_kalite_language_pack_metadata(lang, version, interface_catalog, content_catalog, subtitles,
                                                           dubbed_video_count)

    bundle_language_pack(str(filename), node_data, interface_catalog, interface_catalog,
                         pack_metadata, assessment_data, all_assessment_files, subtitle_paths, html_exercise_path)
Ejemplo n.º 4
0
    def test_always_returns_videos_and_topics(self):
        self.nodes = [
            {
                "kind": NodeType.exercise,
                "id": "no-html",
                "uses_assessment_items": False
            },
            {
                "kind": NodeType.exercise,
                "id": "no-assessment",
                "uses_assessment_items": True,
                "all_assessment_items": []
            },
            {
                "kind": NodeType.video,
                "id": "video"
            },
            {
                "id": "topic",
                "kind": NodeType.topic
            },
        ]
        # these don't matter, and can thus be empty
        item_data = {}
        html_ids = set()

        result = set(
            s.get("id") for s in remove_untranslated_exercises(
                self.nodes, html_ids, item_data))

        assert "video" in result
        assert "topic" in result
Ejemplo n.º 5
0
    def test_returns_exercise_with_html(self):
        nodes = [{"kind": NodeType.exercise, "id": "has-html", "uses_assessment_items": False}]
        html_ids = ["has-html"]

        exercises = set(k.get("id") for k in remove_untranslated_exercises(nodes, html_ids, {}))

        assert "has-html" in exercises
Ejemplo n.º 6
0
    def test_returns_exercise_with_html(self):
        nodes = [{
            "kind": NodeType.exercise,
            "id": "has-html",
            "uses_assessment_items": False
        }]
        html_ids = ["has-html"]

        exercises = set(
            k.get("id")
            for k in remove_untranslated_exercises(nodes, html_ids, {}))

        assert "has-html" in exercises
Ejemplo n.º 7
0
    def test_returns_exercise_with_assessment_items(self):
        nodes = [
            {"kind": NodeType.exercise,
                            "id": "translated",
                            "uses_assessment_items": True,
                            "all_assessment_items": [{"id": "jebs"}],
            }
        ]

        items = [{"id": "jebs"}]

        exercises = set(k.get("id") for k in remove_untranslated_exercises(nodes, [], items))

        assert "translated" in exercises
Ejemplo n.º 8
0
    def test_returns_exercise_with_assessment_items(self):
        nodes = [{
            "kind": NodeType.exercise,
            "id": "translated",
            "uses_assessment_items": True,
            "all_assessment_items": [{
                "id": "jebs"
            }],
        }]

        items = [{"id": "jebs"}]

        exercises = set(
            k.get("id")
            for k in remove_untranslated_exercises(nodes, [], items))

        assert "translated" in exercises
Ejemplo n.º 9
0
    def test_always_returns_videos_and_topics(self):
        self.nodes = [
            {"kind": NodeType.exercise, "id": "no-html", "uses_assessment_items": False},
            {
                "kind": NodeType.exercise,
                "id": "no-assessment",
                "uses_assessment_items": True,
                "all_assessment_items": [],
            },
            {"kind": NodeType.video, "id": "video"},
            {"id": "topic", "kind": NodeType.topic},
        ]
        # these don't matter, and can thus be empty
        item_data = {}
        html_ids = set()

        result = set(s.get("id") for s in remove_untranslated_exercises(self.nodes, html_ids, item_data))

        assert "video" in result
        assert "topic" in result