Page 1 of 1

language templates

Posted: Tue Aug 17, 2004 4:43 pm
by Fredix
Since it is something a user cannot see I post this "code design question" right here.

I would like to talk to with you guys about language templates...
I mean how do you solve the problem that your projects have to be multilingual.

In my case I decided that my scripts that operate and then output data should not be copied and translated one by one because if I find an error one file there will be 10 files more to correct (same error different language). So I made up languagefiles containing a whole bunch of variables which maybe is not a very nice solution in respect to memory usage and speed but anyway it is easier to maintain. So how it works:

the script that the user operates with first reads a file that tells him about the language that should be used, then this script loads the languagefile

Code: Select all

<?php
//$language could be sth. like "var_en.php" or "var_de.php" etc.
include($language);
?>
the language file looks like:

Code: Select all

<?php
$welcome = "Hello dear visitor";
$prompt = "Please enter your nickname";
?>
or

Code: Select all

<?php
$welcome = "Herzlich Willkommen!";
$prompt = "Bitte melden Sie sich an";
?>
And the main file now would use the variables since the variables' names are always the same but depending on what was included at the beginning the output will be English or German.

What do you say to such a solution and what would you propose?
Thanks for your comments!

Posted: Tue Aug 17, 2004 4:47 pm
by feyd
it's sorta what I use.. although I stuff them into an array, for easier keeping, passing around, and whatnot..

Code: Select all

<?php

$lang['welcome'] = 'Welcome y''all!';

?>

Posted: Wed Aug 18, 2004 2:56 am
by CoderGoblin
phpBB uses a language array similar to how Feyd described. I have previously looked into the PHP extension Gettext but did not find it that useful. I now also use the a language array but get the information from a database. If necessary I could write an interface for translators rather than giving them access to the code.[/mail_search]