Created
December 13, 2019 14:02
-
-
Save ammgws/fceaf31b787066002bb22451537c65fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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