473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Language file, Best practice


Hi,

I would like to add international support for my site to allow some of
my users to translate the site if they really feel the urge to do it.

I don't use any CMS, the site was developed, (and refined :)), by me.
But I see that various CMSs handle languages very differently.
Joomla! for example has a smallish define file that has all the
translations.
Wordress on the other hand seems to have a function __(...) that is
altogether a lot more complicated but also more flexible.

But I am not sure that the Joomela! approach is the best, defining what
could become a rather big language file seems a bit silly to me, (well
in my case it seems to be). And there does not seem to be any naming
convention of all those defines, that could spell<sictrouble.

So, what is the best way, so far, of handling languages?

FFMG?
--

'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory'
(http://www.webhostshunter.com/) | 'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php)
'Free URL redirection service' (http://urlkick.com/)
------------------------------------------------------------------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=14085

Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).

Apr 23 '07 #1
2 2672
On Apr 23, 2:05 am, FFMG <FFMG.2ph...@no-mx.httppoint.comwrote:
Hi,

I would like to add international support for my site to allow some of
my users to translate the site if they really feel the urge to do it.

So, what is the best way, so far, of handling languages?
I think phpBB and similar use files for language for portability and
ease of updating. I would save smaller strings (like messages, link
text, page titles) into a database and retrieve the needed language on
each page. I think SQL caching should be effective here because each
language should use the same query every time.

If you think it would be faster, you can save it in both the database
and into files (into a PHP file, with array assignments), and each
time it needs to be updated the form is filled with data from the
database, and then when the form is submitted the data would be
updated in the database and the language file would be regenerated
with that new data. Then the files that use the language would include
the appropriate language file instead of querying the database each
time (useful if the table gets big and the queries start taking too
long). I've benchmarked with 100 rows of data and 100 files, and found
that retrieving an indexed row from the database is about twice as
fast as reading the file named with that index. I've been told that
the database would be even faster in comparison if there were more
files and rows.

-Mike PII

Apr 28 '07 #2
I did some more tests (I am working on a multi-lingual site also so
this is useful to me too), and it looks like reading and unserializing
a serialized language array from a file is much quicker than reading
and unserializing from a database (on my server environment). The
first two times are using PHP to create a PHP file and then
include()ing it

Array
(
[create file] =0.0070760250091553
[direct read] =0.0096750259399414
[write serial] =0.0053510665893555
[read serial] =0.00060105323791504
[insert db serialized] =0.054249048233032
[get db serialized] =0.037890911102295
)

Here's the (PHP5) test that you can try on your server:
<?php
$db = new mysqli( 'dbhost', 'dbuser', 'dbpass' );
$db->query( 'USE `dbtable`' );

$i = 0;
$lang = array();

define( 'DATAFILE', 'benchmarking.php' );

//create file
$data = '';
$times = array( 'create file' =microtime( true ) );
$data = "<?php\n\$lang=array('asdfasdfasdf'";
for( $i = 20000; $i < 20500; ++$i )
$data .= ",'asdfewqrhbeqstn{$i}asdfasdfasd{$i}fasdf'";
$data .= ');?>';
file_put_contents( DATAFILE, $data );
$times['create file'] = microtime( true ) - $times['create file'];

unset( $data );

//direct read
$times['direct read'] = microtime( true );
require( 'benchmarking.php' );
$times['direct read'] = microtime( true ) - $times['direct read'];

//write serialized
$times['write serial'] = microtime( true );
file_put_contents( DATAFILE, serialize( $lang ) );
$times['write serial'] = microtime( true ) - $times['write serial'];

$lang = array();

//read serialized
$times['read serial'] = microtime( true );
$lang = unserialize( file_get_contents( DATAFILE ) );
$times['read serial'] = microtime( true ) - $times['read serial'];

unlink( DATAFILE );

$data = '';

//db serialized
$times['insert db serialized'] = microtime( true );
$data = serialize( $lang );
$sql_query = 'INSERT INTO `bm2` ( `data` ) VALUES ('
."'$data' )";
$db->query( $sql_query )
or trigger_error( $db->error, E_USER_ERROR );
$times['insert db serialized'] = microtime( true ) - $times['insert db
serialized'];

$data = '';
$lang = array();

//get db serialized
$times['get db serialized'] = microtime( true );
if( !( $sql = $db->query( "SELECT `data` FROM `bm2` WHERE `id` = $db-
>insert_id" ) ) )
trigger_error( $db->error, E_USER_ERROR );
list( $data ) = $sql->fetch_row();
$lang = unserialize( $data );
$times['get db serialized'] = microtime( true ) - $times['get db
serialized'];

print_r( $times );
?>

The table looks like:
`bm2` (collation is utf-8)
`id` PRIMARY INT NOT NULL auto_increment
`data` TEXT

Apr 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Thiva Charanasri | last post by:
http://www.poweroflanguage.org Track: Computer Language 1st World Congress on the Power of Language: Theory, Practice and Performance Date: March 6 - 10, 2006 Bangkok, Thailand On this...
79
by: pinkfloydhomer | last post by:
I want to scan a file byte for byte for occurences of the the four byte pattern 0x00000100. I've tried with this: # start import sys numChars = 0 startCode = 0 count = 0
0
by: Thiva Charanasri | last post by:
http://www.poweroflanguage.org Track: Computer Language 1st World Congress on the Power of Language: Theory, Practice and Performance Date: March 6 - 10, 2006 Bangkok, Thailand On this...
2
by: James Tillery | last post by:
We have an App which has hundreds of ASP pages with thousands of labels and strings. We also sell this to all different countries. What we have done is to create a txt file with a number and text...
22
by: petermichaux | last post by:
Hi, I'm curious about server load and download time if I use one big javascript file or break it into several smaller ones. Which is better? (Please think of this as the first time the scripts...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
7
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already...
46
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.