2010-05-07 16:33:48 +05:30
|
|
|
# SetLanguage.py
|
|
|
|
#
|
|
|
|
# Gramps - a GTK+ based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010 Stephen George
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2014-08-09 07:59:07 +05:30
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-05-07 16:33:48 +05:30
|
|
|
#
|
|
|
|
# $Id: $
|
|
|
|
import locale
|
|
|
|
import _winreg
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
import logging
|
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
|
|
format='%(asctime)s %(name)-10s %(levelname)-8s %(message)s',
|
|
|
|
datefmt='%H:%M',
|
|
|
|
filename= 'c:/launcher.log', #path.join(out_dir,'build.log'),
|
|
|
|
filemode='w')
|
|
|
|
#create a Handler for the console
|
|
|
|
console = logging.StreamHandler()
|
|
|
|
console.setLevel(logging.INFO)
|
|
|
|
#Set a simle format for console
|
|
|
|
formatter = logging.Formatter('%(levelname)-8s %(message)s')
|
|
|
|
console.setFormatter(formatter)
|
|
|
|
#add the console handler to the root handler
|
|
|
|
log = logging.getLogger('BuildApp')
|
|
|
|
log.addHandler(console)
|
|
|
|
|
|
|
|
|
|
|
|
langLookup = {
|
|
|
|
'ar' : 'Arabic',
|
|
|
|
'bg' : 'Bulgarian',
|
|
|
|
'ca' : 'Catalan',
|
|
|
|
'cs' : 'Czech',
|
|
|
|
'da' : 'Danish ',
|
|
|
|
'de' : 'German',
|
|
|
|
'en' : 'English',
|
2010-11-18 07:47:38 +05:30
|
|
|
'eo' : 'Esperanto',
|
2010-05-07 16:33:48 +05:30
|
|
|
'es' : 'Spanish',
|
|
|
|
'fi' : 'Finnish',
|
2016-09-01 10:22:45 +05:30
|
|
|
'fr' : 'French',
|
2011-12-14 14:07:29 +05:30
|
|
|
'ga' : 'Irish',
|
2010-05-07 16:33:48 +05:30
|
|
|
'he' : 'Hebrew',
|
|
|
|
'hr' : 'Croatian',
|
|
|
|
'hu' : 'Hungarian',
|
2016-09-01 10:22:45 +05:30
|
|
|
'it' : 'Italian',
|
2011-12-14 14:07:29 +05:30
|
|
|
'ja' : 'Japanese',
|
2010-05-07 16:33:48 +05:30
|
|
|
'lt' : 'Lithuanian',
|
|
|
|
'mk' : 'Macedonian',
|
|
|
|
'nb' : '',
|
|
|
|
'nl' : 'Dutch',
|
|
|
|
'nn' : '',
|
|
|
|
'pl' : 'Polish',
|
|
|
|
'pt_BR' : 'Portuguese (Brazil)',
|
|
|
|
'ro' : 'Romanian',
|
|
|
|
'ru' : 'Russian',
|
|
|
|
'sk' : 'Slovak',
|
|
|
|
'sl' : 'Slovenian',
|
|
|
|
'sq' : 'Albanian',
|
|
|
|
'sr' : 'Serbian',
|
|
|
|
'sv' : 'Swedish',
|
2016-09-01 10:22:45 +05:30
|
|
|
'tr' : 'Turkish',
|
|
|
|
'uk' : 'Ukrainian',
|
2011-12-14 14:07:29 +05:30
|
|
|
'vi' : 'Vietnamese',
|
2010-05-07 16:33:48 +05:30
|
|
|
'zh_CN' : 'Chinese (PRC)',
|
|
|
|
}
|
|
|
|
|
|
|
|
def GetGtkPath():
|
|
|
|
log.debug('GetGtkPath()')
|
|
|
|
dllPathInRegistry = None
|
|
|
|
try:
|
|
|
|
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\GTK\\2.0') as key:
|
|
|
|
dllPathInRegistry = _winreg.QueryValueEx(key, 'DllPath')[0]
|
|
|
|
# check a few key files exist at this location
|
2016-08-22 20:18:17 +05:30
|
|
|
gtkfiles = ['libgdk-win32-2.0-0.dll', 'libglib-2.0-0.dll', 'libgobject-2.0-0.dll', 'libcairo-2.dll']
|
2010-05-07 16:33:48 +05:30
|
|
|
for file in gtkfiles:
|
|
|
|
if not os.path.isfile(os.path.join(dllPathInRegistry, file)):
|
|
|
|
dllPathInRegistry = None # one of the files not present, so assume path is wrong
|
|
|
|
break
|
2016-08-22 20:18:17 +05:30
|
|
|
except WindowsError as e:
|
2010-05-07 16:33:48 +05:30
|
|
|
dllPathInRegistry = None
|
|
|
|
log.debug(' DLLPATH=%s'%dllPathInRegistry)
|
|
|
|
return dllPathInRegistry
|
|
|
|
|
|
|
|
def GetGrampsPath():
|
|
|
|
GrampsPathInRegistry = None
|
2016-08-22 20:18:17 +05:30
|
|
|
try:
|
2010-05-07 16:33:48 +05:30
|
|
|
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\GRAMPS') as key:
|
|
|
|
GrampsPathInRegistry = _winreg.QueryValue(key, '')
|
|
|
|
# check a few key files exist at this location
|
2016-08-22 20:18:17 +05:30
|
|
|
except WindowsError as e:
|
2010-05-07 16:33:48 +05:30
|
|
|
GrampsPathInRegistry = None
|
2016-08-22 20:18:17 +05:30
|
|
|
|
2010-05-07 16:33:48 +05:30
|
|
|
log.debug(' GRAMPSPATH=%s'%GrampsPathInRegistry)
|
|
|
|
return GrampsPathInRegistry
|
2016-08-22 20:18:17 +05:30
|
|
|
|
2010-05-07 16:33:48 +05:30
|
|
|
def GetLanguageFromLocale():
|
|
|
|
lang = ' '
|
|
|
|
try:
|
|
|
|
lang = os.environ["LANG"]
|
|
|
|
lang = lang.split('.')[0]
|
|
|
|
except:
|
|
|
|
# if LANG is not set
|
|
|
|
lang = locale.getlocale()[0]
|
|
|
|
if not lang:
|
|
|
|
# if lang is empty/None
|
2016-09-01 10:22:45 +05:30
|
|
|
lang = locale.getdefaultlocale()[0]
|
2010-05-07 16:33:48 +05:30
|
|
|
return lang
|
|
|
|
|
|
|
|
def writeLauncher(language, langcode, runtimepath, grampspath):
|
|
|
|
lines = []
|
2010-11-18 07:47:38 +05:30
|
|
|
lines.append('''@rem Setting the working language
|
2016-08-22 20:18:17 +05:30
|
|
|
@rem ============================
|
2016-09-01 10:22:45 +05:30
|
|
|
@rem GRAMPS looks during the start-up-phase for an environment variable (called LANG)
|
2010-11-18 07:47:38 +05:30
|
|
|
@rem to switch to a special language. It's better to use a ".CMD" or ".BAT" file to
|
|
|
|
@rem control this environment variable instead a permanent setting in the windows registry,
|
2016-09-01 10:22:45 +05:30
|
|
|
@rem to have the possibility to go back to the GRAMPS standard language (English) in the
|
2010-11-18 07:47:38 +05:30
|
|
|
@rem case you want to report about a problem or a bug.
|
2016-08-22 20:18:17 +05:30
|
|
|
''')
|
2010-11-18 07:47:38 +05:30
|
|
|
lines.append('\n@rem Set GRAMPS environment settings to %s \n' % language)
|
2010-05-07 16:33:48 +05:30
|
|
|
lines.append('SET LANG=$LANG$ \nSET LANGUAGE=$LANG$\n'.replace("$LANG$", langcode) )
|
2016-08-22 20:18:17 +05:30
|
|
|
|
2010-11-18 07:47:38 +05:30
|
|
|
lines.append('''\n\n@rem Setting the configuration path
|
2016-08-22 20:18:17 +05:30
|
|
|
@rem ==============================
|
2010-11-18 07:47:38 +05:30
|
|
|
@rem During the boot process of GRAMPS there is a check for an environment variable
|
2016-09-01 10:22:45 +05:30
|
|
|
@rem called GRAMPSHOME. Without this environment variable GRAMPS uses the default
|
2010-11-18 07:47:38 +05:30
|
|
|
@rem windows path as the location to save all configuration files:
|
2016-09-01 10:22:45 +05:30
|
|
|
@rem <system drive>\<userpath>\<application data>\gramps
|
2010-11-18 07:47:38 +05:30
|
|
|
@rem If required, uncomment GRAMPSHOME line and edit to suit your use.
|
|
|
|
''')
|
|
|
|
lines.append('\n@rem set the path for GRAMPS configuration files')
|
|
|
|
lines.append('\n@rem set GRAMPSHOME=PATH_TO_CONFIG_FILES')
|
|
|
|
|
|
|
|
lines.append('''\n\n@rem Put GTK runtime on PATH
|
|
|
|
@rem =========================
|
|
|
|
@rem Ensure GTK runtime on path first, so right GTK DLL's used.
|
|
|
|
''')
|
2010-05-07 16:33:48 +05:30
|
|
|
if runtimepath:
|
2010-11-18 07:47:38 +05:30
|
|
|
lines.append('\n@rem Put your gtk runtime first on path')
|
2010-05-07 16:33:48 +05:30
|
|
|
path = '\npath="%s";%%PATH%%' % runtimepath
|
|
|
|
else:
|
2010-11-18 07:47:38 +05:30
|
|
|
lines.append('\n@rem Uncommnet following line, and edit path to your GTK runtime')
|
2016-09-01 10:22:45 +05:30
|
|
|
path = "\n@rem path=PATH_TO_YOUR_GTK_RUNTIME;%%PATH%%\n"
|
2010-05-07 16:33:48 +05:30
|
|
|
lines.append(path)
|
2010-11-18 07:47:38 +05:30
|
|
|
lines.append('''\n\n@rem Start GRAMPS application
|
|
|
|
@rem =========================
|
2016-08-22 20:18:17 +05:30
|
|
|
@rem Start GRAMPS with pythonw.exe (Python interpreter that runs without a command line console)
|
2010-11-18 07:47:38 +05:30
|
|
|
''')
|
2010-05-07 16:33:48 +05:30
|
|
|
lines.append('\n@rem start Gramps')
|
|
|
|
lines.append('\n"%s" "%s"\n' % (os.path.join(sys.prefix, 'pythonw.exe') , os.path.join(grampspath, 'gramps.py' ) ))
|
|
|
|
fout = open( os.path.join(grampspath, 'gramps_locale.cmd'), 'w')
|
|
|
|
fout.writelines(lines)
|
|
|
|
fout.close()
|
|
|
|
for line in lines:
|
2016-08-22 20:18:17 +05:30
|
|
|
print(line)
|
2010-05-07 16:33:48 +05:30
|
|
|
|
|
|
|
gtkpath = GetGtkPath()
|
|
|
|
grampspath = GetGrampsPath()
|
|
|
|
lang = GetLanguageFromLocale()
|
|
|
|
if lang:
|
|
|
|
try:
|
|
|
|
lang_text = langLookup[lang.split('_', 1)[0]]
|
2016-08-22 20:18:17 +05:30
|
|
|
except KeyError as e:
|
2010-05-07 16:33:48 +05:30
|
|
|
try:
|
|
|
|
lang_text = langLookup[lang]
|
2016-08-22 20:18:17 +05:30
|
|
|
except KeyError as e:
|
2010-05-07 16:33:48 +05:30
|
|
|
lang_text = "Unknown"
|
2016-08-22 20:18:17 +05:30
|
|
|
|
|
|
|
writeLauncher(lang_text, "%s.utf-8"%lang, gtkpath, grampspath)
|