Skip to content

Commit

Permalink
Minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Apr 4, 2024
1 parent c265cbd commit 5202150
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Changes

In next release ...

- Minor optimization when rendering translations with a static
message id (don't need to test if it's non-empty).

- Fix a bug where a macro could not be used correctly to render a
translation name.
(`#419 <https://github.com/malthe/chameleon/issues/419>`_)
Expand Down
11 changes: 9 additions & 2 deletions src/chameleon/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1492,13 +1492,20 @@ def visit_Translate(self, node):
msgid = ast.Str(s=node.msgid)

# emit the translation expression
body += template(
"if msgid: __append(translate("
translation = template(
"__append(translate("
"msgid, mapping=mapping, default=default, domain=__i18n_domain, context=__i18n_context, target_language=target_language))", # noqa: E501 line too long
msgid=msgid,
default=default,
mapping=mapping)

if not node.msgid:
translation = [ast.If(
test=load(msgid), body=translation, orelse=[]
)]

body += translation

# pop away translation block reference
self._translations.pop()

Expand Down

0 comments on commit 5202150

Please sign in to comment.