language templates

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Fredix
Forum Contributor
Posts: 101
Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:

language templates

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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!';

?>
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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]
Post Reply