Php – More descriptive Language String placeholder


<?LANG(no_download, 'you are not allowed to download')

instead of


I have what I think is a better approach for embedding language strings in templates.

In almost all the PHP applications, the predominant language placeholder format is like <?=$lang['no_download']?> or {{no_download}}. Other designers/developers/translators will have a hard time deciphering what the placeholders represent without referring to the language file.

In order to make language placeholders more descriptive, why don't we include the original string together with the placeholder?

<?=lang( 'no_download' , 'You are not allowed to download this file because you have exceeded your quota' )?>

The second parameter is a dummy and thus nothing is being done to it by the lang() function.

At a glance, one might think that it is too verbose, adding clutter to the template markup.
But in my opinion it is not a valid argument since the language string would've taken as much space as the placeholder if it weren't language aware.

I would like to hear your thoughts regarding this.

Best Solution

EDIT Didnt see this was tagged Smarty. Disregard my answer if you want a Smarty specific answer.

I wouldn't agree that there is a predominant placeholder format. In general, the format depends on how you handle the translations and that can vary.

Apart from that, it is not uncommon to provide the default language strings as translation labels. For instance, in the Zend Framework manual, this is part of their usage example. Nothing wrong with that if your translation adapter supports that. If it requires IDs, then it's not an option.

Personally, I prefer IDs and try to name them according to their usage in the application, e.g. form.label.login.username or cart.checkout or flashmessage.notice.

Using IDs also provides another layer of separation. Given that texting might not fall into the responsibility of either developer or template designer, it's better to have IDs in your templates.