Having produced many i18n applications most with language switching I will confirm that using a distinct key that isn't the English equivalent is the only way to do it.
Apart from the example you give, there are times when the same english phrase may need to be translated differently.
So, each unique phrase should have a unique ID. I've found that ~PHnnnn~ is my preferred method - as I can easily parse it out and do a lot of the work automatically.
For example:
/*
* in the following line ~PH2228~ is a placeholder and will be replaced with the
* heading text from the language database - the resulting output will be
* whatever language is currently selected by the user.
*/
phrase_op("<h1>~PH2228~</h1>"); // ~PH2228~ = "Introduction to the system"
phrase_op is a simple routine that takes phrases from a database and replaces the token.
I admit that the code isn't as readable - however the advantage is that the English also is editable so you get a mini CMS for free....
For reference - the core of my entire language system is two functions:
/**
* outputs a string changing all the ~PH####~ into the corresponding phrase
*/
function phrase_op($txt)
{
preg_match_all("/\~PH[0-9][0-9][0-9][0-9]\~/",$txt,$regs,PREG_SET_ORDER);
foreach($regs as $result) {
$phc = substr($result[0],1,strlen($result[0])-2);
$ph = get_phrase($phc);
$txt = str_replace($result[0],$ph,$txt);
}
echo $txt;
}
/*
* loads the phrases from the database - called once during system load. With a system with a lot
* of phrases (more than 3000) it may be more efficient to modify phrase_op to load each phrase as required from the DB.
* Alternatively the table could be modified to work with modules - however initial testing during
* development showed that this load everything method wasn't a performance issue.
* Tested against a production server with 572 phrases.
*/
function load_phrases()
{
global $phrases;
global $config;
$phrases = array();
$sql = "SELECT * FROM tb_phrases where iso='".mysql_real_escape_string($config['cur_lang'])."'";
$result = mysql_query($sql) or die('exec_query failed: [ '.$sql.' ]'.mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$phrases[$row['phrase_code']] = $row['text'];
}
}