Load gettext, and load it into the template environment
This commit is contained in:
parent
e461b77713
commit
b77eec653d
@ -2,6 +2,9 @@
|
|||||||
In some places, we need to access the database, public_store, queue_store
|
In some places, we need to access the database, public_store, queue_store
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# General mediagoblin globals
|
# General mediagoblin globals
|
||||||
#############################
|
#############################
|
||||||
@ -16,6 +19,12 @@ database = None
|
|||||||
public_store = None
|
public_store = None
|
||||||
queue_store = None
|
queue_store = None
|
||||||
|
|
||||||
|
# gettext
|
||||||
|
translations = gettext.find(
|
||||||
|
'mediagoblin',
|
||||||
|
pkg_resources.resource_filename(
|
||||||
|
'mediagoblin', 'translations'), ['en'])
|
||||||
|
|
||||||
|
|
||||||
def setup_globals(**kwargs):
|
def setup_globals(**kwargs):
|
||||||
from mediagoblin import globals as mg_globals
|
from mediagoblin import globals as mg_globals
|
||||||
|
@ -19,9 +19,7 @@
|
|||||||
|
|
||||||
{% block mediagoblin_content %}
|
{% block mediagoblin_content %}
|
||||||
|
|
||||||
<h2>Welcome to GNU MediaGoblin!</h2>
|
<h2>{% trans %}Welcome to GNU MediaGoblin!{% endtrans %}</h2>
|
||||||
{# <!-- THE FUTURE -->
|
|
||||||
<h2>{% trans %}Welcome to GNU MediaGoblin!{% endtrans %}</h2> #}
|
|
||||||
|
|
||||||
{% if request.user %}
|
{% if request.user %}
|
||||||
<p>
|
<p>
|
||||||
|
BIN
mediagoblin/translations/en/LC_MESSAGES/mediagoblin.mo
Normal file
BIN
mediagoblin/translations/en/LC_MESSAGES/mediagoblin.mo
Normal file
Binary file not shown.
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PROJECT VERSION\n"
|
"Project-Id-Version: PROJECT VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -17,7 +17,7 @@ msgstr ""
|
|||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"Generated-By: Babel 0.9.6\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!"
|
msgid "Welcome to GNU MediaGoblin!"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from email.MIMEText import MIMEText
|
from email.MIMEText import MIMEText
|
||||||
|
import gettext
|
||||||
|
import pkg_resources
|
||||||
import smtplib
|
import smtplib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -56,10 +58,18 @@ def get_jinja_env(template_loader, locale):
|
|||||||
(In the future we may have another system for providing theming;
|
(In the future we may have another system for providing theming;
|
||||||
for now this is good enough.)
|
for now this is good enough.)
|
||||||
"""
|
"""
|
||||||
return jinja2.Environment(
|
setup_gettext(locale)
|
||||||
|
|
||||||
|
template_env = jinja2.Environment(
|
||||||
loader=template_loader, autoescape=True,
|
loader=template_loader, autoescape=True,
|
||||||
extensions=['jinja2.ext.i18n'])
|
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):
|
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):
|
def locale_to_lower_upper(locale):
|
||||||
"""
|
"""
|
||||||
Take a locale, regardless of style, and format it like "en-us"
|
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'
|
target_lang = 'en'
|
||||||
|
|
||||||
return locale_to_lower_upper(target_lang)
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user