View previous topic :: View next topic |
Author |
Message |
smisonline2 Smarty Rookie
Joined: 12 Mar 2014 Posts: 7
|
Posted: Mon May 19, 2014 11:09 am Post subject: Sprache dynamisch? |
|
|
Hallo,
aktuell lade ich eine Sprachdatei so
{config_load file='lang/de.lang.conf' section='home'}
Ich möchet nun aber diese dynamisch laden, also
{config_load file='lang/en.lang.conf' section='home'}
{config_load file='lang/ch.lang.conf' section='home'}
je nach Aufruf
Wie kann ich das machen?
Mit einer Varialezuordnung und Aufruf via
{config_load file='lang/{$lang}.lang.conf' section='home'}
scheint es nicht zu funktionieren
Danke für Eure Hilfe. |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Mon May 19, 2014 1:20 pm Post subject: |
|
|
Versuch es mal ohne die geschweiften Klammern, also so:
Code: | {config_load file=lang/$lang.lang.conf section='home'} |
bzw. das wird wahrscheinlich nicht funktionieren, wegen den punkten, aber dann mach mal einen test, dass du in die $lang-Variable z. B. "de.lang.conf" schreibst und dann so den aufruf machst:
Code: | {config_load file=lang/$lang section='home'} |
|
|
Back to top |
|
smisonline2 Smarty Rookie
Joined: 12 Mar 2014 Posts: 7
|
Posted: Mon May 19, 2014 2:28 pm Post subject: Language |
|
|
Hallo,,
wirft beides einen Fehler:
Code: | Fatal error: Uncaught --> Smarty: Unable to read config file 'lang/$lang' <-- thrown in /home/external/Smarty/libs/sysplugins/smarty_internal_resource_file.php on line 68 |
Mein Aufruf sieht aktuell so aus;
Code: | class smarty_setup extends Smarty {
public function __construct() {
parent::__construct();
//$this->Smarty();
$this->setTemplateDir(LOCAL_SMARTY_TEMPLATE);
$this->setCompileDir(LOCAL_SMARTY_TEMPLATE_C);
$this->setConfigDir(LOCAL_SMARTY_CONFIGS);
$this->setCacheDir(LOCAL_SMARTY_CACHE);
$this->caching = SMARTY_CACHE;
$this->cache_lifetime = SMYRTY_CACHE_LIFETIME;
$this->assign('app_name',PROJEKTNAME);
// Dynamisieren!!
$this->assign('lang','de.lang.conf');
}
} |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon May 19, 2014 6:25 pm Post subject: |
|
|
Code: | {config_load file="lang/$lang.lang.conf" section='home'} |
|
|
Back to top |
|
smisonline2 Smarty Rookie
Joined: 12 Mar 2014 Posts: 7
|
Posted: Thu May 22, 2014 9:44 am Post subject: Languag |
|
|
OK, danke, jetzt klappt es:) |
|
Back to top |
|
Chrissio Smarty Rookie
Joined: 07 Oct 2014 Posts: 10
|
Posted: Tue Oct 07, 2014 9:01 pm Post subject: Sprachumschaltung - Sprache kommt aus MYSQL-Datenbank |
|
|
Hallo,
zu diesem Thema habe ich eine Frage.
In einer Datenbanktabelle steht die englische Sprache in einem Feld "description_english", die deutsche Sprache im Feld "description_german".
Im zugehörigen Template wird folgendes übergeben:
Code: | {foreach $confdata as $item}
<tr >
<td id="row_{$item.config_variable}_col1" >{$item.description_|stripslashes}</td>
...
</tr>
{/foreach} |
Um nun eine Anzeige der gewünschten Sprache zu erhalten, muss ich folgendes übergeben:
Code: | <td id="row_{$item.config_variable}_col1" >{$item.description_english|stripslashes}</td> |
für die englische Sprache oder
Code: | <td id="row_{$item.config_variable}_col1" >{$item.description_german|stripslashes}</td> | für die deutsche Sprache.
Dieser Wert ist in der Variablen $language korrekt hinterlegt und wird mit
auch als Text im Browserfenster angezeigt
Wie kann ich nun innerhalb des Arrays(?)
Code: | <td id="row_{$item.config_variable}_col1" >{$item.description_|stripslashes}</td> | die Variable $language übergeben?
Alle bisherigen Versuche wie z.B
Code: | <td id="row_{$item.config_variable}_col1" >{$item.description_[$language]|stripslashes}</td> |
schlugen fehl.
Was mache ich falsch?
Danke für Tips, ich verwende Smarty Version 3.1.19 |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Oct 07, 2014 10:19 pm Post subject: |
|
|
Verwende das PHP Array Format und dann Variablen in double quoted strings
Code: | {$item["description_$language"]} |
|
|
Back to top |
|
Chrissio Smarty Rookie
Joined: 07 Oct 2014 Posts: 10
|
Posted: Wed Oct 08, 2014 5:34 pm Post subject: |
|
|
U.Tews wrote: | Verwende das PHP Array Format und dann Variablen in double quoted strings
Code: | {$item["description_$language"]} |
|
Danke für den Tip - vom Prinzip her funktioniert das so.
Freundliche Grüße
Christian |
|
Back to top |
|
|