Re: Internationalizing pages

From: Lüpher Cypher (lupher.cypher_at_verizon.net)
Date: 09/23/04


Date: Thu, 23 Sep 2004 18:33:42 GMT

steve wrote:
> "Lpher_Cypher" wrote:
> > Tony Marston wrote:
> >
> > > "J.O. Aho" <user@example.net> wrote in message
> > > news:2r4p5gF15f3nuU1@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
>
> 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



Relevant Pages

  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.perl.misc)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.c)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.python)
  • whats OOPs jargons and complexities?
    ... in advanced languages such as LISP family, it is not uncommon to define ... subroutine f1 ... For example, in Java, a string is a class String. ...
    (comp.lang.lisp)
  • Re: OOs best feature survey results
    ... I would probably define a boolean "string" ... I LIKE dynamic languages. ...
    (comp.object)