NYCPHP Meetup

NYPHP.org

[nycphp-talk] automatic translation

Anirudh Zala xml at aumcomputers.com
Sat Apr 3 06:22:04 EST 2004


It is not really advisable to use Database for basic things like Static text
and Images where you can effectively use File system. Why do we need to
store all translations into DB? Suppose a 100 page website containing 50
lines in each page which is to be displayed in 40 languages, count how many
database queries you will need to generate to display for 1 connection only.
Even if you have proper load balancing applied to your website, it won't be
effective solution.

For multilingual websites, core problem is displaying Static text and Images
which should load dynamically according to selected language. While user
defined Data appear as it is. We had similar problem 4-5 years ago when we
started developing websites in PHP especially for European countries. And
everybody knows how many type of varieties in Languages available in those
countries there are. (We have been using Temple-pHp method which keeps GUI
and Logic separate.) We solved our problem in following way.

We stored all Static text, which we usually keep embedded with coding, into
separate Language files like "1.inc, 2.inc, 3.inc" which can be available in
any pHp script. While in coding we used variables of corresponding
text/words derived from those language files.

For example 1 file called welcome.php displays some word like "Hello" but
different words in different languages.

<?php echo "Hello"  ?>    //English
<?php echo "Hola"  ?>    //Spanish
<?php echo "Foo..."  ?>    //Some Foo language

But you know you need to configure your script in such a way that output
will be in different language. Hence extract language specific words from
your code and place them into 1.inc, 2.inc, 3.inc to N.inc in form of Array
values. Here 1,2, 3 to N you can set in form of variable (mostly as Session
Variable) for different languages and can include respective language file
in your code just like normal pHp code. See example of 1.inc, 2.inc ...
3.inc below.

<?php $cap[welcome]="Hello";  .....other words/texts/characters.......... ?>
//1.inc
<?php $cap[welcome]="Hola";  .....other words/texts/characters.......... ?>
//2.inc
<?php $cap[welcome]="Foo...";  .....other words/texts/characters..........
?>    //3.inc

Do not use separate variables for separate values, instead use Arrays,
otherwise your stock of variables in mind will exhaust quickly and it may be
possible that at the time of developing code you may not find any variables
to use :). Advantage of using Array is, you can properly control your all
language specific text/words/sentences if required, and some nasty user
can't manipulate your original variables by using browser's GET method.
(However, mostly it is not possible, but need to take care well) plus you
need not worry about unsetting them 1 by 1.

Hence, welcome.php becomes like below.

<?php

//Prints "Hello", "Hola" or "Foo" according to value of variable $LANG which
can be from 1 to N.
include_once $LANG.".inc";    //$LANG would be your Session/Cookie variable

echo $cap[welcome];

?>

You can apply same solution for displaying images dynamically as well. But
for that you need to store language specific images into separate folder
like by giving name like 1 2 and 3 and, same we used $LANG above, can
display images dynamically like below.

.... some code...

echo "<IMG SRC=\"PATH/..../$LANG/foo.gif\">";

.... some code...

There are many advantages of using above system like:

# As you keep language specific part separate from Code, you can
add/edit/modify your text very easily and you need not to worry abuts mix-up
of hard coded text and your code.

# Just give print out of your primary language to translator for different
languages and he/she can write *Effective* translation in his/her language
without any problem.

# You are avoiding valuable DB connections and consumption of lot of
processing power for displaying static text.

# This type of translation, as done by Human, gives you power to display
type of text/sentences/phrases of your choice without worrying of Computer
Assisted Translation (CAT) tools. Remember Machine level Translations can
never take place of Human Translations.

# You can add/remove as many languages as possible very quickly and in
effective manner.

Thanks

Anirudh Zala

----------------------------------------------------------------------------
--------------------------
Anirudh Zala (Project Manager),           Tel: +91 281 2451894
AUM Computers,                                Gsm: +91 9898 264911
317, Star Plaza,                                 anirudh at aumcomputers.com
Rajkot-360001, Gujarat, INDIA             http://www.aumcomputers.com
----------------------------------------------------------------------------
--------------------------

----- Original Message -----
From: <rinaudom at tiscali.it>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Friday, 02 April, 2004 5:11 PM
Subject: Re: [nycphp-talk] automatic translation


> You were pretty clear while explaining what you need.
> Once you are done with auto/manual translation (e.g. you got translated
> text), you may consider to use my GPL software, PanamaSuite
> (http://panamasuite.sourceforge.net/), which is REALLY useful in order to
> manage languages. This software assumes you already got translated text;
> it is ready for 40 preconfigured languages you can manage via the
> control-panel. All text is stored in database (MySQL for now); each text
> region is callable via a needle you define for it, e.g.:
> echo $panamasuite->getText('WELCOME_TEXT');
> where `WELCOME_TEXT' is the text displayed in the active language stored
> in session. Languages can be deactivated (when you still not have a ready
> translation), modified (modifying, for istance, the text direction, the
> code page, etc.) and created. Each needle you plan to insert in your PHP
> application must be mapped in database via the proper control panel. A
> `security filter' allows you to switch on/off some actions like
> delete/modify needle.
> Last version of PanamaSuite is 0.8.0 (Thu Feb 12 16:34:28 CET 2004).
> Let me know if you find it useful.
>
> Matteo Rinaudo
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>




More information about the talk mailing list