Link to home
Start Free TrialLog in
Avatar of Matthew_Way
Matthew_Way

asked on

Smarty include paramater not translating

PHP 5.2.0, Apache 2.0, Smarty 2.6.18

I'm working on a multilingual PHP application, using the Smarty / Gettext extension (available on source forge).

The gettext extension works well and allows phrases within smarty templates to be translated.
for example;
<span> {t}Hello World{/t}</span>
becomes (in French)
<span>bonjour monde</span>

The problem is we have a number of custom functions and included templates we need to pass translated parameter text.
for example;
{include file="operations/include/contact_list.tpl" table_tile="{t}Company Contacts{/t}" }

generates this error;
Fatal error: Smarty error: [in operations/company/company_detail.tpl line 72]: syntax error: mismatched tag {/t}. (Smarty_Compiler.class.php, line 2300)

Any ideas on how to fix this?
Avatar of ahoffmann
ahoffmann
Flag of Germany image

sounds like you use unmatched {t} {/t} pairs (probably forgot to close on {t} }
Avatar of basiclife
basiclife

Not a user of Smarty myself so my help may be somewhat limited, but check the contents of the file you're including. You can see the table title tags are matched, but there may be other in the file that aren't?
mismatched {/t} means there is a {/t} somewhere without an opening {t}.
Avatar of Matthew_Way

ASKER

I know what the error message is trying to say....

But when I have a template with only a single line such as.

{include file="operations/include/contact_list.tpl" table_tile="{t}Company Contacts{/t}" }

I get the error.
Without the {t} , {/t} tags the included file works perfectly but without the translation.
You can't include Smarty tags inside a function parameter. Pass Company Contacts as is and apply {t}..{/t} in contact_list.tpl.
Problem with having {t}..{/t} in contact_list.tpl is that the translation file input would look like this within the PO translation file;
{$table_tile}

Rather than;
Company Contacts

I want table_title to represent the context of the include file...

The only other work around I can think of is to hide the translation on the main form and then copy the content over at run time with javascript.
But that's ugly and will confuse the template designers.

Some thing like this;
<span id="text_for_contact_list_title" style="display:none;">{t}Company Contacts{/t}</span>
{include file="operations/include/contact_list.tpl"}

Any other suggestions for a more elegant work around ?

Or should I look at hacking the smarty class to parse parameters ?

Something else I should point out as the solution needs to by MuliByte / utf8
As one of the target languages is Chinese.
ASKER CERTIFIED SOLUTION
Avatar of Matthew_Way
Matthew_Way

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad you were able to find a colution. Sorry I was absolutely no help whatsoever :)
Thanks for contributing any way.

Just need to work out how to use sourceforge CVS then I can upload my new files.

I'm sure other people out there are having the same issue.

Matt
No objection at all from me
Avatar of modus_operandi
Closed, 500 points refunded.
modus_operandi
EE Moderator