From 1bbcc8e5599b1eb2840df3daf0037c4948b09bbc Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 5 Oct 2008 23:14:25 +0000 Subject: [PATCH] start internationalisation * add babel stuff to setup.py * translate existing templates (addresses #11) * translate existing controllers git-svn-id: file:///var/www/wwwusers/usr01/svn/pyalchemybiz/trunk@9 389c73d4-bf09-4d3d-a15e-f94a37d0667a --- pyalchemybiz/controllers/index.py | 1 + .../i18n/de/LC_MESSAGES/pyalchemybiz.mo | Bin 0 -> 643 bytes .../i18n/de/LC_MESSAGES/pyalchemybiz.po | 45 ++++++++++++++++++ pyalchemybiz/i18n/pyalchemybiz.pot | 44 +++++++++++++++++ pyalchemybiz/lib/base.py | 9 +++- pyalchemybiz/templates/base.mako | 6 +-- pyalchemybiz/templates/customer/index.mako | 4 +- pyalchemybiz/templates/index.mako | 6 ++- setup.py | 8 ++-- 9 files changed, 112 insertions(+), 11 deletions(-) create mode 100644 pyalchemybiz/i18n/de/LC_MESSAGES/pyalchemybiz.mo create mode 100644 pyalchemybiz/i18n/de/LC_MESSAGES/pyalchemybiz.po create mode 100644 pyalchemybiz/i18n/pyalchemybiz.pot diff --git a/pyalchemybiz/controllers/index.py b/pyalchemybiz/controllers/index.py index e959244..8549b3c 100644 --- a/pyalchemybiz/controllers/index.py +++ b/pyalchemybiz/controllers/index.py @@ -8,6 +8,7 @@ log = logging.getLogger(__name__) class IndexController(BaseController): def index(self): + c.menuitems = [(_("Customer management"), "customer", "index")] # Return a rendered template # return render('/some/template.mako') # or, Return a response diff --git a/pyalchemybiz/i18n/de/LC_MESSAGES/pyalchemybiz.mo b/pyalchemybiz/i18n/de/LC_MESSAGES/pyalchemybiz.mo new file mode 100644 index 0000000000000000000000000000000000000000..28b70e6475c1f4db2e3aca795639a061492f9ff6 GIT binary patch literal 643 zcmZXR&u-H|5XKi&gs_nKcjd4bPSqL*36vVB;v{Ywu#?DfkSM3MGjX=qyU}`Fnmhv> zc>vCwxFasS02i)23uCBMBv$(A^V;96cfR>`ckd&kb)C3Rr0wRP^`4&Z5g&*f#3$k! z@tL?ud?D@---tcp2a#W4>?i4M;@~P{4(SWhwr)Y%*1aLUMY_KDeoo2;O^v1k%PXm6 z0TpOuN7iVZ(T*KMSsFIm24%j6YTH*kmH;+Zb2J>+z#r5ugQY??v*r|X6yv3M1-4d3 z`+T#Nf9o=}ngo6&TN{Bfdz?lkQhn? zpFi@vuIPBed%``>f9&mh^oEQgfiupG+sA6UiDyYNf7A ziN^Z;Xc0wx62u{Y7RJFi>IK7L63*v`WYtAO-HQ}tB8sTOrbLZ z3V|A?fVMvG%M41&?ts!`FB`oCeFpZOEV0oAo1?T?gF>2={BKexjs5;Lf6I4`{WGTw Kq|I8hX1@VO53q3n literal 0 HcmV?d00001 diff --git a/pyalchemybiz/i18n/de/LC_MESSAGES/pyalchemybiz.po b/pyalchemybiz/i18n/de/LC_MESSAGES/pyalchemybiz.po new file mode 100644 index 0000000..9d354de --- /dev/null +++ b/pyalchemybiz/i18n/de/LC_MESSAGES/pyalchemybiz.po @@ -0,0 +1,45 @@ +# German translations for pyalchemybiz. +# Copyright (C) 2008 ORGANIZATION +# This file is distributed under the same license as the pyalchemybiz +# project. +# Jan Dittberner , 2008. +# +msgid "" +msgstr "" +"Project-Id-Version: pyalchemybiz 0.1\n" +"Report-Msgid-Bugs-To: jan@dittberner.info\n" +"POT-Creation-Date: 2008-10-06 00:50+0200\n" +"PO-Revision-Date: 2008-10-06 01:10+0200\n" +"Last-Translator: Jan Dittberner \n" +"Language-Team: de \n" +"Plural-Forms: nplurals=2; plural=(n != 1)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 0.9.1\n" + +#: pyalchemybiz/controllers/index.py:11 +msgid "Customer management" +msgstr "Kundenverwaltung" + +#: pyalchemybiz/templates/base.mako:5 +msgid "PyAlchemyBiz" +msgstr "PyAlchemyBiz" + +#: pyalchemybiz/templates/base.mako:14 +#, python-format +msgid "Return to the %s." +msgstr "Zurück zur %s." + +#: pyalchemybiz/templates/base.mako:15 +msgid "FrontPage" +msgstr "Startseite" + +#: pyalchemybiz/templates/customer/index.mako:3 +msgid "Hello" +msgstr "Hallo" + +#: pyalchemybiz/templates/customer/index.mako:7 +msgid "edit" +msgstr "bearbeiten" + diff --git a/pyalchemybiz/i18n/pyalchemybiz.pot b/pyalchemybiz/i18n/pyalchemybiz.pot new file mode 100644 index 0000000..afe1aef --- /dev/null +++ b/pyalchemybiz/i18n/pyalchemybiz.pot @@ -0,0 +1,44 @@ +# Translations template for pyalchemybiz. +# Copyright (C) 2008 ORGANIZATION +# This file is distributed under the same license as the pyalchemybiz project. +# FIRST AUTHOR , 2008. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: pyalchemybiz 0.1\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2008-10-06 01:10+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 0.9.1\n" + +#: pyalchemybiz/controllers/index.py:11 +msgid "Customer management" +msgstr "" + +#: pyalchemybiz/templates/base.mako:5 +msgid "PyAlchemyBiz" +msgstr "" + +#: pyalchemybiz/templates/base.mako:14 +#, python-format +msgid "Return to the %s." +msgstr "" + +#: pyalchemybiz/templates/base.mako:15 +msgid "FrontPage" +msgstr "" + +#: pyalchemybiz/templates/customer/index.mako:3 +msgid "Hello" +msgstr "" + +#: pyalchemybiz/templates/customer/index.mako:7 +msgid "edit" +msgstr "" + diff --git a/pyalchemybiz/lib/base.py b/pyalchemybiz/lib/base.py index 7933628..4bbaf27 100644 --- a/pyalchemybiz/lib/base.py +++ b/pyalchemybiz/lib/base.py @@ -7,7 +7,7 @@ from pylons import c, cache, config, g, request, response, session from pylons.controllers import WSGIController from pylons.controllers.util import abort, etag_cache, redirect_to from pylons.decorators import jsonify, validate -from pylons.i18n import _, ungettext, N_ +from pylons.i18n import _, ungettext, N_, add_fallback, set_lang from pylons.templating import render import pyalchemybiz.lib.helpers as h @@ -24,6 +24,13 @@ class BaseController(WSGIController): # WSGIController.__call__ dispatches to the Controller method # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] + # set language environment + for lang in request.languages: + try: + add_fallback(lang) + except: + pass + # connect to database conn = meta.engine.connect() meta.Session.configure(bind=conn) try: diff --git a/pyalchemybiz/templates/base.mako b/pyalchemybiz/templates/base.mako index f9b2739..b3f1cf4 100644 --- a/pyalchemybiz/templates/base.mako +++ b/pyalchemybiz/templates/base.mako @@ -2,7 +2,7 @@ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> - PyAlchemyBiz + ${_('PyAlchemyBiz')} ${h.stylesheet_link_tag('/pyalchemybiz.css')} ${h.javascript_include_tag( '/javascripts/pyalchemybiz.js', builtins=True)} @@ -11,8 +11,8 @@
${next.body()}\
diff --git a/pyalchemybiz/templates/customer/index.mako b/pyalchemybiz/templates/customer/index.mako index 20989c6..58055e6 100644 --- a/pyalchemybiz/templates/customer/index.mako +++ b/pyalchemybiz/templates/customer/index.mako @@ -1,9 +1,9 @@ <%inherit file="/base.mako" /> -

Hallo

+

${_('Hello')}

    % for customer in c.customers: -
  • ${h.escape_once(customer)} [${h.link_to('edit', h.url_for(id=customer.id, action="edit"))}]
  • +
  • ${customer | h} [${h.link_to(_('edit'), h.url_for(id=customer.id, action="edit"))}]
  • % endfor
diff --git a/pyalchemybiz/templates/index.mako b/pyalchemybiz/templates/index.mako index 24b60ec..37fd53a 100644 --- a/pyalchemybiz/templates/index.mako +++ b/pyalchemybiz/templates/index.mako @@ -1,3 +1,7 @@ <%inherit file="base.mako" /> -${h.link_to('customers', h.url_for(controller="customer", action="index"))} \ No newline at end of file + \ No newline at end of file diff --git a/setup.py b/setup.py index ce20d15..6e3fa76 100755 --- a/setup.py +++ b/setup.py @@ -18,10 +18,10 @@ setup( include_package_data=True, test_suite='nose.collector', package_data={'pyalchemybiz': ['i18n/*/LC_MESSAGES/*.mo']}, - #message_extractors = {'pyalchemybiz': [ - # ('**.py', 'python', None), - # ('templates/**.mako', 'mako', None), - # ('public/**', 'ignore', None)]}, + message_extractors = {'pyalchemybiz': [ + ('**.py', 'python', None), + ('templates/**.mako', 'mako', None), + ('public/**', 'ignore', None)]}, entry_points=""" [paste.app_factory] main = pyalchemybiz.config.middleware:make_app