comparison pyntnclick/main.py @ 817:beac13c4e982 pyntnclick

Also warn about out-of-date tool translations if running rect-drawer
author Neil Muller <neil@dip.sun.ac.za>
date Sun, 27 Jan 2013 22:20:40 +0200
parents 5ec7905b2365
children 9f542ef6e498
comparison
equal deleted inserted replaced
816:eed75a1d50c4 817:beac13c4e982
10 from optparse import OptionParser 10 from optparse import OptionParser
11 11
12 import pygame 12 import pygame
13 from pygame.locals import SWSURFACE 13 from pygame.locals import SWSURFACE
14 14
15 from pyntnclick.i18n import _, get_module_locale 15 from pyntnclick.i18n import _, get_module_i18n_path
16 from pyntnclick.engine import Engine 16 from pyntnclick.engine import Engine
17 from pyntnclick.gamescreen import DefMenuScreen, DefEndScreen, GameScreen 17 from pyntnclick.gamescreen import DefMenuScreen, DefEndScreen, GameScreen
18 from pyntnclick.constants import GameConstants, DEBUG_ENVVAR 18 from pyntnclick.constants import GameConstants, DEBUG_ENVVAR
19 from pyntnclick.resources import Resources 19 from pyntnclick.resources import Resources
20 from pyntnclick.sound import Sound 20 from pyntnclick.sound import Sound
68 68
69 locale.setlocale(locale.LC_ALL, "") 69 locale.setlocale(locale.LC_ALL, "")
70 lang = locale.getdefaultlocale(['LANGUAGE', 'LC_ALL', 'LC_CTYPE', 70 lang = locale.getdefaultlocale(['LANGUAGE', 'LC_ALL', 'LC_CTYPE',
71 'LANG'])[0] 71 'LANG'])[0]
72 self.resource = Resources(self._resource_module, lang) 72 self.resource = Resources(self._resource_module, lang)
73 gettext.bindtextdomain(self.constants.short_name, 73 locale_path = self.resource.get_resource_path('locale')
74 self.resource.get_resource_path('locale')) 74 gettext.bindtextdomain(self.constants.short_name, locale_path)
75 gettext.textdomain(self.constants.short_name) 75 gettext.textdomain(self.constants.short_name)
76 76
77 self._check_translations() 77 popath = self.resource.get_resource_path('po')
78 self._check_translations(popath, locale_path)
78 79
79 self.sound = Sound(self.resource) 80 self.sound = Sound(self.resource)
80 self.debug_options = [] 81 self.debug_options = []
81 self.running = False 82 self.running = False
82 83
83 def _check_translations(self): 84 def _check_translations(self, popath, locale_path):
84 """Check for outdated mo files""" 85 """Check for outdated mo files"""
85 popath = self.resource.get_resource_path('po') 86 name = gettext.textdomain() # only check the current app
86 mopath = self.resource.get_resource_path('locale')
87 for candidate in os.listdir(popath): 87 for candidate in os.listdir(popath):
88 if candidate.endswith('.po'): 88 if candidate.endswith('.po'):
89 polang = candidate.split('.', 1)[0] 89 polang = candidate.split('.', 1)[0]
90 pofile = os.path.join(popath, candidate) 90 pofile = os.path.join(popath, candidate)
91 mofile = gettext.find(self.constants.short_name, mopath, 91 mofile = gettext.find(name, locale_path, (polang,))
92 (polang,))
93 if mofile is None: 92 if mofile is None:
94 print 'Missing mo file for %s' % pofile 93 print 'Missing mo file for %s' % pofile
95 continue 94 continue
96 if os.stat(pofile).st_mtime > os.stat(mofile).st_mtime: 95 if os.stat(pofile).st_mtime > os.stat(mofile).st_mtime:
97 print 'po file %s is newer than mo file %s' % (pofile, 96 print 'po file %s is newer than mo file %s' % (pofile,
167 sys.exit(0) 166 sys.exit(0)
168 if self.constants.debug and opts.rect_drawer: 167 if self.constants.debug and opts.rect_drawer:
169 if opts.scene is None: 168 if opts.scene is None:
170 print 'Need to supply a scene to use the rect drawer' 169 print 'Need to supply a scene to use the rect drawer'
171 sys.exit(1) 170 sys.exit(1)
172 gettext.bindtextdomain('pyntnclick-tools', 171 locale_path = get_module_i18n_path(
173 get_module_locale(self.resource.DEFAULT_RESOURCE_MODULE)) 172 self.resource.DEFAULT_RESOURCE_MODULE)
173 gettext.bindtextdomain('pyntnclick-tools', locale_path)
174 gettext.textdomain('pyntnclick-tools') 174 gettext.textdomain('pyntnclick-tools')
175 popath = get_module_i18n_path(
176 self.resource.DEFAULT_RESOURCE_MODULE, 'po')
177 self._check_translations(popath, locale_path)
175 make_rect_display() 178 make_rect_display()
176 try: 179 try:
177 self.engine = RectEngine(self, opts.detail) 180 self.engine = RectEngine(self, opts.detail)
178 except RectDrawerError, e: 181 except RectDrawerError, e:
179 print 'RectDrawer failed with: %s' % e 182 print 'RectDrawer failed with: %s' % e