|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Sim00n Smarty n00b
Joined: 01 Feb 2010 Posts: 3
|
Posted: Mon Feb 01, 2010 3:55 am Post subject: [HELP]Including language files |
|
|
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 |
|
fornve Smarty Rookie
Joined: 25 Apr 2008 Posts: 29 Location: Sheffield, UK
|
Posted: Wed Mar 03, 2010 12:14 pm Post subject: |
|
|
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 |
|
Viruzzz Smarty n00b
Joined: 10 Nov 2009 Posts: 4
|
Posted: Sat Nov 12, 2011 10:31 pm Post subject: |
|
|
anyone have complete code?
with session, i try to implement this code and don`t works
PS. Sim00n code
thx |
|
Back to top |
|
|
|
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
|