def test_creates_folder_with_contents(self):
        exercises = sorted(self.khan_exercises)[:5]  # use only first five for fast testing
        exercise_path, retrieved_exercises = retrieve_html_exercises(exercises, lang="es")

        assert retrieved_exercises  # not empty
        assert set(retrieved_exercises).issubset(self.khan_exercises)
        assert os.path.exists(exercise_path)
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)
Пример #3
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)
Пример #4
0
    def test_creates_folder_with_contents(self):
        exercises = sorted(
            self.khan_exercises)[:5]  # use only first five for fast testing
        exercise_path, retrieved_exercises = retrieve_html_exercises(exercises,
                                                                     lang="es")

        assert retrieved_exercises  # not empty
        assert set(retrieved_exercises).issubset(self.khan_exercises)
        assert os.path.exists(exercise_path)
    def test_returns_exercise_with_translation(self):
        # espanol has almost complete
        # translation. Assuming this specific
        # exercise has one
        lang = "es"
        exercise = self.khan_exercises[0]

        path, retrieved_exercises = retrieve_html_exercises([exercise], lang, force=True)

        assert retrieved_exercises == [exercise]
    def test_doesnt_return_exercises_without_translation(self):
        # The expected behaviour from KA's API is that it would return
        # the english version of an exercise if either a translated
        # exercise for the given language doesn't exist, or the
        # language is unsupported.
        exercise = self.khan_exercises[0]
        lang = "aaa"            # there's no language with code aaa... I hope?

        path, retrieved_exercises = retrieve_html_exercises([exercise], lang, force=True)

        assert not retrieved_exercises
Пример #7
0
    def test_returns_exercise_with_translation(self):
        # espanol has almost complete
        # translation. Assuming this specific
        # exercise has one
        lang = "es"
        exercise = self.khan_exercises[0]

        path, retrieved_exercises = retrieve_html_exercises([exercise],
                                                            lang,
                                                            force=True)

        assert retrieved_exercises == [exercise]
Пример #8
0
    def test_doesnt_return_exercises_without_translation(self):
        # The expected behaviour from KA's API is that it would return
        # the english version of an exercise if either a translated
        # exercise for the given language doesn't exist, or the
        # language is unsupported.
        exercise = self.khan_exercises[0]
        lang = "aaa"  # there's no language with code aaa... I hope?

        path, retrieved_exercises = retrieve_html_exercises([exercise],
                                                            lang,
                                                            force=True)

        assert not retrieved_exercises
Пример #9
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, 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,
    )
    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(
        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
    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(assessment_data, handle)