Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I'm launching a site to show how Google could provide unified search
results. I expect it to have a good audience and volunteers to
translate to other languages. There is a translation mechanism already
in place, in the following form:

$language = language();
if ($language =3D 'en-us')
  $content[0] = 'Unified Search Prototype';
  $content[1] = 'on Pleke';
if ($language =3D 'pt-br')
  $content[0] = 'Prot=F3tipo de Busca Unificada';
  $content[1] = 'no Pleke';

and in the page code, all the content is displayed as:

<meta name=3D"description" content=3D"<?php echo $content[0]; ?>">

I expect that PHP will jump to the correct condition of the "if"
statement and just ignore the others, so it should not affect
performance even if there are 800 lines of translation content, 40 for
each language. Am I right?

Another thing, does this implementation support oriental languages,
like Japanese and Korean?

How do I profile the performance of the page processing and use of the
processor? Does PHP have built-in profiling tools?

best regards,
Mauricio Macedo

Re: Internationalization

Mauricio - Pleke wrote:
Quoted text here. Click to load it

It works, but probably is not the best way to go about it.  Performance
will suffer to a limited extent - some from all of the if statements,
but more due to the parsing of all that code.

A better way would be to use a "switch" statement with a case for each
language.  Even better would be to keep the strings in a database and
just fetch the rows for the language you want.

As for oriental languages, it doesn't really matter to PHP - but you
have to send the correct charset header to the client.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Internationalization

Quoted text here. Click to load it
No. php cannot "jump" to the correct if statement. It will run through
each one in turn until it fins the target. After that, it will have to
go through all the rest until it reaches the end of the set of if

A database is the way to go. You could just install Joomla! with Joom!
Fish and the whole mechanism is there for you.

Re: Internationalization

Quoted text here. Click to load it

Not strictly true.

PHP must parse all the code, but once it has built up the tokenized
version there won't be much difference in the performance. So the
overhead is in parsing the source code. If performance is a problem
then you can do something like.....

include("lang_specific." . language() . ".inc.php");
if (!function_exists('something_in_include_file')) {
    log_msg("user requested language " . language() . " but not


Re: Internationalization

Quoted text here. Click to load it
I wasn't commenting on performance. I was just correcting the
impression that php would magically "jump" to the correct if
statement, without having to check all the preceding ones first.

Re: Internationalization

On Mon, 24 Aug 2009 07:27:34 -0700 (PDT), Captain Paralytic wrote:
Quoted text here. Click to load it

Hooray! We're both arguing about differences that make no difference,
then! I thought I was the only one...

77. If I have a fit of temporary insanity and decide to give the hero the
    chance to reject a job as my trusted lieutentant, I will retain enough
    sanity to wait until my current trusted lieutenant is out of earshot
    before making the offer.  --Peter Anspach's Evil Overlord List

Re: Internationalization

.oO(Mauricio - Pleke)

Quoted text here. Click to load it

Besides the DB idea you could use a separate file for each language,
which contains the $content array, e.g.

$content = array(
  'Unified Search Prototype',
  'on Pleke',

Then your main script simply has to include the required language file.

Another idea would be to use gettext. It also stores all the strings in
separate files, which makes maintenance much easier.

Quoted text here. Click to load it

Not built-in, but the Xdebug extension can do it. You can then analyze
the output with WinCacheGrind or similar tools to find the bottlenecks
in your code. /


Site Timeline