July 7th, 2005, 7:09 am by lig
I have posted on the code snippet page a couple of things. My hacked version of IntSmarty is there, as well as the MyIntSmarty class I used, and finally the newArticle template converted over to use it. I have written in this
blog extensively about my experiences learning and hacking IntSmarty. The creation of the MyIntSmarty was also discussed.
If you look at the original newArticle template and the revised one - you will probably see very little difference (minus the few slight layout changes I made for the inclusion of a navigation menu). All I had to do was add the {l} and {/l} tags around the text I wanted translated. How easy is that.
Hopefully this will help anyone who has to create a multilingual site (mine was Japanese, English and eventually Korean). It really isn’t that hard once you get the basics - so do your homework. If you have a hard time getting this to work or have a question about it please let me know - I’d be more then willing to help you figure it out.
Posted in General, computers, PHP, IntSmarty | No Comments »
January 20th, 2005, 8:20 pm by lig
Well the first page of my administrative area is up and running (debugged and minor testing). Will be starting the next page tomorrow. Worked on fixing a few bugs and Photoshop all day today. Was a nice change of pace.
The Project Manager/Translator finally had a chance to see her translation in context and hated it.
Said it looked like a bad translation script was used. HEHE. She asked to have the files re-sent so she could do a better job this time. Luckily I had just finished the first admin page. Wonder if she is surprised by the size of the translation file (it is getting pretty large).
Posted in General, computers, PHP, IntSmarty | 2 Comments »
January 5th, 2005, 10:44 pm by lig
Well I’m back at work (about a week now) and working on my project. Got some things done on varaction but not as much as I wanted. *shrug* My boss is actually letting me code all day instead of doing all the other million things I have to do so I am actually getting somewhere.
While I was just hanging out on the PHPCommunity channel today coogle came around asking about the IntSmarty project. Told him about my current problem and sent him the translation file that crashed the site. Wouldn’t ya know it - it about 5 minutes he saw where/how the translation file formating was screwed up (there were stray single quote marks and a comma where there should not have been). John reminded me that the single quotes will end the translation string so I had extra strings just hanging around messing up the parsing. So I fix it and what do you know - it works.
John also commented that it seems I found a bug in the PHP. I haven’t a clue how or where so I asked him to report it since he would know more about the actual details involved (I only know that it didn’t work and what I did before hand). I admit it - I am a CIS person not a CS. I don’t care how it works as long as it does.
Well I now have a total of 4 pages up and running. 2 are in English and Japanese, 2 in only English. Still have to code the administrative area, backend cron programs- and get a korean translation to try that out on the pages. I almost feel done.
Posted in General, computers, PHP, IntSmarty | No Comments »
December 22nd, 2004, 6:27 pm by lig
Well I got the translation file back from Tokyo for the index page. Uploaded the file… and everything died.
- figures.
Anyway, here is the current scenario… opened the site in English and navigated through it with no problems. Made Japanese the prefered language (In Mozilla - Edit ->Preferences. In the Navigator list go to languages and add it or move it up to the top of the list.) and reloaded. Blank white page with the status bar saying Done.
Hmm. Time to find out where the problem is with a little debugging. Put in a few echos to see what is happening. Upload and reload. Blank white page. View page source -> Nothing. Not even a openning and closing html tag. Hmm. Check the error logs to see if it says anything… Nothing. Go to the access logs to see if any information is there about what is going on… Nothing. Not even an entry to say that someone has requested a japanese page. Now that is interesting.
Got to the PHPCommunity IRC channel and ask the guys there since I’m stumped. Explain to them what is going on and what I have done. It is suggested that there may be a problem with the interaction of the PHP and the Apache since the requests aren’t even making it to the access logs. I then recalled an email I got from the hosting service that they are upgrading the version of PHP and the Zend Optimizer. So maybe I am just catching it in the middle of the upgrade…
Someone else (cnb to be exact) suggests I try rolling back the translation file. Daah - I do need to verify it isn’t the new file. So I dig out the old file and reload it. And don’t ya know it works again! So it is the translation file that is the problem. Hours of work trying to figure out the problem and it is the stupid file. Grrr.
Have downloaded a clean new translation file and sent it back out to the translator. Made sure to tell them not to mess around with the format. Never did find out exactly what the problem was.
So now I will be going back to work on the next page. Almost there. Have the templates done and ~80% of the logic. Hopefully will have the logic done soon.
Posted in General, computers, PHP, IntSmarty | No Comments »
December 17th, 2004, 12:34 pm by lig
Well I have just finished the index page and it was much more complex then the login page. In English - it is working fine. I have just sent out the translation table to my co-worker in Toyko and will hopefully be getting it back soon. Will let ya know how it goes.
Posted in General, computers, PHP, IntSmarty | No Comments »
November 27th, 2004, 10:53 pm by lig
Well I have about 2/3 of my index page working in English (4 of the 5 templates are being used). Planning on working on the last 1/3 tomorrow. Then I have to send out the tranlation files and get them back. I wonder if this page will work without a hitch? Hey - I can hope!
(Man - this sucks not being able to talk about the specifics of the project - never mind not being able to show it. But the company does own it and it is going to be proprietary software… *sigh*)
Posted in General, computers, PHP, IntSmarty | No Comments »
November 23rd, 2004, 11:23 pm by lig
Well I finally have the Intsmarty completly displaying the login page correctly. YEAH!!!
The problem was in the smarty_lang_prefilter. The code originally has the strings being replaced in the ISO-8859-1 character set (using the utf8_decode). But my page is in the utf8 character set (so it can be more flexable). So of course there were problems with the display of 2 character sets on 1 page. Once I removed the the utf8_decode it worked perfectly.
[php]
/**
* hack starting here
*/
/** the line below is the original line of code
*$content = preg_replace(”!{$ldq}l{$rdq}$q_str{$ldq}/l{$rdq}!s”,
*utf8_decode($inst->translation [$hash]), $content);
*/
// here I am removing the utf8_decode because my page is in the utf8 character set
$content = preg_replace(”!{$ldq}l{$rdq}$q_str{$ldq}/l{$rdq}!s”,$inst->translation [$hash], $content);
/**
* end hack
*/[/php]
Posted in General, computers, PHP, IntSmarty | 4 Comments »
November 21st, 2004, 11:17 pm by lig
Well this past week I have had to suspend all work on the IntSmarty project…. Just have too many other things to do before I go stateside for a month. With the problems I’m having with the IntSmarty handling the Japanese and the work required to straighten it out… I can’t take the time right now. *sigh* Have been catching up on all my other projects and duties (and unfortunately my paperwork). Hope to restart work on the IntSmarty next week.
Posted in General, computers, PHP, business, IntSmarty | No Comments »
November 13th, 2004, 5:15 pm by lig
Well I jave my japanese file loaded and the page runs. Few problems though. The translation strings for the error messages (use cnb’s myGettext on those) are working fine in English and Japanese. The problem is in the IntSmarty or Smarty. I personally think it is the Smarty. Ok here goes my theory - IntSmarty does its job and gets the string conversion in the alternate language and passes it to the Smarty to put into the template. Smarty however doesn’t know what to do with the multibyte strings or how to display them, so I get the wonderful ???? strings.
Sent an email to coogle (John Coogeshall - the creator of IntSmarty) telling him of my problem and my opinion of what and where the problem is. He very quickly got back to me that he would take a look. And today he sent me another email saying that he thinks there is a “problem with multibyte support” and is taking a closer look. Man I really wish I knew Smarty and how it works. Will be taking a look at it’s code when I get back to work and see if I can pinpoint the problem since coogle does have another job (Congrats by the way and I hope you enjoy your new job at Zend) that has nothing to do with me and my problems (
). More minds working the better. Will keep you posted.
Oh and I am just about ready to load the index page and all it’s templates on to the server and start debugging that page. Want to first get it working in English. Maybe by then I will have a solution for the problem I am having with the multibyte strings. The index page is much more complex then the login screen so I am sure I will having a couple of new problems.
And one more shout out to coogle - Thank you for your help with solving this problem. I know you are very busy, so I really appreciate you taking the time to help.
Posted in General, computers, PHP, IntSmarty | No Comments »
November 11th, 2004, 4:26 pm by lig
Well I finally remembered to ask my friend if I could post his code to the blog and he said yes. so here it is:
[php]
function myGettext($value) {
$hash = md5($value);
if (key_exists($hash, $this->translation)) {
$value = $this->translation[$hash];
} else {
$this->translation[$hash] = $value;
}
return $value;
}
[/php]
cnb is an awesome programmer and guy. You should checkout out his blog to learn more about him and what he is currently doing in the world of PHP. I would also like to thank the people on the PHPCommunity IRC channel (#phpc on freenode) for helping me get this far.
Posted in General, computers, PHP, IntSmarty | No Comments »
November 7th, 2004, 11:32 pm by lig
Well I’m still waiting to get my translation files returned. Didn’t think that it would take this long to get them back. In the mean time I have been working on the templates for my index page. All in all I have 5 templates for it. Am thinking about extracting the header html (looks like file tabs - navigation) and making that into it’s own template. Will have to learn how to make a template that accepts a param so the right “tab” is displayed. Granted I can do the copy and paste thing with the best of them, but… probably be more “professional” with it’s own template. *sigh* Research and learning time vs. just getting it to work… The great trade off.
Have also started the index.php page. Talk about a big switch (
) - pun intended. Think I have most of the logic worked out (in the comments) - just have to actually write the code to do it now. Since I have never done anything OOP I have never been shown how to diagram a page like this in UML. That would have come in handy with the 5 templates interacting… another thing to learn.
Posted in General, computers, PHP, IntSmarty | No Comments »
October 21st, 2004, 10:52 pm by lig
TaDa!!! I think I got it to work! With the help of a good friend (cnb) and a little bit of his code - By golly I think I got it to work! I will post the code he sent me later if he says its OK but basically it takes the individual strings and looks for them in or adds them to the translation array based on what is needed. It’s a slick little thing. Now all I need is the table in another language so I can make sure it isn’t just my imagination.
Oh and the function not existing…. *blush* it didn’t - I added it outside of the IntSmarty closing bracket. I didn’t realize that the prefilter and compiler were OUTSIDE of the IntSmarty class.
Posted in General, computers, PHP, IntSmarty | 2 Comments »
October 21st, 2004, 9:43 pm by lig
Well I have the majority of the IntSmarty working and have sent out the files to be translated. Still trying to get the messages sent back to the user to be translated. Keep on being entered into the language tables as the variable name not the string they contain. Waiting for the Darn cache to clear because it keeps trying to tell me that a function doesn’t exist when I’m sitting here looking at it in the code. Freaking irritating!
cnb sent me a function to use to get the error messages to be translated. Will try using it as soon as the #*!$ cache clears. (*calm down lig*). Have tried (client side) clearing the history listings, deleted the cookies, looking for a new page everytime, and (server side) force compiling the pages…. still have the cacheing problem. Think it’s time to shut down the browser to clear the session variables… Sigh - what a pain.
Posted in General, computers, PHP, IntSmarty | No Comments »
October 20th, 2004, 11:43 pm by lig
Well I had to walk away from it (the IntSmarty) for a bit to clear my head…. and the cache. And guess what. The page is now saving and destructing.
Still am not getting the error messages but then they are placed into the $errorMessage variable on the PHP page not the template. My language table has the ‘{$errorMessage}’ being converted rather then the string that goes into it. Will try to figure out a workaround or hack later for it. For right now I am now the proud owner of a generated “en-us” table and that is enough. So I guess that means I can copy it and pass it on to be translated into Japanese and Korean. Want to do that soon so I can have it tested to make sure it all works OK.
Thanks coogle, cnb, and grout for the help! Going to leave all the debugging lines in for now so if there are problems later I don’t have to start over from scratch. Thank you to whomever created and coded “Copy and Paste”. Your a life saver.
Posted in General, computers, PHP, IntSmarty | No Comments »
October 20th, 2004, 7:33 pm by lig
Thanks to a friend giving me a swift kick in the buttocks I have started debugging the IntSmarty code for my server. Found a couple of problems. First problem I had was that my a_languages array was not being copied over to the cur_language array correctly. It seems that an empty element was also being added and of course it had to be in the first position. So made a little hack (that took longer then it should of since I was coding in java all weekend so my variables were all messed up - kept on forgetting the $) that simply loops through and finds the first non-empty element.[php]
/* hack started here */
/* to handle a_languages having empty elements in the front for no apparent reason - like mine */
$i = 0;
$isEmpty = 1;
while($isEmpty){
if (trim($this->a_languages[$i]) != ‘’){
$this->cur_language = $this->a_languages[$i];
$isEmpty = 0;
}
else{
$i++;
}
}
/* hack ended here *[/php]
Ok once that was fixed kept on debugging because my language table still isn’t being saved. Found out the lang_path from MyIntSmarty was being overriden by the IntSmarty lang_path. So I hard coded the path into the IntSmarty (don’t like that but can’t think of another way to do it.).
Well the language tables are finally loading… but the IntSmarty isn’t destructing and saving the table. Figure it’s because the server is running PHP4 rather then 5. Tried calling the destruct explicitly at the end of the page (after the display) and still no good. I thought about moving it to earlier in the code but then I would lose all the information for the display. Instead I called the saveLanguageTable function before all of the assignments for the display and it worked. Will try it after the assignments to see if I get the error messages.
Posted in General, computers, PHP, IntSmarty | No Comments »
September 29th, 2004, 4:05 pm by lig
Well I thought I figured out what I did wrong. I didn’t have a constructor in my version of IntSmarty. So I made one.
[php]< ?php
// load IntSmarty library
require("/.../intsmarty.class.php");
class MyIntSmarty extends IntSmarty {
function MyIntSmarty() {
parent::IntSmarty('');
$this->template_dir = ‘/…/smarty/templates’;
$this->compile_dir = ‘/…/smarty/templates_c’;
$this->config_dir = ‘/…/smarty/configs’;
$this->cache_dir = ‘/…/smarty/cache’;
$this->force_compile = true;
$this->default_lang = ‘en-us’;
$this->lang_path = ‘/…/public_html/languages/’;
}
}
?>[/php]
It works kind of. But again I am not saving the language table. Coogle save me from hell!
Posted in General, computers, PHP, IntSmarty | No Comments »
September 28th, 2004, 11:49 pm by lig
Well I decided to try the MyIntSmarty and in a way I got the IntSmarty working (had to really pay attention to paths though - originally couldn’t find Smarty and then later IntSmarty, language folder and a couple of other things). So now I have the {l} around my text to be translated and the MyIntSmarty class made with my specifics. Only 1 problem - I’m not creating the language tables.
Created the file and changed the perms to 777 so the webserver can write to it and set the path in the $lang_path… easy right? Call up the page and it displays. Look in the language directory for the en-us.php or en.php file and nothing. Hmmm - check the compiled templates and there is a directory named ‘en’ follow it down to a compiled page. Hmmm. Maybe I need to clean out the compiled templates and the cache so the IntSmarty can make the files… Do that. Call the page again - same thing. Check the error logs - maybe something popped up there…. Nothing. Maybe the access logs (hey I was desperate)…. POST 200 code. Dang nothing showing there… Maybe I need to create the blank files and put them in place? Do that. Nothing still! Grrr.
Tried to figure it out (tweek, alter, rewrite) and couldn’t… spent most of the day on it. Hate doing this but time to ask a dumb question. Write an email to John Coggeshall (the author of IntSmarty) explaining what I did and sent some of the code (the MyIntSmarty, the php page and the template). Hopefully I’m not asking a totally stupid question or missing a really basic component. Nothing like a novice to screw up something easy
.
So here I sit. Hopefully the email will be noticed some time this month since I’m sure the author gets tons of email. Maybe the IntSmarty in the Subject line will help - maybe it will get it dumped. We’ll see and I’ll let ya know
Posted in General, computers, PHP, IntSmarty | No Comments »
September 27th, 2004, 12:00 am by lig
Well I started reminding myself how to use Smarty and PEAR’s DB today. Took awhile since I forgot that the server was changed since the last time I used it (path names were changed). Pulled out the old file I played with originally to get a small grasp of Smarty and DB (a login screen). Thank goodness I commented it well so I could easily remember what was going on. Took apart the template and redid it so it looks the way I want, and fine tuned the code and tada I have a working login screen for my project. See R&D time for a programmer is needed even when you can’t see a time in the near future.
Now I have to throw in the IntSmarty. First thing I did is install the class file in the same directory as the Smarty class file and include it. Am thinking about trying out John Coogeshall’s way with a MyIntSmarty class but I’m not very strong in OOP. I still haven’t decided, but that is for tomarrow.
Posted in General, computers, PHP, IntSmarty | No Comments »
September 21st, 2004, 4:20 pm by lig
Well so far on my latest project the system engineer has thus far decided on me programming my part using PEAR DB and IntSmarty (still in planning stage though). IntSmarty was chosen for the easy internationization and the seperation of presentation and logic. That was my idea since we will be using it for the PHPCommunity website (hopfully everyone won’t occasionally mind answering my questions). I’ve only played with Smarty a little bit just to get a feel for it so I should be able to do this. The PEAR DB was chosen so the program can be used on multiple DB manufacturers easily. Again I have only played with this but I don’t forsee any problems. The system engineer is still trying to decide whether he wishes to use MySQL or PostgreSQL.
For a person who never really learned OOP (and is slightly uncomfortable with it) this should be fun and a good strech of unused muscles. I look forward to it as much as I worry about screwing up. I think thats a good thing.?!? Thank goodness I have at least played with them. So it isn’t completely new.
I will also try to keep the blog up to date on problems I have as well as the solutions I use so anyone else who tries after me will have better luck. I’m sure there will be more then a few interesting situations.
Oh and if anyone wants to pass on any tips, tricks, or pitfalls I should know about - I would apprieciate it.
Posted in General, computers, PHP, IntSmarty | No Comments »