Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
[HELP]Including language files

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
Sim00n
Smarty n00b


Joined: 01 Feb 2010
Posts: 3

PostPosted: Mon Feb 01, 2010 3:55 am    Post subject: [HELP]Including language files Reply with quote

Hi. I've got problem, ohh actually it's not compatible or not satisfied code.
I'm making website based on PHP + Smarty and MySQL.
My problem is I'm doing it with two languages (English and Polish) and all text's in .tpl file have to be in two languages depending on what language is set.

I did it with assign function. Example:

Code:

PHP:
<?
if($language == 'Polish')
{
   include(ROOT_PATH .'Languages/Polish/main.php');
} else {
   include(ROOT_PATH .'Languages/English/main.php');
}
   $smarty->assign("title", $lang['Main_title']);
   $smarty->dispaly("index.tpl");
?>


Polish/main.php
<?
$lang['Main_title'] = "Tytuł";
?>


English/main.php
<?
$lang['Main_title'] = "Title";
?>


index.tpl

<html>
some html stuff ...
<title>{$title}</title>
rest of html ...
</html>



This is really basic example that I wrote for this site but this is how it basically work. My question is:
Is there any way to skip first php file and all assign stuff and do something kind of "if" and "include" in tpl file and use varibles from lang files.

I'm sorry for my English and I hope someone will know how to help.
Back to top
View user's profile Send private message
fornve
Smarty Rookie


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

PostPosted: Wed Mar 03, 2010 12:14 pm    Post subject: Reply with quote

You can do this simpler.

In controller:

Code:

include(ROOT_PATH .'Languages/'. $language .'/main.php'); 
$smarty->assign( 'language', $language ); // $language taken somehow from your main.php file


In template:

Code:

{$language.HELLO_WORD}
Back to top
View user's profile Send private message Visit poster's website
Viruzzz
Smarty n00b


Joined: 10 Nov 2009
Posts: 4

PostPosted: Sat Nov 12, 2011 10:31 pm    Post subject: Reply with quote

anyone have complete code?
with session, i try to implement this code and don`t works

PS. Sim00n code

thx
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks 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