lots of variables and speed?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shenron

    lots of variables and speed?

    Hello,

    I'm trying to translate my website in some languages, therefore I
    include a file which contains all words. This is something like that:

    $hello_english= "Hello"; in lang_en.php
    $hello_francais ="Salut"; in lang_fr.php
    $hello_deutch=" Heil"; in lang_de.php
    ....

    So my file contains more 1000 lines with a new variable per line. Do
    you know another method? I'm afraid of losing speed with this method.

    What's your opinion?

    Best Regards,
  • Michael Fesser

    #2
    Re: lots of variables and speed?

    .oO(Shenron)
    [color=blue]
    >I'm trying to translate my website in some languages, therefore I
    >include a file which contains all words. This is something like that:
    >
    >$hello_english ="Hello"; in lang_en.php
    >$hello_francai s="Salut"; in lang_fr.php
    >$hello_deutch= "Heil"; in lang_de.php
    >...
    >
    >So my file contains more 1000 lines with a new variable per line. Do
    >you know another method?[/color]

    I would probably use gettext.



    Micha

    Comment

    • neur0maniak

      #3
      Re: lots of variables and speed?

      Shenron wrote:
      [color=blue]
      > Hello,
      >
      > I'm trying to translate my website in some languages, therefore I
      > include a file which contains all words. This is something like that:
      >
      > $hello_english= "Hello"; in lang_en.php
      > $hello_francais ="Salut"; in lang_fr.php
      > $hello_deutch=" Heil"; in lang_de.php
      > ....
      >
      > So my file contains more 1000 lines with a new variable per line. Do
      > you know another method? I'm afraid of losing speed with this method.
      >
      > What's your opinion?
      >
      > Best Regards,[/color]

      My methods of translation have involved a database, so I can use the
      query to choose language and refine the search to a specific page.

      From the query I'd build an array..

      Table could look something like this (though I'd extend it to use
      another table for listed languages, and pages, and link them)

      |----------|------|------------|-----------------|
      | language | page | tag | text |
      |----------|------|------------|-----------------|
      | english | home | hello | Hello |
      | french | home | hello | Salut |
      | dutch | home | hello | Heil |
      |----------|------|------------|-----------------|

      Then in the code use something like this:

      $dbO = mysql_query("SE LECT * FROM language_text WHERE language =
      'english' AND page = 'home'");

      $lang = Array();
      while ($dbR = mysql_fetch_arr ay($dbO)) {
      $lang[$dbR['tag']] = $dbR['text'];
      }

      then when using the translated text, just access it by using:
      $lang['hello']


      Comment

      • Chung Leong

        #4
        Re: lots of variables and speed?

        "Shenron" <cyril@aceboard .net> wrote in message
        news:dce67b33.0 407211057.13349 f91@posting.goo gle.com...[color=blue]
        > Hello,
        >
        > I'm trying to translate my website in some languages, therefore I
        > include a file which contains all words. This is something like that:
        >
        > $hello_english= "Hello"; in lang_en.php
        > $hello_francais ="Salut"; in lang_fr.php
        > $hello_deutch=" Heil"; in lang_de.php
        > ...
        >
        > So my file contains more 1000 lines with a new variable per line. Do
        > you know another method? I'm afraid of losing speed with this method.
        >
        > What's your opinion?
        >
        > Best Regards,[/color]

        As Michael suggested, Gettext is the more robust approach.

        Using variables isn't too bad. I wouldn't worry about speed all that much.
        PHP can comfortably parse files with thousands of lines. It probably makes
        more sense to use the same variable name across languages, then include the
        lang_xx.php of the language requested by the user.


        Comment

        • steve

          #5
          Re: Re: lots of variables and speed?

          "Chung Leong" wrote:[color=blue]
          > "Shenron" <cyril@aceboard .net> wrote in message
          > news:dce67b33.0 407211057.13349 f91@posting.goo gle.com...[color=green]
          > > Hello,
          > >
          > > I’m trying to translate my website in some languages,[/color]
          > therefore I[color=green]
          > > include a file which contains all words. This is something like[/color]
          > that:[color=green]
          > >
          > > $hello_english= "Hello"; in lang_en.php
          > > $hello_francais ="Salut"; in lang_fr.php
          > > $hello_deutch=" Heil"; in lang_de.php
          > > ...
          > >
          > > So my file contains more 1000 lines with a new variable per line.[/color]
          > Do[color=green]
          > > you know another method? I’m afraid of losing speed with[/color]
          > this method.[color=green]
          > >
          > > What’s your opinion?
          > >
          > > Best Regards,[/color]
          >
          > As Michael suggested, Gettext is the more robust approach.
          >
          > Using variables isn’t too bad. I wouldn’t worry about
          > speed all that much.
          > PHP can comfortably parse files with thousands of lines. It[/color]
          probably[color=blue]
          > makes
          > more sense to use the same variable name across languages, then
          > include the
          > lang_xx.php of the language requested by the user.[/color]

          A lot of scripts use the conditional include of different language
          files. Take a look at phpbb which supports quite a few languages.
          You may, in fact, want to borrow their language files-- I am sure, a
          lot of what you want to do is already covered there.

          --
          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-lots-var...ict131912.html
          Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=440653

          Comment

          Working...