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

Correct setting of languages with Smarty

 
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 -> General
View previous topic :: View next topic  
Author Message
toplisek
Smarty Regular


Joined: 17 Sep 2009
Posts: 48

PostPosted: Fri Mar 11, 2011 1:46 pm    Post subject: Correct setting of languages with Smarty Reply with quote

I have set the following for languages:

1.
Code:
$smarty->lang_dir = ROOT_DIR . "languages";


within file called smarty.inc.php

2. I have created folder called languages in root

in my root file I have config file with defined name file LANG_DIR

Code:

define('DS', DIRECTORY_SEPARATOR);
define('LANG_DIR', ROOT_DIR . 'languages' . DS);


3. In controller index PHP file I like to detect languages for german, english etc.:
<?
$language = $_GET['lang'];
if($language == 'en-GB')
{
include(ROOT_PATH .'languages/en-GB/index.php');
} elseif ($language == 'de-DE'){
include(ROOT_PATH .'languages/de-DE/index.php');
}
$smarty->assign("title", $lang['Main_title']);
$smarty->dispaly("index.tpl");

?>
include(ROOT_PATH .'languages/'. $language .'/index.php');
$smarty->assign( 'language', $language ); // $language taken from GET ID
Back to top
View user's profile Send private message
fornve
Smarty Rookie


Joined: 25 Apr 2008
Posts: 29
Location: Sheffield, UK

PostPosted: Fri Mar 11, 2011 2:51 pm    Post subject: Reply with quote

Hi topliset,

It is good solution which I used successfully as well. Recently I have developed something different such translation blocks.

In smarty template it looks like:

{t}String to translate{/t}

And to allow use this I had to register 't' block:
$smarty->registerPlugin( 'block', 't', translate' );

function translate( $params, $content )
{
$language_array = Language::getLanguageArray(); // This will return array with strings for current language

return $language_array[ $content ];
}

I hope it will help.

Best,
Marek
Back to top
View user's profile Send private message Visit poster's website
toplisek
Smarty Regular


Joined: 17 Sep 2009
Posts: 48

PostPosted: Fri Mar 11, 2011 9:01 pm    Post subject: Reply with quote

Do you separate text content for each language with included files within each index.php file as it is used the same index.tpl for each language?
Back to top
View user's profile Send private message
ChrisFah
Smarty Pro


Joined: 02 Nov 2009
Posts: 159
Location: Traun, Austria

PostPosted: Fri Mar 11, 2011 11:54 pm    Post subject: Reply with quote

Hi,
I am using another way to get language content:

Language is stored into Session after user has selected a language or default lang is set.
After this, I use config files to import all text :
Code:
$smarty->config_load('languages/'.$_SESSION['language'].'/'.$_SESSION['language'].'.conf', 'module_search');


With this, I can use the text in correct language in php by using
Code:
$smarty->get_config_vars('text');

or
Code:
{$smarty.config.text}
in template files.

Without caching, the correct language config file is used automatically, with caching, I use $_SESSION[language] as cache_id.

Regards, Chris
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 -> General 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