Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Need words of advise for language system

Posted on 2005-02-27
Medium Priority
Last Modified: 2008-03-10
I'm busy building a site, using php. I designed it so that the php just returns xml to the browser, and combines this with a style sheet.
What I'd like to do is be able to use multiple languages on this pages, part of wich can be contained in the xsl style sheet. But some output must be generated by the php (such as input field labels). I could place every message in a db (using postgresql) and query everything I need, but that might slow down this page to much. Or I could have everything in a php script and access it by a function or just load it as variable (or constant).

I need some suggestions, advise or even some benchmarking perhaps, to make up my mind.

Question by:stimno1
  • 3
  • 2
LVL 25

Accepted Solution

Marcus Bointon earned 195 total points
ID: 13418305
I use a custom Smarty extension I wrote that does queries on a translation DB. It's a whole load better than using the ugly gettext approach. The key way to keep performance up when using a DB for translations is to use caching (works especially well if your translations do not change much). Try using one of PEAR's caching modules, or use ADOdb (what I use in my Smarty extension) to talk to your DB as it has query caching built-in.

If you're sending only XML and XSL, then your browser compatibility will be way down - better to transform it at the server end.

Assisted Solution

alberthendriks earned 180 total points
ID: 13418421
For smaller sites, the variable approach will suit.




echo _HELLO;

Author Comment

ID: 13420219
Can you tell me more about these pear modules? pear.php.net doesn't return much on a search for cache or caching.
I think I like smarty, although I do not agree on bad browser compatability with xml/xsl since xml is w3c standard (and I have solved all the problems I have encountered so far using mozilla ff and ie).
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 25

Expert Comment

by:Marcus Bointon
ID: 13420490

I think ADOdb is a little more elegant for DB applications than these generic caching packages.

I don't doubt that it's a W3C standard (and I'm generally very keen on sticking to W3C specs), it's just that many browsers I encounter don't have XSLT that works (let alone HTML or CSS in the case of IE), nor do I see many sites that try to use it. If you're going to have to implement server-side transformations to support those browsers anyway, there's not a huge amount to be gained by doing the client-side version in the first place. I'd like to see your site!

Author Comment

ID: 13420947
Isn't caching just taking the data from the database and save it in a file? Why can't I do that myself.

I mean: I caching is so good, why don't I use that technique in the first place?

So: how does proper caching work? Or is it to complicated and should I stick to ready made developed stuff.

Author Comment

ID: 13574209
I've taken a look at squirrel mail language support, and there solution used a getText module.
They've written there own function (or simply copied, don't know) to support the usability when the module is not installed. I took a fair glance at there code and decided to write a similar thing for myself.
I now load a file that seperates the name from the translation by ';' and use {$1} to replace by parameters.
The hole lot is loaded into a hash array, and is kept alive passing it through by session (I don't yet know wheter this is better than file reading every time). (The session save was used in squirrel because getText supports 'fuzzy translations' for when the original is slightly changed, and the translationfile is not yet updated. getText then searches for the best match. Because this takes a lot of cpu the best match is preserved to prevent continuous matching)

I know that i bare a couple of the getText features, but i don't think i'll ever need lft-to-rgt language support. So I'll save myself the trouble of getting into yet another extention..

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question