Kornel Lesiński | 2 Nov 2009 12:50
Picon
Favicon
Gravatar

Re: Chaining i18n:translate

On 31-10-2009 at 18:49:16 Daniel Trebbien <dtrebbien@...> 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.
(Continue reading)

Tobias Herp | 3 Nov 2009 18:56
Picon

Re: Escaping of dollar sign ($)

Kornel Lesiński wrote:
> I could change it to:
> 
> ${x} → value
> $${x} → ${x}
> $$${x} → $value
> $$$${x} → $${x}
> $$$$${x} → $$value
> $$$$$${x} → $$${x}
> etc.

Yes, please!

This is logical, and it is the behaviour defined by the TALES standard (http://wiki.zope.org/ZPT/TALESSpecification13#required_type_prefixes).
The current behaviour is a *bug* and should be fixed.

It's ok to add features to ZPT (especially the definition of operators); but IMO it's /not/ ok to change the
meaning of existing syntax.

> However:
> 
> • Pre-filters may need to deal with this to (un)escape text properly.
> With simpler rules you can just replace ${ with $${ to escape text.
> It's not so easy when you need to observe even/odd number of $s.

Well, you can consume the text sequentially and change every $$ into $, and treat every ${ or $\w as the
beginning of a variable. Doesn't look very complicated to me.

Using regular expressions, you could look for $(.); if \1 is another $, you have a literal $, etc.  Anything
else but [${\w] should yield an error, of course!
(Continue reading)

Kornel Lesiński | 4 Nov 2009 10:54
Picon
Favicon
Gravatar

Re: Escaping of dollar sign ($)

On 03-11-2009 at 17:56:02 Tobias Herp <bruno-the-questionable@...>  
wrote:

> Kornel Lesiński wrote:
>> I could change it to:
>>
>> ${x} → value
>> $${x} → ${x}
>> $$${x} → $value
>> $$$${x} → $${x}
>> $$$$${x} → $$value
>> $$$$$${x} → $$${x}
>> etc.
>
> Yes, please!
>
> This is logical, and it is the behaviour defined by the TALES standard  
> (http://wiki.zope.org/ZPT/TALESSpecification13#required_type_prefixes).
> The current behaviour is a *bug* and should be fixed.

OK. That's a good point.

>> • Pre-filters may need to deal with this to (un)escape text properly.
>> With simpler rules you can just replace ${ with $${ to escape text.
>> It's not so easy when you need to observe even/odd number of $s.
>
> Well, you can consume the text sequentially and change every $$ into $,  
> and treat every ${ or $\w as the beginning of a variable. Doesn't look  
> very complicated to me.
>
(Continue reading)

Tjerk Meesters | 4 Nov 2009 11:22
Picon
Gravatar

Re: Escaping of dollar sign ($)

Would it be possible to use a preg_replace() with two expressions, one
to replace $$ by $ and one to handle \b${?(\w+)

2009/11/4 Kornel Lesiński <kornel@...>:
> On 03-11-2009 at 17:56:02 Tobias Herp <bruno-the-questionable@...>
> wrote:
>
>> Kornel Lesiński wrote:
>>>
>>> I could change it to:
>>>
>>> ${x} → value
>>> $${x} → ${x}
>>> $$${x} → $value
>>> $$$${x} → $${x}
>>> $$$$${x} → $$value
>>> $$$$$${x} → $$${x}
>>> etc.
>>
>> Yes, please!
>>
>> This is logical, and it is the behaviour defined by the TALES standard
>> (http://wiki.zope.org/ZPT/TALESSpecification13#required_type_prefixes).
>> The current behaviour is a *bug* and should be fixed.
>
> OK. That's a good point.
>
>>> • Pre-filters may need to deal with this to (un)escape text properly.
>>> With simpler rules you can just replace ${ with $${ to escape text.
>>> It's not so easy when you need to observe even/odd number of $s.
(Continue reading)

Kornel Lesiński | 4 Nov 2009 11:59
Picon
Favicon
Gravatar

Re: Escaping of dollar sign ($)

On 04-11-2009 at 10:22:56 Tjerk Meesters
<tjerk.meesters@...> wrote:

> Would it be possible to use a preg_replace() with two expressions, one
> to replace $$ by $ and one to handle \b${?(\w+)

You'd have to use assertions or other tricks, to avoid replacing unrelated  
"$$"s.

I think I'll just have to provide (un)escaping function for prefilters.

--

-- 
regards, Kornel
GRolf | 5 Nov 2009 17:04

custom modifier?


I was trying to achieve this:
- I have a div, with a tal:repeat="person persons", and I want to
compare the person/person_id to a "global" variable (i.e. unrelated to
"persons") "selectedperson"
- if person/person_id == selectedperson, I want to change the class of
my div

I guess I need a custom modifier for this, but I found the
documentation rather complicated.

Could anybody point me in the right direction?
GRolf | 5 Nov 2009 17:14

temp files ?


while experimenting, I noticed that PHPTal leaves a lot of cached
templates. Are those ever cleaned up?
Kornel Lesiński | 5 Nov 2009 17:21
Picon
Favicon
Gravatar

Re: custom modifier?

On 05-11-2009 at 16:04:50 GRolf <gerolf@...> wrote:

> I was trying to achieve this:
> - I have a div, with a tal:repeat="person persons", and I want to
> compare the person/person_id to a "global" variable (i.e. unrelated to
> "persons") "selectedperson"
> - if person/person_id == selectedperson, I want to change the class of
> my div
>
>
> I guess I need a custom modifier for this, but I found the
> documentation rather complicated.
>
>
> Could anybody point me in the right direction?

<div class="${php:person['person_id'] == selectedperson ? 'is-selected' :  
'not-selected'}">

or

<div tal:attributes="class php:person['person_id'] == selectedperson ?  
'is-selected' : NULL">

If person is an object, then use person.person_id instead.

Unfortunately you can't mix TALES (foo/bar/baz) with any operators (==).

You could write your own modifier though:

(Continue reading)

Kornel Lesiński | 5 Nov 2009 17:22
Picon
Favicon
Gravatar

Re: temp files ?

On 05-11-2009 at 16:14:58 GRolf <gerolf@...> wrote:

>
> while experimenting, I noticed that PHPTal leaves a lot of cached
> templates. Are those ever cleaned up?

Yes.

http://phptal.org/manual/en/split/configuration.html#set-cache-lifetime

--

-- 
regards, Kornel
Wallace McGee | 9 Nov 2009 00:08
Picon
Favicon

Re: Tepm file filetime

---8<--
setCacheLifetime(num_days)

Maximum number of days intermediate files and fragments cached with phptal:cache should be kept.
---8<--

What is the default (if any) or do we need to set this otherwise the temp files live forever?

The doco is not making this clear.

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

Gmane