473,465 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Internationalizing pages

Hi,
I'm writing a site in PHP with mySQL. I've decided to have it in several
languages, but don't want to use XML just yet. So, I was wondering if
anyone has done it before and have some ideas. :)
Basically, I've come up with this: create include files with error
messages/page text/etc. and define 2-dimensional arrays, say:

global $errors;
$errors = array("id_error1" => ("en" => "error in english",
"de" => "error in german",
"fr" => "error in french",
...
),
"id_error2" => ...
);

then define a function, say,

getLangText($array,$id) {
global $$array;
global $lang;
$msg = $$array[$id];
return $msg[$lang];
}

where $lang is a global variable containing locality string. So, if we
need error1, we'd call:

echo getLangText("errors","error1");

This would work, but I thought maybe someone has a more elegant solution :)

Thanks
Jul 17 '05 #1
7 1601
Lüpher Cypher wrote:
Hi,
I'm writing a site in PHP with mySQL. I've decided to have it in several
languages, but don't want to use XML just yet. So, I was wondering if
anyone has done it before and have some ideas. :)
Basically, I've come up with this: create include files with error
messages/page text/etc. and define 2-dimensional arrays, say:

global $errors;
$errors = array("id_error1" => ("en" => "error in english",
"de" => "error in german",
"fr" => "error in french",
...
),
"id_error2" => ...
);

then define a function, say,

getLangText($array,$id) {
global $$array;
global $lang;
$msg = $$array[$id];
return $msg[$lang];
}

where $lang is a global variable containing locality string. So, if we
need error1, we'd call:

echo getLangText("errors","error1");

This would work, but I thought maybe someone has a more elegant solution :)


What I had done, if I had done somethign similare would have been

create languges include files for each language, eg: lang_en.php lang_fi.php

In the langauge file, I would use defines for each error message.

Depending on what language is used, I would include that languages and use the
defines to get the error message you want.

IMHO this would be easier to handle and you get less ram used and a fraction
faster too.
//Aho
Jul 17 '05 #2

"J.O. Aho" <us**@example.net> wrote in message
news:2r*************@uni-berlin.de...
Lüpher Cypher wrote:
Hi,
I'm writing a site in PHP with mySQL. I've decided to have it in several
languages, but don't want to use XML just yet. So, I was wondering if
anyone has done it before and have some ideas. :)
Basically, I've come up with this: create include files with error
messages/page text/etc. and define 2-dimensional arrays, say:

global $errors;
$errors = array("id_error1" => ("en" => "error in english",
"de" => "error in german",
"fr" => "error in french",
...
),
"id_error2" => ...
);

then define a function, say,

getLangText($array,$id) {
global $$array;
global $lang;
$msg = $$array[$id];
return $msg[$lang];
}

where $lang is a global variable containing locality string. So, if we
need error1, we'd call:

echo getLangText("errors","error1");

This would work, but I thought maybe someone has a more elegant solution
:)


What I had done, if I had done somethign similare would have been

create languges include files for each language, eg: lang_en.php
lang_fi.php

In the langauge file, I would use defines for each error message.

Depending on what language is used, I would include that languages and use
the defines to get the error message you want.

IMHO this would be easier to handle and you get less ram used and a
fraction faster too.


I agree. Have a separate file for each language rather than a single file
for every language.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #3
Tony Marston wrote:
"J.O. Aho" <us**@example.net> wrote in message
news:2r*************@uni-berlin.de...
Lüpher Cypher wrote:
Hi,
I'm writing a site in PHP with mySQL. I've decided to have it in several
languages, but don't want to use XML just yet. So, I was wondering if
anyone has done it before and have some ideas. :)
Basically, I've come up with this: create include files with error
messages/page text/etc. and define 2-dimensional arrays, say:

global $errors;
$errors = array("id_error1" => ("en" => "error in english",
"de" => "error in german",
"fr" => "error in french",
...
),
"id_error2" => ...
);

then define a function, say,

getLangText($array,$id) {
global $$array;
global $lang;
$msg = $$array[$id];
return $msg[$lang];
}

where $lang is a global variable containing locality string. So, if we
need error1, we'd call:

echo getLangText("errors","error1");

This would work, but I thought maybe someone has a more elegant solution
:)


