how do you translate news blocks?

ding
2009-09-04
2013-05-29
  • ding
    ding
    2009-09-04

    silly question but:

    how do you translate news blocks?

     
    • Gerry Kroll
      Gerry Kroll
      2009-09-05

      Not at all a silly question.

      The simple answer is:  "you can't do this directly".

      Complex answer:  You need to create a series of language variables in the "languages/extra.xx.php" file for each of the languages your site supports, and then reference these language variables in the title and text areas of each news item.  You need a language variable for each title, and you need a different variable for each text.

      That way, when the user selects a new language, the appropriate text for that language will be loaded and then used.

       
      • ding
        ding
        2009-09-05

        just to be clear, I would need one title and variable per news entry?

         
    • Gerry Kroll
      Gerry Kroll
      2009-09-05

      Correct.

      Each "languages/extra.xx.php" file would look something like this:

      <?php
      $pgv_lang["myTitle01"] = "some news title";
      $pgv_lang["myText01"] = "some news text";
      $pgv_lang["myTitle02"] = "another news title";
      $pgv_lang["myText02"] = "another news text";
      ?>

      You'd reference the current value of the variable in either the title area or the text area thus:
      #pgv_lang[myTitle01]#  .  Inside the paired # characters you mention the language variable whose value should appear in its place.

      Note that the "languages/extra.xx.php" file behaves differently from other language files.  Normally, when a given language variable doesn't exist in a given language, the English value will be used.  In the case of these "language/extra.xx.php" files, the English value will NOT be used, unless you happen to choose a variable name that exists in the regular English files.

      If you choose names such as $pgv_lang["myTitle01"] you should be safe -- these definitely DO NOT exist, and never will.  If you want to be absolutely sure (not really necessary), you can use your name in place of the "my".

      The disadvantage of using this method is that you need to maintain not only the actual News block but also the various "languages/extra.xx.php" files.  You'll find that eventually this will become too much of a nuisance.