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 ...@@ -26,8 +26,6 @@ from DocumentTemplate.DT_String import String
from .patches import get_request from .patches import get_request
from . import Localizer, MessageCatalog from . import Localizer, MessageCatalog
from .LocalFiles import LocalDTMLFile from .LocalFiles import LocalDTMLFile
from .GettextTag import GettextTag
misc_ = {'arrow_left': ImageFile('img/arrow_left.gif', globals()), misc_ = {'arrow_left': ImageFile('img/arrow_left.gif', globals()),
...@@ -69,5 +67,3 @@ def initialize(context): ...@@ -69,5 +67,3 @@ def initialize(context):
context.registerHelp() context.registerHelp()
# Register the dtml-gettext tag
String.commands['gettext'] = GettextTag
...@@ -47,44 +47,6 @@ The parameters are: ...@@ -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 Zope Page Templates
------------------- -------------------
......
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
<fieldset><legend><dtml-var "gettext('Add language')"></legend> <fieldset><legend><dtml-var "gettext('Add language')"></legend>
<p class="form-help"> <p class="form-help">
<dtml-gettext>
To add a language select it and click the <tt>Add</tt> button. To add a language select it and click the <tt>Add</tt> button.
</dtml-gettext>
</p> </p>
<dtml-let languages=get_languages> <dtml-let languages=get_languages>
...@@ -34,9 +32,7 @@ ...@@ -34,9 +32,7 @@
<dtml-let languages=get_languages_mapping> <dtml-let languages=get_languages_mapping>
<dtml-if languages> <dtml-if languages>
<p class="form-help"> <p class="form-help">
<dtml-gettext>
To delete a language check it and click the <tt>Delete</tt> button. To delete a language check it and click the <tt>Delete</tt> button.
</dtml-gettext>
</p> </p>
<form action="<dtml-var URL1>" method="post"> <form action="<dtml-var URL1>" method="post">
...@@ -62,7 +58,7 @@ ...@@ -62,7 +58,7 @@
</table> </table>
</form> </form>
<dtml-else> <dtml-else>
<em><dtml-gettext>There are no languages</dtml-gettext></em> <em>There are no languages</em>
</dtml-if> </dtml-if>
</dtml-let> </dtml-let>
</fieldset> </fieldset>
...@@ -72,10 +68,8 @@ ...@@ -72,10 +68,8 @@
<table> <table>
<tr> <tr>
<td> <td>
<dtml-gettext>
To change the default language select it and click the To change the default language select it and click the
<tt>Change</tt> button. <tt>Change</tt> button.
</dtml-gettext>
</td> </td>
</tr> </tr>
<tr> <tr>
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
<dtml-if need_upgrade> <dtml-if need_upgrade>
<p class="form-help"> <p class="form-help">
<dtml-gettext>
This object must be upgraded. This object must be upgraded.
</dtml-gettext>
</p> </p>
<blockquote> <blockquote>
...@@ -17,9 +15,7 @@ ...@@ -17,9 +15,7 @@
<dtml-else> <dtml-else>
<p class="form-help"> <p class="form-help">
<dtml-gettext>
This object is up-to-date. This object is up-to-date.
</dtml-gettext>
</p> </p>
</dtml-if> </dtml-if>
......
...@@ -9,11 +9,9 @@ ...@@ -9,11 +9,9 @@
<p class="form-help"> <p class="form-help">
<dtml-gettext>
A Localizer object lets you customize the language negotiation policy. A Localizer object lets you customize the language negotiation policy.
It lets you use cookies, the path or any other criteria to select the It lets you use cookies, the path or any other criteria to select the
user preferred language. user preferred language.
</dtml-gettext>
</p> </p>
......
...@@ -2,13 +2,11 @@ ...@@ -2,13 +2,11 @@
<dtml-var manage_tabs> <dtml-var manage_tabs>
<p class="form-help"> <p class="form-help">
<dtml-gettext>
Locale folders are useful to store special multilingual objects like Locale folders are useful to store special multilingual objects like
images and specific logic. If used the <tt>Localizer</tt> object will 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 transparently add the right locale folder to the url. If you want to
use locale folders check the checkbox, otherwise uncheck it, then click use locale folders check the checkbox, otherwise uncheck it, then click
the <tt>Change</tt> button. the <tt>Change</tt> button.
</dtml-gettext>
</p> </p>
......
...@@ -3,13 +3,11 @@ ...@@ -3,13 +3,11 @@
<fieldset><legend><dtml-var "gettext('Export messages to PO file')"></legend> <fieldset><legend><dtml-var "gettext('Export messages to PO file')"></legend>
<p class="form-help"> <p class="form-help">
<dtml-gettext>
You can export the messages and their translations to PO files. Check You can export the messages and their translations to PO files. Check
<tt>locale.pot</tt> to get only the messages, without their translations. <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 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> translations to the selected language. Then click the <tt>Export</tt>
button. button.
</dtml-gettext>
</p> </p>
<form action="manage_export" method="post"> <form action="manage_export" method="post">
......
...@@ -3,11 +3,9 @@ ...@@ -3,11 +3,9 @@
<fieldset><legend><dtml-var "gettext('Import translations from PO file')"></legend> <fieldset><legend><dtml-var "gettext('Import translations from PO file')"></legend>
<p class="form-help"> <p class="form-help">
<dtml-gettext>
You can add new messages and translations importing a PO file. Enter the You can add new messages and translations importing a PO file. Enter the
filename, select the language of the translations and click the filename, select the language of the translations and click the
<tt>Import</tt> button. <tt>Import</tt> button.
</dtml-gettext>
</p> </p>
......
...@@ -10,12 +10,10 @@ ...@@ -10,12 +10,10 @@
<p class="form-help"> <p class="form-help">
<dtml-gettext>
A message catalog stores messages and its translations to different A message catalog stores messages and its translations to different
languages. It provides the <tt>gettext</tt> method to get the right languages. It provides the <tt>gettext</tt> method to get the right
translation for a given message. Message catalogs are useful to translation for a given message. Message catalogs are useful to
translate the application interfaces (labels, buttons, etc..). translate the application interfaces (labels, buttons, etc..).
</dtml-gettext>
</p> </p>
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
value=" <dtml-var "gettext('Delete')"> "> value=" <dtml-var "gettext('Delete')"> ">
</form> </form>
<dtml-else> <dtml-else>
<dtml-gettext>There are no messages.</dtml-gettext> There are no messages.
<br> <br>
<dtml-in languages mapping> <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> <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 @@ ...@@ -93,7 +93,7 @@
</dtml-in> </dtml-in>
</table> </table>
<dtml-else> <dtml-else>
<dtml-gettext>There are no messages.</dtml-gettext> There are no messages.
</dtml-if> </dtml-if>
</fieldset> </fieldset>
</td> </td>
...@@ -103,8 +103,8 @@ ...@@ -103,8 +103,8 @@
<!-- EMPTY --> <!-- EMPTY -->
<dtml-else> <dtml-else>
<p> <p>
<dtml-gettext>No languages available, please add them using the No languages available, please add them using the
<a href='manage_languages'>Languages</a> tab</dtml-gettext> <a href='manage_languages'>Languages</a> tab
</p> </p>
</dtml-if> </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