Re: [PHPTAL] Chaining i18n:translate

2009-11-02 Thread Kornel LesiƄski

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
passwordLogin 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=fnBob/span

you'd want it output as:

Hello lt;span class=fnBob/spangt;

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;fnquot;gt;Boblt;/spangt;gt;


--
regards, Kornel

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


[PHPTAL] Chaining i18n:translate

2009-10-31 Thread Daniel Trebbien
Hello all,

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
passwordLogin 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.
(Is it just me, or shouldn't the second argument to
TranslationService::translate be deprecated?)

Feel free to try out the patches (license: Public Domain) and let me
know what you think.

Sincerely,

Daniel Trebbien.


Content.php.diff
Description: Binary data


Translate.php.diff
Description: Binary data
___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal