#! /usr/bin/python3

import sys, os, os.path
from subprocess import call

lang     = os.environ.get('LANG')
language = os.environ.get('LANGUAGE')
lc_all   = os.environ.get('LC_ALL')

pdfTail  = 'eyes17.pdf'

preferred='en'
if language and language[0:2] != preferred:
    preferred=language[0:2]
elif lang and lang[0:2] != preferred:
    preferred=lang[0:2]
elif lc_all and lc_all[0:2] != preferred:
    preferred=lc_all[0:2]
if len(sys.argv)>1:
    preferred=sys.argv[1]

filename=os.path.join('/usr/share/eyes17/doc', preferred, pdfTail)
if not os.path.exists(filename):
    filename=os.path.join('/usr/share/eyes17/doc/en', pdfTail)
call('evince '+filename, shell=True)
