View previous topic :: View next topic |
Author |
Message |
brice Smarty Rookie
Joined: 14 Apr 2006 Posts: 11
|
Posted: Sun Apr 16, 2006 8:40 am Post subject: translation of error messages |
|
|
I'm using gettext,php gettext, and smarty-gettext to handle i18n of a project...
I've just switched over to Smarty and am learning the ropes. I really like this class & plan on using it (+ perhaps one day popping the hood to add drop in client side JS validation).
Anway, I came across one hitch; Translating the text of an error message. Translation occurs (calls gettext function(s) on text between the {t}{/t} block.
Here's an example:
<div class="error">{validate id="email" message="{t}Invalid email address{/t}"}</div>
Results in:
Fatal error: Smarty error: [in user/login.tpl line 21]: syntax error: mismatched tag {/t}. (Smarty_Compiler.class.php, line 2286) ..
Can anyone suggest a workaround? |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Sun Apr 16, 2006 3:52 pm Post subject: |
|
|
its not allowed to nest smarty tags
you have to save it in a temp var |
|
Back to top |
|
brice Smarty Rookie
Joined: 14 Apr 2006 Posts: 11
|
Posted: Sun Apr 16, 2006 6:28 pm Post subject: |
|
|
can I assign temp vars in the template file (so the error message remains in designer view)? it's too bad because there's no way to around this w/o adding much clutter
~ Brice |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Apr 16, 2006 8:03 pm Post subject: |
|
|
maybe something like this:
Code: | {validate id="email" message="Invalid email address" assign="error"}
{t}{$error}{/t} |
|
|
Back to top |
|
brice Smarty Rookie
Joined: 14 Apr 2006 Posts: 11
|
Posted: Sun Apr 16, 2006 9:28 pm Post subject: |
|
|
Monte,
That solution is certainly the most elegant... however, I believe the translators would see "{$error}" as the text to translate rather than "Invalid email address" due to the way gettext / smartygettext pulls strings to be translated from files?
I've opted to assign the error message from the PHP parent script, and if a user want's to customize the error message, they can easily do it in their own language w/o the need for the translation function.
Here's my code (which I have no idea of its quality...)
Parent PHP: _T() is the translation function
Code: | if (empty ($_POST)) {
//____ FORM NOT SUBMITTED ____
$formError = array();
SmartyValidate :: connect($smarty, true);
SmartyValidate :: register_validator('email', 'Email', 'isEmail', false, false, 'trim');
$formError['email'] = _T('Invalid email address');
$smarty->assign('formError',$formError);
$smarty->display('user/login.tpl');
} else {
|
Template: Code: |
<form action="" method="POST">
<fieldset>
<legend>{t}Login{/t}</legend>
<div class="field">
<div class="error">{validate id="email" message=$formError.email}</div>
<label for="Email"><span class="required">{t}Your Email:{/t} </span></label>
<input type="text" class="text" size="32" maxlength="60"
name="Email" value="{$Email|escape}" id="email" />
<input style="margin-left: 30px;" type="submit" value="{t}Login{/t}" />
</div>
</fieldset>
</form>
|
PS -> Thanks for your dedication!! |
|
Back to top |
|
brice Smarty Rookie
Joined: 14 Apr 2006 Posts: 11
|
Posted: Tue Apr 18, 2006 2:02 am Post subject: documentation type |
|
|
typo @ documentation:
line 827 -> SmartyValidate::register_validator('v_username','username:!^\w+$!','isLength');
should read
SmartyValidate::register_validator('v_username','username:!^\w+$!','isRegExp');
? |
|
Back to top |
|
brice Smarty Rookie
Joined: 14 Apr 2006 Posts: 11
|
Posted: Thu May 04, 2006 11:23 pm Post subject: Cannot have an option isEqual field? |
|
|
I've struggled to have an optional isEqual field. For instance;
I have a form listing a user's information, along with two password fields. If the user types the same password in both fields, the password will be changed upon a valid form submittal. If the fields are left blank, the password will not be changed.
The form never registers as valid if the passwords are left blank -- even though a dump of the SmartyValidate object shows that the field passed validation!
Here's the validator's I've tried;
Code: |
1)
SmartyValidate :: register_validator('admin_password2', 'admin_password2:admin_password', 'isEqual',TRUE);
2)
SmartyValidate :: register_validator('admin_password', 'admin_password:admin_password2', 'isEqual',TRUE);
SmartyValidate :: register_validator('admin_password2', 'admin_password2:admin_password', 'isEqual',TRUE);
3)
SmartyValidate :: register_validator('admin_password', 'admin_password', 'dummyValid');
SmartyValidate :: register_validator('admin_password2', 'admin_password2:admin_password', 'isEqual',TRUE);
|
form fields are text input.
Will I have to find a workaround? |
|
Back to top |
|
OpenMacNews Smarty Rookie
Joined: 03 Aug 2004 Posts: 34 Location: Floating on Io's Methane Seas ...
|
Posted: Thu May 11, 2006 6:27 am Post subject: SmartyValidate & ZF? |
|
|
hi all.
as i keep pluggin along with Zend Framework, next step is validation.
i understand that there *is* a Zend_Validate class 'proposal' somewhere out ther (not holding my breath ...), and SmartyValidate is *here* & working great now.
that said, has anyone thought about the integration of SmartyValidate + ZF?
the two obvious approaches include either ignoring the ZF as much as possible, and simply using SmartyValidate within the smarty tpl context, and/or extending a Zend class for tighter integration.
Currently, i've taken the extend Zend_View class for integrating Smarty templating; working fine so far. so, my first inclination is to do the same with Validate ... altho, it's kinad moot until it actually exists!
nonetheless, i'd be interested in folks' thoughts on ZF + validate ...
cheers,
richard |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Mon Jun 26, 2006 8:41 am Post subject: |
|
|
Hi monte,
is it the intended behavior that isValid returns false if no validator is registered?
Bye,
Markus |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Fri Jun 30, 2006 6:53 am Post subject: |
|
|
anyone? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Jun 30, 2006 7:22 pm Post subject: |
|
|
@kills: I wouldn't think that was intended but it is an interesting corner case. If there are no validators registered, why is SmartyValidate being loaded/used at all? |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Wed Jul 05, 2006 10:11 am Post subject: |
|
|
Hi boots,
Maybe you are right.
I`m using SmartyValidate in an non-smarty env with a full-automated validation system and so I am not sure if I have to handle this problem with my framework, or is it only a bug in SmartyValidate itself...
It would be a complex task to if-case this situation through the whole framework and thats the reason why I post here in the forums.
Maybe its a bug, but if not, I will fix it in the framework..
Thanks,
Markus |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 05, 2006 3:11 pm Post subject: |
|
|
Hi Kills.
Although I think it is rare case, I do agree that it is probably a case that should be handled. I would fix it myself, but I haven't looked at the code in quite a while. Maybe Monte is following this thread ... if not, send me a patch and I will try to remember my cvs password |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jul 05, 2006 4:43 pm Post subject: |
|
|
kills wrote: | Hi monte,
is it the intended behavior that isValid returns false if no validator is registered?
Bye,
Markus |
More likely an oversight. If you don't register a validator, then why load the class at all? |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Fri Jul 07, 2006 3:26 pm Post subject: |
|
|
Hi,
i subclassed the SmartyValidate Class und handeled it this way
Bye,
Markus |
|
Back to top |
|
|