Skip to content

Commit

Permalink
update skip-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
zyddnys committed May 24, 2024
1 parent c101755 commit b547722
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions manga_translator/manga_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,25 @@ async def _translate(self, ctx: Context) -> Context:
# -- OCR
await self._report_progress('ocr')
ctx.textlines = await self._run_ocr(ctx)

if ctx.skip_lang is not None :
filtered_textlines = []
skip_langs = ctx.skip_lang.split(',')
for txtln in ctx.textlines :
try :
source_language = LANGDETECT_MAP.get(langdetect.detect(txtln.text), 'UNKNOWN')
except Exception :
source_language = 'UNKNOWN'
if source_language not in skip_langs :
filtered_textlines.append(txtln)
ctx.textlines = filtered_textlines

if not ctx.textlines:
await self._report_progress('skip-no-text', True)
# If no text was found result is intermediate image product
ctx.result = ctx.upscaled
return await self._revert_upscale(ctx)

if ctx.skip_lang is not None :
skip_langs = ctx.skip_lang.split(',')
detected_text = ''.join([l.text for l in ctx.textlines])
source_language = LANGDETECT_MAP.get(langdetect.detect(detected_text), 'UNKNOWN')
if source_language in skip_langs :
print('skip due to', source_language, 'in', skip_langs)
await self._report_progress('finished', True)
ctx.result = ctx.upscaled
return await self._revert_upscale(ctx)

# -- Textline merge
await self._report_progress('textline_merge')
ctx.text_regions = await self._run_textline_merge(ctx)
Expand Down

0 comments on commit b547722

Please sign in to comment.