dosage/scripts/mklanguages.py
Tobias Gruetzmacher 808b624e5f Remove hard dependency on pycountry again.
This basically reverts commit 86b31dc12b.

It now works like this: If the use has pycountry installed, it is used.
If not, Dosage falls back to a small internal list generated from
pycountry by scripts/mklanguages.py.

This means additional work if we ever decide to translate Dosage, since
pycountry already has all the translations for language names...

This fixes #23.
2015-07-11 01:27:39 +02:00

41 lines
1.2 KiB
Python
Executable file

#!/usr/bin/python
# update languages.py from pycountry
import os
import sys
import codecs
basepath = os.path.dirname(os.path.dirname(__file__))
sys.path.append(basepath)
from dosagelib.scraper import get_scraperclasses
def main():
"""Update language information in dosagelib/languages.py."""
fn = os.path.join(basepath, 'dosagelib', 'languages.py')
encoding = 'utf-8'
with codecs.open(fn, 'w', encoding) as f:
f.write('# -*- coding: %s -*-%s' % (encoding, os.linesep))
f.write('# ISO 693-1 language codes from pycountry%s' % os.linesep)
f.write('# This file is automatically generated, DO NOT EDIT!%s' % os.linesep)
lang = get_used_languages()
write_languages(f, lang)
def get_used_languages():
lang = {}
for scraperclass in get_scraperclasses():
l = scraperclass.lang
if l not in lang:
lang[l] = scraperclass.language()
return lang
def write_languages(f, l):
"""Write language information."""
f.write("Languages = {%s" % os.linesep)
for lang in sorted(l):
f.write(" %r: %r,%s" % (lang, l[lang], os.linesep))
f.write("}%s" % os.linesep)
if __name__ == '__main__':
main()