diff --git a/mediagoblin/globals.py b/mediagoblin/globals.py index 59a94558..80d1f01d 100644 --- a/mediagoblin/globals.py +++ b/mediagoblin/globals.py @@ -2,6 +2,9 @@ In some places, we need to access the database, public_store, queue_store """ +import gettext +import pkg_resources + ############################# # General mediagoblin globals ############################# @@ -16,6 +19,12 @@ database = None public_store = None queue_store = None +# gettext +translations = gettext.find( + 'mediagoblin', + pkg_resources.resource_filename( + 'mediagoblin', 'translations'), ['en']) + def setup_globals(**kwargs): from mediagoblin import globals as mg_globals diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html index 44d26a65..fa78bda2 100644 --- a/mediagoblin/templates/mediagoblin/root.html +++ b/mediagoblin/templates/mediagoblin/root.html @@ -19,9 +19,7 @@ {% block mediagoblin_content %} -

Welcome to GNU MediaGoblin!

- {# -

{% trans %}Welcome to GNU MediaGoblin!{% endtrans %}

#} +

{% trans %}Welcome to GNU MediaGoblin!{% endtrans %}

{% if request.user %}

diff --git a/mediagoblin/translations/en/LC_MESSAGES/mediagoblin.mo b/mediagoblin/translations/en/LC_MESSAGES/mediagoblin.mo new file mode 100644 index 00000000..fb7046cd Binary files /dev/null and b/mediagoblin/translations/en/LC_MESSAGES/mediagoblin.mo differ diff --git a/mediagoblin/translations/en/LC_MESSAGES/mediagoblin.po b/mediagoblin/translations/en/LC_MESSAGES/mediagoblin.po index 0e242fee..3bec204e 100644 --- a/mediagoblin/translations/en/LC_MESSAGES/mediagoblin.po +++ b/mediagoblin/translations/en/LC_MESSAGES/mediagoblin.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2011-05-12 10:17-0500\n" +"POT-Creation-Date: 2011-05-12 22:28-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,7 +17,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 0.9.6\n" -#: mediagoblin/templates/mediagoblin/root.html:21 +#: mediagoblin/templates/mediagoblin/root.html:22 msgid "Welcome to GNU MediaGoblin!" msgstr "" diff --git a/mediagoblin/util.py b/mediagoblin/util.py index ac977bdb..8c6ec6cc 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -15,6 +15,8 @@ # along with this program. If not, see . from email.MIMEText import MIMEText +import gettext +import pkg_resources import smtplib import sys @@ -56,10 +58,18 @@ def get_jinja_env(template_loader, locale): (In the future we may have another system for providing theming; for now this is good enough.) """ - return jinja2.Environment( + setup_gettext(locale) + + template_env = jinja2.Environment( loader=template_loader, autoescape=True, extensions=['jinja2.ext.i18n']) + template_env.install_gettext_callables( + mgoblin_globals.translations.gettext, + mgoblin_globals.translations.ngettext) + + return template_env + def setup_user_in_request(request): """ @@ -196,6 +206,10 @@ def send_email(from_addr, to_addrs, subject, message_body): ################### +TRANSLATIONS_PATH = pkg_resources.resource_filename( + 'mediagoblin', 'translations') + + def locale_to_lower_upper(locale): """ Take a locale, regardless of style, and format it like "en-us" @@ -246,3 +260,20 @@ def get_locale_from_request(request): target_lang = 'en' return locale_to_lower_upper(target_lang) + + +def setup_gettext(locale): + """ + Setup the gettext instance based on this locale + """ + # Later on when we have plugins we may want to enable the + # multi-translations system they have so we can handle plugin + # translations too + + # TODO: fallback nicely on translations from pt_PT to pt if not + # available, etc. + this_gettext = gettext.translation( + 'mediagoblin', TRANSLATIONS_PATH, [locale], fallback=True) + + mgoblin_globals.setup_globals( + translations=this_gettext)