IntSmarty, has anyone ever implimented this?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

IntSmarty, has anyone ever implimented this?

Post by NewfieBilko »

Hey guys. NOTE: Looking for Smarty Enthusiasts

I have been working on my smarty system, and have been scouring for ways to impliment internationialization. There seems to be 2 distinct ways. Use IntSmarty which acts like the block(?) t function? I am not too sure on it as I havn't been able to get it to work, but it seems similair to what people have been tlaking about by using block delimiters like {L} and {tr} to tag off some text, which will then draw up a table of words, then you can go ahead and translate all those words yourself into diferent language tables. Seems legit, but I cannot get it to work, I keep getting flex scan errors and other weird occurences. So anyway, i went on to do more reserarch and found that the get-text function seeems to work ok for this (Sagi's approach), but I havn't tried this yet.
I have also been conccerned wityh something that i've seen in recently updates of smarty. In the setup.php I've noticed a call to some language arguments:

Code: Select all

<?php
global $lang;
include_once('lang/language.php');
function tra($content)
{
    global $lang;
    if ($content) {
      if(isset($lang[$content])) {
        return '+'.$lang[$content].'+';  
      } else {
        return '-'.$content.'-';        
      }
    }
}


?>
Its as If they have already installed some sort of language tranlator block. When i scour my code I DO notice that some things are demlimited. with {tr}'s!!!!!! What is this, can anyone trell me? Does it actually work, or why is it in smarty, has smarty already been internationialized and i am left in the dark? Anyway, that is one big matter/question i need answered.

But on I go , cause I know i need my system to be intrnationialized. I need my entire system to be hotswapable with any language, so i was thinking about a "news-maniac/moodle" approach.. Where you store everything as a variable and then just call the vbariable and whatevere lang is set is what page it ghets the variables from.. This is a very neat concept and I like it. But betweeen the 2 methods I seem to be getting lost, not knowing which way to go with it. And consdiering I can't get INTsmarty to work ( when I put something in {l} i get this:

Code: Select all

<?php

Warning: Smarty plugin error: [in leftbar.tpl line 4]: unknown tag - 'l' in /var/www/php2/Smarty/Smarty.class.php on line 1889

Warning: Smarty plugin error: [in leftbar.tpl line 4]: unknown tag - '/l' in /var/www/php2/Smarty/Smarty.class.php on line 1889
 
Fatal error: Call to undefined function: () in /var/www/php2/templates_c/N626/N626615291/leftbar.tpl.php on line 8 


?>

So I dont really understand.. its as if L cannot be found, but this magicaly TR(?) which seems to be built into smarty does nothing.

If anyone knows anything about SMarty, if it already has int built in (blockt), or know any other good way to go about internationization then please write. I am looking to make my entirie system changeable at any time by the user by the way, so not have it pick the lang bythe browser incoming, but by a user selected drop down menu, wh9ich would need to cahnge the $lang variable i gues, not to hard. But in order to get to that step, i need to first of all understnad why Int will not work, or maybe see how I can get somethnig at all to work.

Thank you...
*distressed*
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

BTW, for some weird reason, this version of Smarty I got seems to have some sort of lang support built in.. But it deflninilty is not using it.. Does anyone know anything about this? I have a file called "get_strings.php" which links up to the language support it seems. I need to add on to this, and actually make it work.. Seems my version is using TR as the demlimiter, but it is not working.. I dont understand, beacuse i never implimmneted this internationalization, yet it is just here, when i ask the boys over at Smarty.com they say this wasn't in the distributation package, so WTF.. here is the code from get_strings.php:

Code: Select all

<?php
<?
// Cambiar lo que busca segun sea .php o .tpl

$languages = Array('en','sp');

$files = Array();
  
$handle=opendir('templates');
while ($file = readdir($handle))
{
  if($file=='.'||$file=='..')
  continue;
  if(substr($file,strlen($file)-3,3)=="tpl") {
    print("File: $file<br/>");  
    $files[] = 'templates/'.$file;
  }
}    	
closedir($handle);

$handle=opendir('.');
while ($file = readdir($handle))
{
  if($file=='.'||$file=='..')
  continue;
  if(substr($file,strlen($file)-3,3)=="php") {
    print("File: $file<br/>");  
    $files[] = $file;
  }
}    	
closedir($handle);



foreach($languages as $sel) {
include_once("lang/$sel/language.php");
$fw = fopen("lang/$sel/new_language.php",'w+');
print("<?php\n<br/>\$lang=Array(\n<br/>");
fwrite($fw,"<?php\n\$lang=Array(\n");
foreach($files as $file) {
  $fp = fopen($file,"r");
  $data = fread($fp,filesize($file));
  fclose($fp);
  preg_match_all("/\{tr\}([^\{]+)\{\/tr\}/",$data,$words);
  foreach(array_unique($words[1]) as $word) {
    if(isset($lang[$word])) {
      print('"'.$word.'" => "'.$lang[$word].'",'."\n<br/>");   
      fwrite($fw,'"'.$word.'" => "'.$lang[$word].'",'."\n");
    } else {
      print('+++"'.$word.'" => "'.$word.'",'."\n<br/>");  
      fwrite($fw,'"'.$word.'" => "'.$word.'",'."\n");
    }
  }
  preg_match_all("/tra\("([^"]+)"\)/",$data,$words);
  foreach(array_unique($words[1]) as $word) {
    if(isset($lang[$word])) {
      print('<b>"'.$word.'" => "'.$lang[$word].'",'."</b>\n<br/>");   
      fwrite($fw,'"'.$word.'" => "'.$lang[$word].'",'."\n");
    } else {
      print('<b>+++"'.$word.'" => "'.$word.'",'."</b>\n<br/>");  
      fwrite($fw,'"'.$word.'" => "'.$word.'",'."\n");
    }
  }
}
print('"'.'##end###'.'" => "'.'###end###'.'"'.");?>\n<br/>");  
fwrite($fw,'"'.'##end###'.'" => "'.'###end###'.'");'."\n".'?>'."\n");  
fclose($fw);
unlink("lang/$sel/old.php");
rename("lang/$sel/language.php","lang/$sel/old.php");
rename("lang/$sel/new_language.php","lang/$sel/language.php");
}
?>
?>

Weird eh, in any case it doesn't work. I am guessing this is using the block.t function though?Maybe with someone whos got expeirence i could getit to work???? $$$$


Mark

Thanks
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

I would recommend that you remove your installation of Smarty and reinstall an offical smarty release. If you have code in there that is not part of the offical smarty distribution then I think you will find it extremely difficult to get support for it (many people donot support modified versions of their code), unless you can find the maintainer for that paticular part of the code and seek help from them.

To be honest, judging by the lack of response to your numerous posts on this subject, I think it is fairly safe to say that non of the regular vistors to this forum have any experience of Smarty (or at least in the areas where you require help).
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

Tru, thought i'd give it a shot anyway.

Thanks for your reply


LOL i cannot find anyone whos used IntSmarty, nor News-maniac... This makes baby jesus cry :oops:
Post Reply