Constants or variables

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

    Constants or variables

    I am translating an existing script into another human language. I am
    putting all human language stuff in one file.
    At the moment I use constants in the following way:

    <?php
    define("LNG_Cha nges_saved_OK", "Changes saved OK");
    define("LNG_Del ete_Are_you_sur e", "Delete: Are you sure???");
    ?>

    It is not too late yet to change to variables (array of strings) like this:

    <?php
    $lng["Changes_saved_ OK"]="Changes saved OK";
    $lng["Delete_Are_you _sure"]="Delete: Are you sure???";
    ?>

    What is better and why? Are there alternative ways of doing this and why
    would they be better? Please consider in your answer things like server
    load, memory usage and speed etc.





  • Guillaume Brocker

    #2
    Re: Constants or variables

    René wrote:
    [color=blue]
    > I am translating an existing script into another human language. I am
    > putting all human language stuff in one file.
    > At the moment I use constants in the following way:
    >
    > <?php
    > define("LNG_Cha nges_saved_OK", "Changes saved OK");
    > define("LNG_Del ete_Are_you_sur e", "Delete: Are you sure???");
    > ?>
    >
    > It is not too late yet to change to variables (array of strings) like this:
    >
    > <?php
    > $lng["Changes_saved_ OK"]="Changes saved OK";
    > $lng["Delete_Are_you _sure"]="Delete: Are you sure???";
    > ?>
    >
    > What is better and why? Are there alternative ways of doing this and why
    > would they be better? Please consider in your answer things like server
    > load, memory usage and speed etc.[/color]

    Have you already looked at *GNU gettext* ? You may check the followings:
    <http://fr3.php.net/manual/en/ref.gettext.php >
    <http://www.gnu.org/directory/gettext.html>
    <http://poedit.sourcefo rge.net/>

    --
    Guillaume Brocker

    Comment

    • René

      #3
      Re: Constants or variables

      Gettext is not installed on my server and it would be a complicated
      procedure to get this done. But thanks for the tip.

      René
      [color=blue]
      > Have you already looked at *GNU gettext* ? You may check the followings:
      > <http://fr3.php.net/manual/en/ref.gettext.php >
      > <http://www.gnu.org/directory/gettext.html>
      > <http://poedit.sourcefo rge.net/>
      >
      > --
      > Guillaume Brocker[/color]


      Comment

      • Chung Leong

        #4
        Re: Constants or variables

        Constants have the advantage of having global scope. On the other handle you
        can't interpolate a constant into a string. In terms of performance there's
        little different between the two, since both involves a hash lookup.

        Uzytkownik "René" <anonymous@nosp am.info> napisal w wiadomosci
        news:c2pg4l$su0 $1@news.ya.com. ..[color=blue]
        > I am translating an existing script into another human language. I am
        > putting all human language stuff in one file.
        > At the moment I use constants in the following way:
        >
        > <?php
        > define("LNG_Cha nges_saved_OK", "Changes saved OK");
        > define("LNG_Del ete_Are_you_sur e", "Delete: Are you sure???");
        > ?>
        >
        > It is not too late yet to change to variables (array of strings) like[/color]
        this:[color=blue]
        >
        > <?php
        > $lng["Changes_saved_ OK"]="Changes saved OK";
        > $lng["Delete_Are_you _sure"]="Delete: Are you sure???";
        > ?>
        >
        > What is better and why? Are there alternative ways of doing this and why
        > would they be better? Please consider in your answer things like server
        > load, memory usage and speed etc.
        >
        >
        >
        >
        >[/color]


        Comment

        Working...