translation translation [continued]
| From: | Michal Prinke | Date: | Fri, 12 Apr 2002 09:23:02 +0000 |
| Subject: | translation translation [continued] | ||
| References: | 1 2 3 4 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3660@lists.php.net to get a copy of this message | ||
Monte Ohrt wrote:
> There is no translation function. This is an example of block function
> syntax:
>
> {myfunc}
>
> {/myfunc}
>
> My point was, you can _create_ a translation function with the block
> funtionality of Smarty.
Okay, can you help with this? I think it shouldn't be too complicated...
1. In the PHP script, I have to assign a template variable containing
the current language:
$sm = new Smarty();
$sm->assign("lg", "en"); // English language
$sm->display("index.tpl");
2. Then, I should include some translations in my template:
<html><body>
{translate lg="en"}
Hello world!
{/translate}
{translate lg="fr"}
Bonjour tout le monde!
{/translate}
</body></html>
3. So, the block function "translate" has a very uncomplicated logic -
it should simply print the content between the tags
if its "lg" parameter matches the "lg" variable set from the outside:
function smarty_function_translate($params, &$smarty) {
$tpl_vars = $smarty->get_template_vars();
if ($params['lg'] == $tpl_vars['lg'])
echo($the_content_between_the_tags); // ???
else
discard_the_content_between_the_tags(); // ???
}
*** FINALLY, MY QUESTIONS ARE: ***
How to write block functions? That is, how to operate on the content
between the opening and the closing tag? How to print it out and how
to omit it? How to implement the lines marked with "???" ?
Thank you...