Domanda

Currently I am working with Smarty and been busy with translations.

I am using the config files for translation, but I cannot find a way to collect all the vars that are not in my config file. When I don't have the translation in my config file, the output is blank.

My config files look like:

register = "Registreren"
username = "Gebruikersnaam"
password = "Wachtwoord"
login = "Inloggen"

In PHP I use:

$this->smarty = new Smarty();
$this->smarty->configLoad(THEME_DIR . "/translations/nl.conf");
$this->translations = $this->smarty->getConfigVars();

echo $this->translations["username"]; // output: Gebruikersnaam

I can use in my HTML:

{#password#}
{#username#}
{#password#}
{#login#}

But when I want to output a not yet translated var like this:

{#logout#}

My result is blank.

Does anyone know how to use a default function when this occurs? Or maybe add the not found var to my config file? Or at least, show the var name instead of nothing.

È stato utile?

Soluzione

There is a way that doesn't need resorting to |default for each of your variables, but it requires a little change in one of the core files.

on line 340 of smarty/sysplugins/smarty_internal_data.php

replace

return null

by

return "#$variable#";

After this, all vars not defined int he conf file will appear as #name# (i.e. this is your #password#).

If for some reason you want a variable to be empty, just define it in the conf file as

variable = ""

Altri suggerimenti

The only way I found was this:

{#foo#|default:'foo'}

setting a default, if the variable is empty it will display that string.

http://www.smarty.net/docsv2/en/tips.tpl

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top