On 31-10-2009 at 18:49:16 Daniel Trebbien <dtrebb...@gmail.com> wrote:

A long time ago I modified two, PHPTAL 1.1.16 library files to allow
expression chaining in i18n:translate. This allowed, for example:
<div class="error" i18n:translate="error | string:Invalid username or
password">Login error</div>
which means: translate the value of the error variable if that
variable is set, or translate the string "Invalid username or
password". The patches worked really well for PHPTAL 1.1.16, and were
quite useful is certain scenarios, so I decided to try and migrate the
changes to 1.2.0.

Attached are unified diffs (from v. 1.2.0) for the two files needing
modification: `PHPTAL/Php/Attribute/I18N/Translate.php` and
`PHPTAL/Php/Attribute/TAL/Content.php`. Basically, I tried to make the
same changes as before, but I noticed the new escape vs. stringify
feature, so I additionally incorporated changes in support of that.

Thanks!

I've had to fix one thing: it broke support for i18n:name. Other than that it works OK and will be part of next release.

(Is it just me, or shouldn't the second argument to
TranslationService::translate be deprecated?)

Unfortunately not.

The problem is that interpolated variables may need to contain XHTML markup.


If you've got translation key:

"Hello <${name}>"

and ${name} is: <span class="fn">Bob</span>

you'd want it output as:

"Hello &lt;<span class="fn">Bob</span>&gt;"

So you need to escape text after it has been translated, but before variables are replaced. Simply escaping everything will give undesirable result:

"Hello &lt;&lt;span class=&quot;fn&quot;&gt;Bob&lt;/span&gt;&gt;"


--
regards, Kornel

_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to