Skip to content

Commit

Permalink
dev instructions should now work with the new gettext-based infrastru…
Browse files Browse the repository at this point in the history
…cture.
  • Loading branch information
toolness committed Nov 12, 2011
1 parent 93a6577 commit 92abd1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,4 +3,4 @@ browser-addon/chrome/webxray.js
src/settings.local.js
static-files/mix-master-dialog
/locale
/src/locale
/src/locale/*.js
20 changes: 15 additions & 5 deletions go.py
Expand Up @@ -103,6 +103,13 @@ def serve(cfg, ip=''):
print "serving on %s port %d" % (ipstr, cfg['port'])
server.serve_forever()

def compilemessages(cfg):
localization.compilemessages(json_dir=path(cfg['staticFilesDir']),
js_locale_dir=path('src', 'locale'),
default_locale='en',
locale_dir=locale_dir,
locale_domain=locale_domain)

if __name__ == "__main__":
cfg = json.loads(open('config.json', 'r').read())
cfg['compiledFilename'] = cfg['staticFilesDir'] + cfg['compiledFile']
Expand All @@ -114,15 +121,13 @@ def serve(cfg, ip=''):
cmd = sys.argv[1]

if cmd == 'serve':
compilemessages(cfg)
serve(cfg, '127.0.0.1')
elif cmd == 'globalserve':
compilemessages(cfg)
serve(cfg)
elif cmd == 'compilemessages':
localization.compilemessages(json_dir=path(cfg['staticFilesDir']),
js_locale_dir=path('src', 'locale'),
default_locale='en',
locale_dir=locale_dir,
locale_domain=locale_domain)
compilemessages(cfg)
elif cmd == 'makemessages':
locale = None
if len(sys.argv) > 2:
Expand All @@ -133,13 +138,18 @@ def serve(cfg, ip=''):
locale_domain=locale_domain,
locale=locale)
elif cmd == 'compile':
compilemessages(cfg)
f = open(cfg['compiledFilename'], 'w')
f.write(build_compiled_file(cfg))
f.close()
print "wrote %s" % cfg['compiledFilename']
elif cmd == 'clean':
if os.path.exists(cfg['compiledFilename']):
print "removing %s" % cfg['compiledFilename']
os.remove(cfg['compiledFilename'])
for filename in glob.glob(path('src', 'locale', '*.js')):
print "removing %s" % filename
os.remove(filename)
print "removed generated files."
else:
print "unknown command: %s" % cmd
Expand Down
13 changes: 10 additions & 3 deletions vendor/localization.py
Expand Up @@ -32,6 +32,8 @@ def webxray_extract(fileobj, keywords, comment_tags, options):
yield (lineno, funcname, message, comments)

def find_locales(dirname, domain):
if not os.path.exists(dirname):
return []
return [name for name in os.listdir(dirname)
if locale_exists(name, dirname, domain)]

Expand All @@ -45,9 +47,11 @@ def compilemessages(json_dir, js_locale_dir, locale_dir, locale_domain,
"convert message files into binary and JS formats"

data = json.load(open(os.path.join(json_dir, 'strings.json')))
babel(['compile', '--use-fuzzy', '-d', locale_dir, '-D',
locale_domain])
locales = find_locales(locale_dir, locale_domain) + [default_locale]
found_locales = find_locales(locale_dir, locale_domain)
if found_locales:
babel(['compile', '--use-fuzzy', '-d', locale_dir, '-D',
locale_domain])
locales = found_locales + [default_locale]
for locale in locales:
nice_locale = locale.replace('_', '-')
print "processing localization '%s'" % nice_locale
Expand Down Expand Up @@ -94,6 +98,9 @@ def makemessages(babel_ini_file, json_dir, locale_dir,
babel(['extract', '-F', babel_ini_file, '-o', potfile,
json_dir])

if not locale and not find_locales(locale_dir, locale_domain):
return

babel([cmd, '-i', potfile, '-d', locale_dir, '-D', locale_domain] +
localeargs)

Expand Down

0 comments on commit 92abd1e

Please sign in to comment.