Skip to content

Instantly share code, notes, and snippets.

@ammgws
Created December 13, 2019 14:02
Show Gist options
  • Save ammgws/fceaf31b787066002bb22451537c65fe to your computer and use it in GitHub Desktop.
Save ammgws/fceaf31b787066002bb22451537c65fe to your computer and use it in GitHub Desktop.
import re
from pathlib import Path
from langdetect import detect
p = Path("/tmp/f/fish-shell/po/")
pattern = re.compile('^msgstr\s*"(.{10,})"')
for pofile in list(p.glob('*.po')):
language = []
with open(pofile) as f:
po_data = f.readlines()
for line in po_data:
if m := pattern.match(line):
language.append(detect(m.group(1)))
if language:
result = max(set(language), key=language.count)
else:
result = "No translations or languages detected!"
print(f"{pofile}: {result}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment