def do_translation(self):
        target_lang_path_list = [l.to_path() for l in self.target_lang_list]

        # translate all files for each language
        for target_lang in self.target_lang_list:
            # Determine directory for translations
            target_path = os.path.join(self.category_path, target_lang.to_path())

            # Make new directory for translated articles
            if not os.path.exists(target_path):
                os.makedirs(target_path)

            # Make translator
            translator = FileTranslator(self.source_lang, target_lang)

            # Translate all files in directory
            for filename in os.listdir(self.category_path):
                # Skip files which are not text files (ends with .txt)
                if not filename.endswith('.txt'): continue

                file_source_path = os.path.join(self.category_path, filename)
                file_target_path = os.path.join(target_path, filename)

                # don't translate if translation already exists
                if os.path.exists(file_target_path): continue

                # Translate source file to target file
                translator.translate_to_file(file_source_path, file_target_path)
Example #2
0
    def do_translation(self):
        target_lang_path_list = [l.to_path() for l in self.target_lang_list]

        # First, remove folders with any translated content
        # for folder in os.listdir(self.category_path):
        #     if folder in target_lang_path_list:
        #         shutil.rmtree(os.path.join(self.category_path, folder))

        # Then, translate all files for each language
        for target_lang in self.target_lang_list:
            # Determine directory for translations
            target_path = os.path.join(self.category_path,
                                       target_lang.to_path())

            # Delete old folder of translations
            # if os.path.isdir(target_path):
            #     shutil.rmtree(target_path)
            #     time.sleep(5)

            # Make new directory for translated articles
            if not os.path.exists(target_path):
                os.makedirs(target_path)

            # Make translator
            translator = FileTranslator(self.source_lang, target_lang)

            # Translate all files in directory
            for filename in os.listdir(self.category_path):
                # Skip files which are not text files (ends with .txt)
                if not filename.endswith('.txt'): continue

                file_source_path = os.path.join(self.category_path, filename)
                file_target_path = os.path.join(target_path, filename)

                # don't translate if translation already exists
                if os.path.exists(file_target_path): continue

                # Translate source file to target file
                translator.translate_to_file(file_source_path,
                                             file_target_path)
Example #3
0
    def do_translation(self):
        target_lang_path_list = [l.to_path() for l in self.target_lang_list]

        # First, remove folders with any translated content
        # for folder in os.listdir(self.category_path):
        #     if folder in target_lang_path_list:
        #         shutil.rmtree(os.path.join(self.category_path, folder))

        # Then, translate all files for each language
        for target_lang in self.target_lang_list:
            # Determine directory for translations
            target_path = os.path.join(self.category_path, target_lang.to_path())

            # Delete old folder of translations
            # if os.path.isdir(target_path):
            #     shutil.rmtree(target_path)
            #     time.sleep(5)

            # Make new directory for translated articles
            if not os.path.exists(target_path):
                os.makedirs(target_path)

            # Make translator
            translator = FileTranslator(self.source_lang, target_lang)

            # Translate all files in directory
            for filename in os.listdir(self.category_path):
                # Skip files which are not text files (ends with .txt)
                if not filename.endswith('.txt'): continue

                file_source_path = os.path.join(self.category_path, filename)
                file_target_path = os.path.join(target_path, filename)

                # don't translate if translation already exists
                if os.path.exists(file_target_path): continue

                # Translate source file to target file
                translator.translate_to_file(file_source_path, file_target_path)