What I had done, if I had done somethign similare would have been

create languges include files for each language, eg: lang_en.php
lang_fi.php

In the langauge file, I would use defines for each error message.

Depending on what language is used, I would include that languages and use
the defines to get the error message you want.

IMHO this would be easier to handle and you get less ram used and a
fraction faster too.

I agree. Have a separate file for each language rather than a single file
for every language.


Ok, that makes sense :) The only drawback is that whenever I need to add
a string, I'll have to go through several files and may forget to update
one of them, as opposed to having them all in one file - I'll be
"forced" to update all strings :) The thing is, the site will consist of
several parts, only one of which will be shown, therefore I don't really
need to have one large file for all of them (I put the parts into
separate directories, since they are kind of "subsites" themselves) :)
Another problem with several files is looking up strings by id: when
they are in one file, I'll just have to find one id and I can make sure
the string is ok in all languages at once, with separate files I'll have
to look in several places :) I think that could be important if I add a
language that I don't really know (say, if someone provides a
translation for me) :)

Thanks
Jul 17 '05 #4
.oO(Lüpher Cypher)
I'm writing a site in PHP with mySQL. I've decided to have it in several
languages, but don't want to use XML just yet. So, I was wondering if
anyone has done it before and have some ideas. :)


Have a look at gettext.

http://www.php.net/gettext

Micha
Jul 17 '05 #5
"Lpher_Cypher" wrote:
Tony Marston wrote:
"J.O. Aho" &lt;us**@example.net&gt; wrote in message
news:2r*************@uni-berlin.de...

&nbsp;>>Lüpher Cypher wrote:
&nbsp;>>
&nbsp;&nbsp;>>>Hi,
&nbsp;&nbsp;>>>I'm writing a site in PHP with mySQL. I've
decided to have it in several
&nbsp;&nbsp;>>>languages, but don't want to use XML just yet.
So, I was wondering if
&nbsp;&nbsp;>>>anyone has done it before and have some ideas.
:)
&nbsp;&nbsp;>>>Basically, I've come up with this: create
include files with error
&nbsp;&nbsp;>>>messages/page text/etc. and define
2-dimensional arrays, say:
&nbsp;&nbsp;>>>
&nbsp;&nbsp;>>>global $errors;
&nbsp;&nbsp;>>>$errors = array("id_error1" =&gt; ("en" =&gt;
"error in english",
&nbsp;&nbsp;>>> "de" =&gt; "error in german",
&nbsp;&nbsp;>>> "fr" =&gt; "error in french",
&nbsp;&nbsp;>>> ...
&nbsp;&nbsp;>>> ),
&nbsp;&nbsp;>>> "id_error2" =&gt; ...
&nbsp;&nbsp;>>> );
&nbsp;&nbsp;>>>
&nbsp;&nbsp;>>>then define a function, say,
&nbsp;&nbsp;>>>
&nbsp;&nbsp;>>>getLangText($array,$id) {
&nbsp;&nbsp;>>> global $$array;
&nbsp;&nbsp;>>> global $lang;
&nbsp;&nbsp;>>> $msg = $$array[$id];
&nbsp;&nbsp;>>> return $msg[$lang];
&nbsp;&nbsp;>>>}
&nbsp;&nbsp;>>>
&nbsp;&nbsp;>>>where $lang is a global variable containing
locality string. So, if we
&nbsp;&nbsp;>>>need error1, we'd call:
&nbsp;&nbsp;>>>
&nbsp;&nbsp;>>>echo getLangText("errors","error1");
&nbsp;&nbsp;>>>
&nbsp;&nbsp;>>>This would work, but I thought maybe someone
has a more elegant solution
&nbsp;&nbsp;>>>:)
&nbsp;>>
&nbsp;>>What I had done, if I had done somethign similare
would have been
&nbsp;>>
&nbsp;>>create languges include files for each language, eg:
lang_en.php
&nbsp;>>lang_fi.php
&nbsp;>>
&nbsp;>>In the langauge file, I would use defines for each
error message.
&nbsp;>>
&nbsp;>>Depending on what language is used, I would include
that languages and use
&nbsp;>>the defines to get the error message you want.
&nbsp;>>
&nbsp;>>IMHO this would be easier to handle and you get less
ram used and a
&nbsp;>>fraction faster too.


