views:

59

answers:

1

Will it downgrade performance significantly (or exhaust the server with http requests), or maybe ill advised, to do something like this

echo "<span>enter_username_message</span>";

and centralize this constant along with all output messages in one file, so that those could be changed without getting into the code:

define('enter_username_message','username please');

that way, if someone were viewing the website in its spanish version, I could simply direct php to require all those output-message constants from a spanish file.

define('enter_username_message','username por favor');

what do you think?

+2  A: 

You should probably just use gettext: http://us3.php.net/manual/en/book.gettext.php

It's designed for the kind of thing you're talking about.

Edit Apparently PHP gettext isn't thread safe (ugh, I hate PHP), so perhaps look at something like Zent Translate with the gettext adapter, which is thread safe: http://framework.zend.com/manual/en/zend.translate.adapter.html

My reason for suggesting using something gettext based is the various tools that are available for creating and editing gettext .po/.mo files, which make creating translations easier than just going through some text file and editing things.

pib
quoting: "As a reminder, this is not thread-safe and will not work on typical windows/apache installs."And it surely will introduce more overhead than the original poster idea.
AlfaTeK
Using the gettext "EXTENSION" is the only way to go in respect to performance IMO and from benchmarks
jasondavis
this won't have any effect on the # of http requests - still just 1 to load the page + 1 for each external resource. so from that standpoint there's no problem.
echo
@jasondavis: what about the aforementioned lack of thread safety?
pib