Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Sprache dynamisch?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
smisonline2
Smarty Rookie


Joined: 12 Mar 2014
Posts: 7

PostPosted: Mon May 19, 2014 11:09 am    Post subject: Sprache dynamisch? Reply with quote

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
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Mon May 19, 2014 1:20 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
smisonline2
Smarty Rookie


Joined: 12 Mar 2014
Posts: 7

PostPosted: Mon May 19, 2014 2:28 pm    Post subject: Language Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon May 19, 2014 6:25 pm    Post subject: Reply with quote

Code:
{config_load file="lang/$lang.lang.conf" section='home'}
Back to top
View user's profile Send private message
smisonline2
Smarty Rookie


Joined: 12 Mar 2014
Posts: 7

PostPosted: Thu May 22, 2014 9:44 am    Post subject: Languag Reply with quote

OK, danke, jetzt klappt es:)
Back to top
View user's profile Send private message
Chrissio
Smarty Rookie


Joined: 07 Oct 2014
Posts: 10

PostPosted: Tue Oct 07, 2014 9:01 pm    Post subject: Sprachumschaltung - Sprache kommt aus MYSQL-Datenbank Reply with quote

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

Code:
 {$language}


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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Oct 07, 2014 10:19 pm    Post subject: Reply with quote

Verwende das PHP Array Format und dann Variablen in double quoted strings

Code:
{$item["description_$language"]}
Back to top
View user's profile Send private message
Chrissio
Smarty Rookie


Joined: 07 Oct 2014
Posts: 10

PostPosted: Wed Oct 08, 2014 5:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP