In some places, we need to access the database, public_store, queue_store
"""
+import gettext
+import pkg_resources
+
#############################
# General mediagoblin globals
#############################
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
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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"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 ""
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from email.MIMEText import MIMEText
+import gettext
+import pkg_resources
import smtplib
import sys
(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):
"""
###################
+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"
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)