raintpl3
raintpl3 copied to clipboard
Bug: Not working strings with modifiers
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
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/
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?
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.
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.
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?
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}
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.
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.
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.
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 .
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.
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.
Let's keep this issue open. modifier on strings can be really useful.
Yes, thats right... this is a feature i really need.
this is still pending, I'll work on it these days
This is good for i18n
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.
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@}
@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.