|
Posted by trlists on 10/21/93 11:15
On 8 May 2005 Evert | Rooftop Solutions wrote:
> What I really need is a fast lookup mechanism, to 'translate'
> statements.
>
> For example:
>
> setOutputType('xhtml');
> echo(translate('authorstart'));
>
> the function translate opens xhtml.data, which contains:
>
> authorstart : <span class="author">
> authorend : </span>
>
> so, the translate function looks 'authorstart' up and returns '<span
> class="author">'
>
> or if you had specified 'wml' as the outputtype, the file could like like:
>
> authorstart : <b>
> authorend : </b>
>
> and the function would return '<b>'
>
> This is all no problem, except that these lists can be pretty big. And I
> wouldn't like to load them all into the memory, or have to loop through
> the file every time translate is called.
>
> So I need a very fast mechanism to overcome this problem.
I think it's called a database. The fields are outputtype, key, and
text to output, with an index on outputtype + key, then you do
something like this:
select OutputText from TranslateTable where OutputType = 'wml'
and key = 'authorstart';
I wonder how many of these you really have. If on each script
invocation you will be looking up many of them (dozens or hundreds) it
might be more efficient to load all the ones for the outputtype you are
using into a PHP array at the start, whether that's in a hard-coded
array or loaded from the database. If you're only looking up a couple
then a separate database lookup for each one is probably more
efficient.
Incidentally I would say this is not a templating problem. It's simply
a translation or lookup problem.
--
Tom
[Back to original message]
|