<commit_before>#!/usr/bin/env python

import sys
import os
import random
import copy
import time
import traceback
import inspect
import imp

#http://stackoverflow.com/questions/606561/how-to-get-filename-of-the-main-module-in-python
def main_is_frozen():
   return (hasattr(sys, "frozen") or # new py2exe
           hasattr(sys, "importers") # old py2exe
           or imp.is_frozen("__main__")) # tools/freeze

def get_main_dir():
   if main_is_frozen():
       # print 'Running from path', os.path.dirname(sys.executable)
       return os.path.dirname(sys.executable)
   return os.path.dirname(os.path.realpath(__file__))

script_dir = get_main_dir()

#if sys.platform == 'win32' and hasattr(sys, "frozen"):
#    script_dir = os.path.dirname(sys.executable)
#else:
#    script_dir = os.path.dirname(os.path.realpath(__file__)) 

# ----- Handling localization
import locale
import gettext
APP_NAME = "monorail"
LOCALE_DIR = os.path.join(script_dir, "data/locale")
DEFAULT_LANGUAGES = os.environ.get('LANG', '').split(':')
DEFAULT_LANGUAGES += ['en_US']
 
lc, encoding = locale.getdefaultlocale()
if lc:
    languages = [lc]

languages += DEFAULT_LANGUAGES
mo_location = LOCALE_DIR

gettext.install (True,localedir=None, unicode=1)
gettext.find(APP_NAME, mo_location)
gettext.textdomain (APP_NAME)
gettext.bind_textdomain_codeset(APP_NAME, "UTF-8")<commit_msg>Also check other enviroment variables for the language<commit_after>#!/usr/bin/env python

import sys
import os
import random
import copy
import time
import traceback
import inspect
import imp

#http://stackoverflow.com/questions/606561/how-to-get-filename-of-the-main-module-in-python
def main_is_frozen():
   return (hasattr(sys, "frozen") or # new py2exe
           hasattr(sys, "importers") # old py2exe
           or imp.is_frozen("__main__")) # tools/freeze

def get_main_dir():
   if main_is_frozen():
       # print 'Running from path', os.path.dirname(sys.executable)
       return os.path.dirname(sys.executable)
   return os.path.dirname(os.path.realpath(__file__))

script_dir = get_main_dir()

#if sys.platform == 'win32' and hasattr(sys, "frozen"):
#    script_dir = os.path.dirname(sys.executable)
#else:
#    script_dir = os.path.dirname(os.path.realpath(__file__)) 

# ----- Handling localization
import locale
import gettext
APP_NAME = "monorail"
LOCALE_DIR = os.path.join(script_dir, "data/locale")
DEFAULT_LANGUAGES = os.environ.get('LANGUAGE', '').split(':')
DEFAULT_LANGUAGES += os.environ.get('LC_ALL', '').split(':')
DEFAULT_LANGUAGES += os.environ.get('LC_MESSAGES', '').split(':')
DEFAULT_LANGUAGES += os.environ.get('LANG', '').split(':')
DEFAULT_LANGUAGES += ['en_US']
 
lc, encoding = locale.getdefaultlocale()
if lc:
    languages = [lc]

languages += DEFAULT_LANGUAGES
mo_location = LOCALE_DIR

gettext.install (True,localedir=None, unicode=1)
gettext.find(APP_NAME, mo_location)
gettext.textdomain (APP_NAME)
gettext.bind_textdomain_codeset(APP_NAME, "UTF-8")
{'fraction_non_alphanumeric': 0.14198576753642833, 'fraction_numerical': 0.008132836326668925, 'mean_word_length': 4.892215568862276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1311433', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1043, 'n_words': 207}