diff --git a/fas/README b/fas/README index ae9df2b..3c01e73 100644 --- a/fas/README +++ b/fas/README @@ -135,3 +135,11 @@ To generate the POT file (located in the po/ subdirectory), run the following from the top level directory: pybabel extract -F pybabel.conf -o po/fas.pot . + +Message merging should be done manually using msgmerge at this point. + + python setup.py build + +compiles the PO files and places them where TurboGears will look for +them. To enable a language to be available to users, it must be added +to po/LINGUAS. diff --git a/fas/fas.cfg b/fas/fas.cfg index 6020ff7..9e1b649 100644 --- a/fas/fas.cfg +++ b/fas/fas.cfg @@ -1,4 +1,6 @@ [global] + +theme = 'fas' # TODO: better namespacing (maybe a [fas] section) admingroup = 'accounts' diff --git a/fas/fas/controllers.py b/fas/fas/controllers.py index b092bf5..40d412d 100644 --- a/fas/fas/controllers.py +++ b/fas/fas/controllers.py @@ -14,6 +14,7 @@ from fas.cla import CLA from fas.json_request import JsonRequest from fas.help import Help from fas.auth import * +from fas.util import available_languages #from fas.openid_fas import OpenID import os @@ -21,11 +22,6 @@ import sys reload(sys) sys.setdefaultencoding('utf-8') -def add_custom_stdvars(vars): - return vars.update({"gettext": _}) - -turbogears.view.variable_providers.append(add_custom_stdvars) - def get_locale(locale=None): if locale: return locale @@ -36,6 +32,12 @@ def get_locale(locale=None): config.update({'i18n.get_locale': get_locale}) +def add_custom_stdvars(vars): + return vars.update({'gettext': _, "lang": get_locale(), 'available_languages': available_languages()}) + +turbogears.view.variable_providers.append(add_custom_stdvars) + + # from fas import json # import logging # log = logging.getLogger("fas.controllers") @@ -138,8 +140,11 @@ class Root(controllers.RootController): @expose() def language(self, locale): - locale_key = config.get("i18n.session_key", "locale") - cherrypy.session[locale_key] = locale - raise redirect(request.headers.get("Referer", "/")) - + if locale not in available_languages(): + turbogears.flash(_('The language \'%s\' is not available.') % locale) + redirect(request.headers.get("Referer", "/")) + return dict() + turbogears.i18n.set_session_locale(locale) + redirect(request.headers.get("Referer", "/")) + return dict() diff --git a/fas/fas/templates/master.html b/fas/fas/templates/master.html index b18fadd..ec9aa4b 100644 --- a/fas/fas/templates/master.html +++ b/fas/fas/templates/master.html @@ -4,9 +4,9 @@ xmlns:py="http://genshi.edgewall.org/" py:strip=""> - @@ -68,15 +68,16 @@
  • ${_('Apply For a new Group')}
  • ${_('News')}
  • -
    - +
    - -->
    diff --git a/fas/fas/templates/user/edit.html b/fas/fas/templates/user/edit.html index 0b25090..c927e38 100644 --- a/fas/fas/templates/user/edit.html +++ b/fas/fas/templates/user/edit.html @@ -65,13 +65,10 @@
    - - - +
    diff --git a/fas/fas/user.py b/fas/fas/user.py index f3ab6ad..5f3b679 100644 --- a/fas/fas/user.py +++ b/fas/fas/user.py @@ -21,6 +21,7 @@ from fas.model import Log from fas import openssl_fas from fas.auth import * +from fas.util import available_languages from random import Random import sha @@ -65,9 +66,7 @@ class ValidSSHKey(validators.FancyValidator): return value.file.read() def validate_python(self, value, state): # value = value.file.read() - print dir(value) keylines = value.split('\n') - print "KEYLINES: %s" % keylines for keyline in keylines: if not keyline: continue @@ -85,6 +84,15 @@ class ValidUsername(validators.FancyValidator): if re.compile(username_blacklist).match(value): raise validators.Invalid(_("'%s' is an illegal username.") % value, value, state) +class ValidLanguage(validators.FancyValidator): + '''Make sure that a username isn't blacklisted''' + def _to_python(self, value, state): + return value.strip() + def validate_python(self, value, state): + if value not in available_languages(): + raise validators.Invalid(_('The language \'%s\' is not available.') % value, value, state) + + class UserSave(validators.Schema): targetname = KnownUser human_name = validators.All( @@ -96,6 +104,7 @@ class UserSave(validators.Schema): validators.Email(not_empty=True, strip=True, max=128), NonFedoraEmail(not_empty=True, strip=True, max=128), ) + locale = ValidLanguage(not_empty=True, strip=True) #fedoraPersonBugzillaMail = validators.Email(strip=True, max=128) #fedoraPersonKeyId- Save this one for later :) postal_address = validators.String(max=512) @@ -236,7 +245,8 @@ class User(controllers.Controller): turbogears.flash(_('You cannot edit %s') % target.username ) turbogears.redirect('/user/view/%s', target.username) return dict() - return dict(target=target) + languages = available_languages() + return dict(target=target, languages=languages) @identity.require(turbogears.identity.not_anonymous()) @validate(validators=UserSave()) diff --git a/fas/fas/util.py b/fas/fas/util.py new file mode 100644 index 0000000..5886cf2 --- /dev/null +++ b/fas/fas/util.py @@ -0,0 +1,16 @@ +import os +import codecs +from turbogears import config +from turbogears.i18n.tg_gettext import get_locale_dir + +def available_languages(): + """Return available languages for a given domain.""" + available_languages = [] + localedir = get_locale_dir() + linguas = codecs.open(os.path.join(localedir, 'LINGUAS'), 'r') + for lang in linguas.readlines(): + lang = lang.strip() + if lang and not lang.startswith('#'): + available_languages.append(lang) + return available_languages + diff --git a/fas/po/LINGUAS b/fas/po/LINGUAS new file mode 100644 index 0000000..074a8ba --- /dev/null +++ b/fas/po/LINGUAS @@ -0,0 +1,2 @@ +en +pl diff --git a/fas/setup.py b/fas/setup.py index d1ba4c5..54171b7 100644 --- a/fas/setup.py +++ b/fas/setup.py @@ -4,6 +4,7 @@ import os import re import glob import subprocess +import shutil from distutils.command.build import build as _build from distutils.command.install_data import install_data as _install_data @@ -71,6 +72,13 @@ class Build(_build, object): outf.writelines(line) outf.close() f.close() + + # Make empty en.po + dirname = 'locale/' + if not os.path.isdir(dirname): + os.makedirs(dirname) + shutil.copy('po/LINGUAS', 'locale/') + for pofile in poFiles: # Compile PO files lang = os.path.basename(pofile).rsplit('.', 1)[0]