I agree. Have a separate file for each language rather than

a single file
for every language.


Ok, that makes sense :) The only drawback is that whenever I
need to add
a string, I'll have to go through several files and may forget
to update
one of them, as opposed to having them all in one file - I'll
be
"forced" to update all strings :) The thing is, the site will
consist of
several parts, only one of which will be shown, therefore I
don't really
need to have one large file for all of them (I put the parts
into
separate directories, since they are kind of "subsites"
themselves) :)
Another problem with several files is looking up strings by
id: when
they are in one file, I'll just have to find one id and I can
make sure
the string is ok in all languages at once, with separate files
I'll have
to look in several places :) I think that could be important
if I add a
language that I don't really know (say, if someone provides a
translation for me) :)

Thanks


Your other option to keep things nicely synchronized (you have a valid
point there), is to create language tables in mysql, where every
column is for a different langugage. That way, things are nicely in
synch. There are no performance issues with mysql since mysql can
cache (by default) query results that are not changing.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Internat...ict151183.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=506567
Jul 17 '05 #6
Having worked on localisation projects in the past and being in the
process of writing a PHP/Smarty driven site in multiple languages, I
hope I can help.

I have indeed created what I call "language packs", each file a PHP with
an array of strings something like:

$strings = array(
"TEXT1" => "Text 1",
"TEXT2" => "Text 2",
"TEXT3" => "Text 3"
);

You can use a db approach (such as ACCESS) to manage the string
translation with an export function to produce automatically the
language packs on demand.

Using the strings array approach you can make your localisation text
available both to PHP code and to SMARTY code segments (using the ASSIGN
function to create an equivalent Smarty variable)

You should bear in mind though that INTERNATIONALISATION is not limited
the "translation" of words. If you wish to offer your PHP program to
various audiences around the world bear in mind that DATE and NUMBER
formats are different across the world and you will encounter complex
situations to manage when STORING, VIEWING and MANIPULATING data across
multiple data standards around the world. Rule number one, remember that
everything will be converted back into basic (anglo-saxon based) formats
(20040922, 12345690192.00 etc) for numbers and accents needed to be
handled carefully.

Hope this helps...

Jonathan
Jul 17 '05 #7
steve wrote:
"Lpher_Cypher" wrote:
> Tony Marston wrote:
>
> > "J.O. Aho" &lt;us**@example.net&gt; wrote in message
> > news:2r*************@uni-berlin.de...
> >

> &nbsp;>>Lüpher Cypher wrote:
> &nbsp;>>
> &nbsp;&nbsp;>>>Hi,
> &nbsp;&nbsp;>>>I'm writing a site in PHP with mySQL. I've
> decided to have it in several
> &nbsp;&nbsp;>>>languages, but don't want to use XML just yet.
> So, I was wondering if
> &nbsp;&nbsp;>>>anyone has done it before and have some ideas.
> :)
> &nbsp;&nbsp;>>>Basically, I've come up with this: create
> include files with error
> &nbsp;&nbsp;>>>messages/page text/etc. and define
> 2-dimensional arrays, say:
> &nbsp;&nbsp;>>>
> &nbsp;&nbsp;>>>global $errors;
> &nbsp;&nbsp;>>>$errors = array("id_error1" =&gt; ("en" =&gt;
> "error in english",
> &nbsp;&nbsp;>>> "de" =&gt; "error in german",
> &nbsp;&nbsp;>>> "fr" =&gt; "error in french",
> &nbsp;&nbsp;>>> ...
> &nbsp;&nbsp;>>> ),
> &nbsp;&nbsp;>>> "id_error2" =&gt; ...
> &nbsp;&nbsp;>>> );
> &nbsp;&nbsp;>>>
> &nbsp;&nbsp;>>>then define a function, say,
> &nbsp;&nbsp;>>>
> &nbsp;&nbsp;>>>getLangText($array,$id) {
> &nbsp;&nbsp;>>> global $$array;
> &nbsp;&nbsp;>>> global $lang;
> &nbsp;&nbsp;>>> $msg = $$array[$id];
> &nbsp;&nbsp;>>> return $msg[$lang];
> &nbsp;&nbsp;>>>}
> &nbsp;&nbsp;>>>
> &nbsp;&nbsp;>>>where $lang is a global variable containing
> locality string. So, if we
> &nbsp;&nbsp;>>>need error1, we'd call:
> &nbsp;&nbsp;>>>
> &nbsp;&nbsp;>>>echo getLangText("errors","error1");
> &nbsp;&nbsp;>>>
> &nbsp;&nbsp;>>>This would work, but I thought maybe someone
> has a more elegant solution
> &nbsp;&nbsp;>>>:)
> &nbsp;>>
> &nbsp;>>What I had done, if I had done somethign similare
> would have been
> &nbsp;>>
> &nbsp;>>create languges include files for each language, eg:
> lang_en.php
> &nbsp;>>lang_fi.php
> &nbsp;>>
> &nbsp;>>In the langauge file, I would use defines for each
> error message.
> &nbsp;>>
> &nbsp;>>Depending on what language is used, I would include
> that languages and use
> &nbsp;>>the defines to get the error message you want.
> &nbsp;>>
> &nbsp;>>IMHO this would be easier to handle and you get less
> ram used and a
> &nbsp;>>fraction faster too.
> >
> >
> > I agree. Have a separate file for each language rather than

