Jump to content

Language text in DB or php file?


Phantom81

Recommended Posts

I was wondering what is the best thing to do when we develop multi-language web application.

 

In the past I use DB to store my language data. So at each page loading, the page call the DB and retrive all language string for this page.

 

But I also see in other application (like osCommerce) the use of files (french.php, english.php, ...) where a bunch of variable are set in the file.

 

This two method work, so now I would like to argue about which one is better and why.

Link to comment
https://forums.phpfreaks.com/topic/112118-language-text-in-db-or-php-file/
Share on other sites

I know in Java, localization usually comes in 'properties' files.

 

Here's a prototype in PHP:

 

Template

<p>
There was an error ${my.error.string}
</p>

 

errors.en_us.properties

my.error.string=The command ${opname} is not recognized. Please try again.
operation.unavailable.error=The command ${opname} is temporarily unavailable. Please try later.

 

errors.sp_mx.properties

my.error.string=Desconocido Operacion ${opname}.
operation.unavailable.error=Operacion  ${opname}  indisponible.

 

Render

<?php
$user = UserDao::getUser($_SESSION['username']); // populate the user model object
try {
   $a = Localization::Load($user->getLocale()) //load the proper localization file
} catch (LocaleNotFoundException) {
   $a = Localization::Load(Localization.DEFAULT);
}

$p = new Template("mytemplate.tpl");
$p->render($a);

?>

I have no problem to program one way or the other.

 

I was looking for the best pratice. Person who use multi-language application store string in file or in DB?

 

-File is easy to edit

-DB who load only string for a page use less memory than load all string for all pages like a file

 

Did I not share with you the best practice I am aware of?

 

Yes, thank you.

 

But I would like to have some explaination and arguments. You method use one big file or multiple small files?

 

In .net they use localization file too. One for each page, I don't like this pratice because the data is in multiple files and for change data or add a language, you have to edit all files.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.