Re: language files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ryan A wrote:
Hey,
I was just wondering which is the best/most efficient way of having language
files for a site?

eg:
if $lang=english then it should include lang.en.inc.php
if $lang=swedish then it should include lang.se.inc.php
etc

One way I did it before was to have an array like so:
$lang_en[0]="Enter username";
$lang_en[1]="Enter password";
etc
and then in the main php files I include the above language files and in the
print/echo statements I echo $lang_en[x].

It works quite well but just looking at the code its quite easy to get
confused because of all the $lang_en[x] statements...and you have to
constantly check the language file and the array number to know whats where,
I though of using short workds like

 $get_user="Enter your username:";
 $get_pass="Enter your password:";

but then sooner or later you are going to use the same variable and
overwrite what you wrote before if you are not careful..esp if you have a
lot of text on your site...or a large site....which will produce some weird
results till you notice your mistake...
So.....how have you guys done it....or ....any advise on doing it? pointers?
tips? ideas?

Cheers,
Ryan

Hey ryan! What I do is use an $lang array, but instead of using the traditional numers ([0], [1], [2]), I use $lang['hello'] or $lang['goodbye']. To prevent overwriting, I usually use the context in which they are used in as well:


$lang['login_username']		=	'Username: ';
$lang['login_password']		=	'Password: ';

$lang['link_index']		=	'Go Home';

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux