Commit ba8750a2 authored by Jérome Perrin's avatar Jérome Perrin

Localizer: drop support for dtml-gettext tag

This seems to be used only in Localizer's ZMI. This is not compatible
with newer version of DocumentTemplate, but because we don't use, it's
better to remove the functionality
parent 689e242c
Pipeline #20094 running with stage
# -*- coding: UTF-8 -*-
# Copyright (C) 2000-2002 Juan David Ibáñez Palomar <jdavid@itaapy.com>
#
# This program 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 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
"""
Localizer
Adds a new DTML tag:
<dtml-gettext [lang=<language>|lang_expr=<expression>] [verbatim] [catalog=<id>] [data=<expression>]>
...
</dtml-gettext>
"""
# Import from Zope
from DocumentTemplate.DT_Util import Eval, ParseError, parse_params, \
InstanceDict, namespace, render_blocks
# Auxiliar functions
def name_or_expr(mapping, name_attr, expr_attr, default):
name = mapping.get(name_attr, None)
expr = mapping.get(expr_attr, None)
if name is None:
if expr is None:
return default
return Eval(expr)
if expr is None:
return name
raise ParseError('%s and %s given' % (name_attr, expr_attr), 'calendar')
class GettextTag:
""" """
name = 'gettext'
blockContinuations = ()
def __init__(self, blocks):
tname, args, section = blocks[0]
self.section = section.blocks
args = parse_params(args, lang=None, lang_expr=None, verbatim=1,
catalog=None, data=None)
self.lang = name_or_expr(args, 'lang', 'lang_expr', None)
self.verbatim = args.get('', None) == 'verbatim' \
or args.get('verbatim', None)
self.catalog = args.get('catalog', None)
self.data = args.get('data', None)
if self.data is not None:
self.data = Eval(self.data)
def __call__(self, md):
# In which language, if any?
lang = self.lang
if lang is not None and type(lang) is not str:
lang = lang.eval(md)
# Get the message!!
ns = namespace(md)[0]
md._push(InstanceDict(ns, md))
message = render_blocks(self.section, md)
md._pop(1)
# Interpret the message as verbatim or not
if not self.verbatim:
message = ' '.join([ x.strip() for x in message.split() ])
# Search in a specific catalog
if self.catalog is None:
gettext = md.getitem('gettext', 0)
else:
gettext = md.getitem(self.catalog, 0).gettext
translation = gettext(message, lang)
# Variable substitution
if self.data is not None:
data = self.data.eval(md)
translation = translation % data
return translation
......@@ -26,8 +26,6 @@ from DocumentTemplate.DT_String import String
from .patches import get_request
from . import Localizer, MessageCatalog
from .LocalFiles import LocalDTMLFile
from .GettextTag import GettextTag
misc_ = {'arrow_left': ImageFile('img/arrow_left.gif', globals()),
......@@ -69,5 +67,3 @@ def initialize(context):
context.registerHelp()
# Register the dtml-gettext tag
String.commands['gettext'] = GettextTag
......@@ -47,44 +47,6 @@ The parameters are:
+----------+--------------------------------------+
dtml-gettext
------------
For long messages the tag dtml-gettext can be more comfortable::
<dtml-gettext>
This could be a very long message.
</dtml-gettext>
It accepts several parameters, they're:
+------------------------------+--------------------------------+
| lang [#msg-catalog-rq]_ | The target language (string). |
+------------------------------+--------------------------------+
| lang_expr [#msg-catalog-rq]_ | The target language (string |
| | expression). |
+------------------------------+--------------------------------+
| verbatim | If set the message will be |
| | interpreted as it is, |
| | otherwise (default) any blank |
| | characters will be interpreted |
| | as just one space character. |
+------------------------------+--------------------------------+
| catalog | The id of the catalog from |
| | where the translations will be |
| | obtained. |
+------------------------------+--------------------------------+
| data | If present the message will be |
| | interpreted as a formatted |
| | string and data will contain |
| | the tuple or dictionary to be |
| | passed to the string. |
+------------------------------+--------------------------------+
.. [#msg-catalog-rq] Only one (or none) can be provided.
Zope Page Templates
-------------------
......
......@@ -3,9 +3,7 @@
<fieldset><legend><dtml-var "gettext('Add language')"></legend>
<p class="form-help">
<dtml-gettext>
To add a language select it and click the <tt>Add</tt> button.
</dtml-gettext>
To add a language select it and click the <tt>Add</tt> button.
</p>
<dtml-let languages=get_languages>
......@@ -34,9 +32,7 @@
<dtml-let languages=get_languages_mapping>
<dtml-if languages>
<p class="form-help">
<dtml-gettext>
To delete a language check it and click the <tt>Delete</tt> button.
</dtml-gettext>
To delete a language check it and click the <tt>Delete</tt> button.
</p>
<form action="<dtml-var URL1>" method="post">
......@@ -62,7 +58,7 @@
</table>
</form>
<dtml-else>
<em><dtml-gettext>There are no languages</dtml-gettext></em>
<em>There are no languages</em>
</dtml-if>
</dtml-let>
</fieldset>
......@@ -72,10 +68,8 @@
<table>
<tr>
<td>
<dtml-gettext>
To change the default language select it and click the
<tt>Change</tt> button.
</dtml-gettext>
To change the default language select it and click the
<tt>Change</tt> button.
</td>
</tr>
<tr>
......
......@@ -4,9 +4,7 @@
<dtml-if need_upgrade>
<p class="form-help">
<dtml-gettext>
This object must be upgraded.
</dtml-gettext>
</p>
<blockquote>
......@@ -17,9 +15,7 @@
<dtml-else>
<p class="form-help">
<dtml-gettext>
This object is up-to-date.
</dtml-gettext>
This object is up-to-date.
</p>
</dtml-if>
......
......@@ -9,11 +9,9 @@
<p class="form-help">
<dtml-gettext>
A Localizer object lets you customize the language negotiation policy.
It lets you use cookies, the path or any other criteria to select the
user preferred language.
</dtml-gettext>
A Localizer object lets you customize the language negotiation policy.
It lets you use cookies, the path or any other criteria to select the
user preferred language.
</p>
......
......@@ -2,13 +2,11 @@
<dtml-var manage_tabs>
<p class="form-help">
<dtml-gettext>
Locale folders are useful to store special multilingual objects like
images and specific logic. If used the <tt>Localizer</tt> object will
transparently add the right locale folder to the url. If you want to
use locale folders check the checkbox, otherwise uncheck it, then click
the <tt>Change</tt> button.
</dtml-gettext>
Locale folders are useful to store special multilingual objects like
images and specific logic. If used the <tt>Localizer</tt> object will
transparently add the right locale folder to the url. If you want to
use locale folders check the checkbox, otherwise uncheck it, then click
the <tt>Change</tt> button.
</p>
......
......@@ -3,13 +3,11 @@
<fieldset><legend><dtml-var "gettext('Export messages to PO file')"></legend>
<p class="form-help">
<dtml-gettext>
You can export the messages and their translations to PO files. Check
<tt>locale.pot</tt> to get only the messages, without their translations.
Check any other option to get a PO file with the messages and their
translations to the selected language. Then click the <tt>Export</tt>
button.
</dtml-gettext>
You can export the messages and their translations to PO files. Check
<tt>locale.pot</tt> to get only the messages, without their translations.
Check any other option to get a PO file with the messages and their
translations to the selected language. Then click the <tt>Export</tt>
button.
</p>
<form action="manage_export" method="post">
......
......@@ -3,11 +3,9 @@
<fieldset><legend><dtml-var "gettext('Import translations from PO file')"></legend>
<p class="form-help">
<dtml-gettext>
You can add new messages and translations importing a PO file. Enter the
filename, select the language of the translations and click the
<tt>Import</tt> button.
</dtml-gettext>
You can add new messages and translations importing a PO file. Enter the
filename, select the language of the translations and click the
<tt>Import</tt> button.
</p>
......
......@@ -10,12 +10,10 @@
<p class="form-help">
<dtml-gettext>
A message catalog stores messages and its translations to different
languages. It provides the <tt>gettext</tt> method to get the right
translation for a given message. Message catalogs are useful to
translate the application interfaces (labels, buttons, etc..).
</dtml-gettext>
A message catalog stores messages and its translations to different
languages. It provides the <tt>gettext</tt> method to get the right
translation for a given message. Message catalogs are useful to
translate the application interfaces (labels, buttons, etc..).
</p>
......
......@@ -48,7 +48,7 @@
value=" <dtml-var "gettext('Delete')"> ">
</form>
<dtml-else>
<dtml-gettext>There are no messages.</dtml-gettext>
There are no messages.
<br>
<dtml-in languages mapping>
<a href="<dtml-var url>"><dtml-if "code == language"><span style="font-weight: bold"><dtml-var name></span><dtml-else><dtml-var name></dtml-if></a>
......@@ -93,7 +93,7 @@
</dtml-in>
</table>
<dtml-else>
<dtml-gettext>There are no messages.</dtml-gettext>
There are no messages.
</dtml-if>
</fieldset>
</td>
......@@ -103,8 +103,8 @@
<!-- EMPTY -->
<dtml-else>
<p>
<dtml-gettext>No languages available, please add them using the
<a href='manage_languages'>Languages</a> tab</dtml-gettext>
No languages available, please add them using the
<a href='manage_languages'>Languages</a> tab
</p>
</dtml-if>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment