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
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);

?>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.