Internationalisation, string ripping help?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
puntloos
Forum Newbie
Posts: 1
Joined: Sat Jul 03, 2004 6:38 am

Internationalisation, string ripping help?

Post by puntloos »

Hello,

Since my little PHP site is expanding, Im running into troubles I never expected. Who would've thought foreigners would want my site in their language.

So now I have to convert semi-complex PHP like for example

from:

Code: Select all

$CONTENT .= "Dear ".$thenickname.", to login, click <a href="login.php".sesInfo()."&blah=$yada">Here</a>";
to:

Code: Select all

$CONTENT .= $_hello_string.$thenickname.$_login_part1_message."<a href="login.php".sesInfo()."&blah=$yada">$_login_here_text</a>";
And a file lang_en.inc containing:

Code: Select all

$_hello_string = "Dear ";
$_login_part1_message = ", to login, click ";
$_login_here_text = "Here";
You get the general idea.. (I hope). The functions, stringnames and php filenames are all english and can stay that way, the inline text has to go.

Bottomline is, doing the above example just took me hmm, 1 minute to do. Now I'm sure I'll get better and more efficient at it when time progresses but what would be HUGELY efficient is a program that

1/ parses the PHP a bit
2/ replaces all 'language' (anything inbetween " or ' I guess) with strings that have auto-generated names, $string1, $string2, whatever.
3/ mix and match a bit to remove obvious redundancy. It just shouldnt fragment sentences, its nice to replace each occurrence of "Welcome to the " with a reusable $welcome, but not with "$welcome $to $the" (duh)
4/ since it auto-assigns variables, then launch an editor of sorts where I can rename the variables myself
5/ rename the auto-assigned variables to what I chose in #4 into the real code.

And presto. International code. I think. Obviously it doesn't have to be 'spiffy looking'.. the main obstacle I think is program the PHP parser that can rip the strings out of the right places without damaging the code. The renaming of the variables can be easily done by just demanding of the user(me) to not re-sort the temporary .inc file or change the original .php before the variable naming work is done.

Or... are there better tools to make code international-aware? My site is still semi-lightweight really, so I don't think I need something 'industry strenght'. It is conceivable that Id want to pull the language text out of a database, but I dont think that will change my problem structurally.

Suggestions wanted :P
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if your codebase has a template engine, you can use that for #1-3 already.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

info gettext marking
? ;)
Post Reply