> a single file
> > for every language.

>
> Ok, that makes sense :) The only drawback is that whenever I
> need to add
> a string, I'll have to go through several files and may forget
> to update
> one of them, as opposed to having them all in one file - I'll
> be
> "forced" to update all strings :) The thing is, the site will
> consist of
> several parts, only one of which will be shown, therefore I
> don't really
> need to have one large file for all of them (I put the parts
> into
> separate directories, since they are kind of "subsites"
> themselves) :)
> Another problem with several files is looking up strings by
> id: when
> they are in one file, I'll just have to find one id and I can
> make sure
> the string is ok in all languages at once, with separate files
> I'll have
> to look in several places :) I think that could be important
> if I add a
> language that I don't really know (say, if someone provides a
> translation for me) :)
>
> Thanks


Your other option to keep things nicely synchronized (you have a valid
point there), is to create language tables in mysql, where every
column is for a different langugage. That way, things are nicely in
synch. There are no performance issues with mysql since mysql can
cache (by default) query results that are not changing.


Well, that's exactly what I'm doing for content in db :)
Say, I have a news page so, I have a table:
table news (
....
text_en text ...
text_de text ...
)
and then I just use a function, say, get_db_text($row,$field,$lang)
which appends the language suffix to the field name :)

But then, I still think it's easier to maintain the page content (which
is not in db) through an include file, since if I need to edit something
I wouldn't have to deal with queries etc. :)

Lüph
Jul 17 '05 #8

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

Similar topics

1
by: Duke Hamacher | last post by:
My client has a laregly static web site in English only. I will be adding e-commerce functionality shortly. Therefore, I am seeking an approach to allow users to select a language to view the...
2
by: skura | last post by:
I am trying to understand how the data in sql server is stored and also regarding fill factor and page splitting. 1) My first question what is the difference between Index pages and Data pages....
12
by: Sunny | last post by:
Hi, I need to download some web pages from a web server (most of them are not static html, but .asp pages). The content (I.e. the pure html) in the pages are not changed very often, so I'll...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
17
by: Rob R. Ainscough | last post by:
Again another simple concept that appears NOT to be intuitive or I'm just stupid. I've read the WROX book and the example doesn't actually show how the .master page links in the other content...
6
by: Konstantin Andreev | last post by:
Hello, all. Let the tablespace SY810T4K is almost full: --------------- db2 =list tablespaces show detail ... Name = SY810T4K Type = Database managed space Contents...
11
by: =?Utf-8?B?UGV0ZXIgSw==?= | last post by:
I am working with Visual Studio or alternately with Expression Web. I need to create about 50 aspx pages with about 1200 thumbnali images, typically arranged in three to four groups per page,...
1
by: deshaipet | last post by:
Hi friends - I created a automatic storage tablespace with a pagesize of 16 K and initial size of 64 MB. create large tablespace test_tbsp1 pagesize 16k managed by automatic storage autoresize...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.