raintpl3 icon indicating copy to clipboard operation
raintpl3 copied to clipboard

Bug: Not working strings with modifiers

Open keskad opened this issue 11 years ago • 19 comments

Hello.

I'm moving from Smarty then from Dwoo template system to RainTPL and in my projects there is a syntax i cant find in RainTPL.

Its a string syntax used to translate applications based on my framework: {"This is a test"|localize} and {"This is a test"|localize:mydomain}

(Example: https://github.com/webnull/panthera/blob/master/lib/templates/admin/templates/plugins.tpl)

Can i try to implement this feature to RainTPL?

@edit Updated title

keskad avatar Jul 05 '13 08:07 keskad

In RainTPL 3 you can modifiers on strings, you only need to create your own modifier: http://www.raintpl.com/Documentation/Documentation-for-web-designers/RainTPL-Tags/_variable_modifiers/

feulf avatar Jul 05 '13 15:07 feulf

Ohh... im using RainTPL 3 and eg. {"This is a test"|localize} is not working for me... why? It's because i didnt register localize modifier?

keskad avatar Jul 05 '13 15:07 keskad

So... im marking this as bug because i pasted examples from RainTPL tutorial - "{"Hello I am a string"|uppercase|substr:0,4}" and it didnt work for me.

keskad avatar Jul 05 '13 15:07 keskad

That functionality got eventually broke on some update. I don't know if makes sense on RainTPL 3 now, but on any next version we'll start writing Unit Test together with the code!!!

Lack of test is the biggest mistake we ever made in this project.

feulf avatar Jul 05 '13 17:07 feulf

Okey, i can help you with Unit Test (i must implement it in my framework too, its a new project, recently released without documentation etc.) and we can also add phpDocumentor documentation.

I really need this bug to be fixed at now, but i dont know where to look for. Can you point me a little bit?

keskad avatar Jul 05 '13 17:07 keskad

I'll check the bug now. In the meaning time, if you need to solve the problem quickly you can assign the string to a variable and then use the modifier:

{$var="string"}
{$var|your_modifier}

feulf avatar Jul 05 '13 18:07 feulf

This is impossible to assing variable to string. I have over 50 template files with string modifiers and i dont have possibility to assing those strings, because they are only in template, not in code.

Im now trying to implement a filter, but i really hate PCRE. I dont know how to exclude a character from a string.

Im testing it in Python:

>>> re.findall('{"([^}"]+)"|([a-zA-Z]+)}', '{"aaa"|localize}{"bbb"|localize}')
[('aaa', ''), ('', 'localize'), ('bbb', ''), ('', 'localize')]

I spent two hours on it... how to group it?

I need result like [aaa, localize], [bbb, localize], this is sick.

keskad avatar Jul 05 '13 18:07 keskad

the string replace was implemented at a certain point or it was implemented in RainTPL 2 I can't remember exactly because in RainTPL 3 for stuff like that I usually create my own tags, such as {@string@}.

I'll see if I can fix your problem tomorrow, today I can't.

feulf avatar Jul 05 '13 19:07 feulf

Okey. Currently im working on a converter Smarty/Dwoo -> RainTPL. I will convert all my {"aaa"|localize} to {function="localize('aaa')"} and also if, elseif, foreach syntax etc. I can publish the converter, its very simple based on regexp and written in Python.

keskad avatar Jul 05 '13 19:07 keskad

that could be nice, thanks.

On Fri, Jul 5, 2013 at 3:36 PM, Damian Kęska [email protected]:

Okey. Currently im working on a converter Smarty/Dwoo -> RainTPL. I will convert all my {"aaa"|localize} to {function="localize('aaa')"} and also if, elseif, foreach syntax etc. I can publish the converter, its very simple based on regexp and written in Python.

— Reply to this email directly or view it on GitHubhttps://github.com/rainphp/raintpl3/issues/80#issuecomment-20535523 .

feulf avatar Jul 05 '13 19:07 feulf

https://gist.github.com/webnull/5937481

I spent about 5 hours to make it working. I hate regular expressions. It's a really very simple converter and it just fits my project needs at this moment. Maybe some people can improve it to make it fits all people needs.

keskad avatar Jul 05 '13 21:07 keskad

Any informations? I can help, but i dont know how. This thing is too complicated for me, i tried to find any footprint of this feature but no luck. My own implementation sucked because im bad at regular expressions - i understand only basic regexp.

keskad avatar Jul 28 '13 19:07 keskad

Let's keep this issue open. modifier on strings can be really useful.

feulf avatar Aug 02 '13 22:08 feulf

Yes, thats right... this is a feature i really need.

keskad avatar Aug 03 '13 14:08 keskad

this is still pending, I'll work on it these days

feulf avatar Aug 25 '13 14:08 feulf

This is good for i18n

kargnas avatar Aug 25 '13 15:08 kargnas

Thank you. I tried to work on it but it was too complex for me, sorry. So I'm still waiting for a fix from you @rainphp.

Yeah @kargnas, thats good for i18n, I was using it in my whole project but i had to convert everything to {function="localize()"} tags which looks really bad.

keskad avatar Aug 26 '13 11:08 keskad

sure, I'll work on it.

@webnull if you need an i18n tag you can create one with register_tag, in example_all.php there's an example for it that uses the following syntax:

{@your message here@}

feulf avatar Aug 26 '13 11:08 feulf

@rainphp I have language and domains in my translation system (yes i used gettext but now im using serialized arrays with memory cache support) and i have to pass a domain name in PHP im doing it in a simple way as a second argument to localize function - "localize('This is a string to be translated', 'domainName')"

I will wait for strings modifiers i dont want any temporary solutions anymore. After it i will write a converter and convert my code from {function="localize(...)"} back to string modifiers :)

Also have you think about a function tag like {var_dump(...)}? This should not be slow because function checks should be done on compilation time.

keskad avatar Aug 26 '13 12:08 keskad