From ee55963d9dfd7b1e4a086c09b71101b0e356eae3 Mon Sep 17 00:00:00 2001 From: popcion Date: Wed, 11 Dec 2024 17:08:43 +0800 Subject: [PATCH] fix skip_lang --- manga_translator/manga_translator.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/manga_translator/manga_translator.py b/manga_translator/manga_translator.py index d0147fe0..dd7343bb 100644 --- a/manga_translator/manga_translator.py +++ b/manga_translator/manga_translator.py @@ -326,32 +326,29 @@ async def _run_ocr(self, config: Config, ctx: Context): async def _run_textline_merge(self, config: Config, ctx: Context): text_regions = await dispatch_textline_merge(ctx.textlines, ctx.img_rgb.shape[1], ctx.img_rgb.shape[0], verbose=self.verbose) - # First, filter out languages to skip - if ctx.skip_lang is not None: - skip_langs = [lang.strip().upper() for lang in ctx.skip_lang.split(',')] - filtered_text_regions = [] - for region in text_regions: + # Filter out languages to skip + if config.translator.skip_lang is not None: + skip_langs = [lang.strip().upper() for lang in config.translator.skip_lang.split(',')] + filtered_textlines = [] + for txtln in ctx.textlines: try: - detected_lang = langdetect.detect(region.text) + detected_lang = langdetect.detect(txtln.text) source_language = LANGDETECT_MAP.get(detected_lang.lower(), 'UNKNOWN').upper() except Exception: source_language = 'UNKNOWN' # Print detected source_language and whether it's in skip_langs - # logger.info(f'Detected source language: {source_language}, in skip_langs: {source_language in skip_langs}, text: "{region.text}"') + # logger.info(f'Detected source language: {source_language}, in skip_langs: {source_language in skip_langs}, text: "{txtln.text}"') if source_language in skip_langs: - logger.info(f'Filtered out: {region.text}') + logger.info(f'Filtered out: {txtln.text}') logger.info(f'Reason: Detected language {source_language} is in skip_langs') continue # Skip this region - filtered_text_regions.append(region) - text_regions = filtered_text_regions + filtered_textlines.append(txtln) + ctx.textlines = filtered_textlines - if not text_regions: - await self._report_progress('skip-no-text', True) - # If all text regions are filtered out, return an empty list - ctx.result = ctx.upscaled - return [] + text_regions = await dispatch_textline_merge(ctx.textlines, ctx.img_rgb.shape[1], ctx.img_rgb.shape[0], + verbose=self.verbose) new_text_regions = [] for region in text_regions: