Page MenuHomec4science

messages.py.wml
No OneTemporary

File Metadata

Created
Sun, Apr 28, 16:37

messages.py.wml

## $Id$
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#include "config.wml"
#include "cdswmllib.wml"
<protect>## -*- coding: utf-8 -*-</protect>
<protect>## $Id$
<protect>## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDS Invenio WML SOURCES.</protect>
"""CDS Invenio international messages functions, to be used by all I18N interfaces.
Typical usage in the caller code is:
from messages import gettext_set_language
[...]
def square(x, ln=cdslang):
_ = gettext_set_language(ln)
print _("Hello there!")
print _("The square of %s is %s.") % (x, x*x)
In the caller code, all output strings should be made translatable via
the _() convention.
For more information, see ABOUT-NLS file.
"""
import string
import sre
from invenio.config import localedir
import gettext
lang = {}
for ln in <: print generate_language_list_for_python(); :>:
lang[ln] = gettext.translation('cds-invenio', localedir, languages = [ln], fallback = True)
def gettext_set_language(ln):
"""
Set the _ gettext function in every caller function
Usage::
_ = gettext_set_language(ln)
"""
return lang[ln].gettext
def wash_language(ln):
"""Look at LN and check if it is one of allowed languages for the interface.
Return it in case of success, return the default language otherwise."""
if ln in <: print generate_language_list_for_python(); :>:
return ln
else:
return '<CDSLANG>'
def create_language_selection_box(urlargs="", language="en"):
"""Take URLARGS and LANGUAGE and return textual language
selection box for the given page."""
_ = gettext_set_language(language)
out = ""
for (lang, lang_namelong) in <: print generate_language_list_for_python("long"); :>:
if lang == language:
out += """ <span class="langinfo">%s</span> &nbsp; """ % lang_namelong
else:
if urlargs:
urlargs = sre.sub(r'ln=.*?(&|$)', '', urlargs)
if urlargs:
if urlargs.endswith('&'):
urlargs += "ln=%s" % lang
else:
urlargs += "&ln=%s" % lang
else:
urlargs = "ln=%s" % lang
out += """ <a class="langinfo" href="?%s">%s</a> &nbsp; """ % (urlargs, lang_namelong)
return _("This site is also available in the following languages:") + "<br>" + out
def language_list_long():
return <: print generate_language_list_for_python("long"); :>

Event Timeline