Custom language variables

My project uses various text strings to replace view values and tooltips in Row_Rendered events (and others).
Now I need to adapt my project for multilanguage use.I have looked at the multilanguage section of the help file, but didn’t see any information relating to making text strings work in multilanguage.

  • How and where should I create my own custom multilange variables?
  • Is there a way to add custom language variables to the multilanguage editor?
  • How do I then call the variables when customising RowRendered events and similar?
  1. You may simply use “Language_Load” server event to define your own language phrases, for example:

if (CurrentLanguageID() == “en”) {
$this->setPhrase(“QA_Title”, “Quick Actions”);
} else {
$this->setPhrase(“QA_Title”, “Aksi Cepat”);
}

  1. There is no feature to add custom language variables/phrases into Multi-Language Editor. All you need to do is by defining it just like explained in #1 above.
  2. To call your own defined language phrases above, then simply use, for example:

echo Language()->phrase(“QA_Title”);

Perfect - just what i needed
thank-you!

For ease of updating, always use language files rather than hard-coding phrases into a project.In your english.xml file put:
…and in your other language file(s) put:
Then, in the Language_Load() event, you simply need to add:
$this->setPhrase(Language()->Phrase(“QA_Title”));…and the correct text will be loaded from the current language file.

ah! so you CAN define custom naguage vars in the language file…
even better :slight_smile:

Be reminded, when you add the new phrases into the .xml language files, then you need to add thoses phrases into the .xml language files again each time the new version is released.

In other words, you may not add it into .xml language files, but simply define it from “Language_Load” server event.

Being a native English speaker, I’ve always felt that many of the default phrases needed “tweaking”, so I began by creating my own language file which I’ve extended as required through the last several versions of PHPM.I simply retain a copy of the latest default language file so that I can run a comparison when a new PHPM version is released (WinMerge is a good freeware utility for that) and update my working language file accordingly.On balance, it’s really doesn’t matter which approach you take - the only thing I would mention is that having all phrases in one place makes it much easier to apply changes. I originally fell into the trap of hard-coding words and phrases into project code because it seemed quicker / simpler …and then discovered what a nightmare it became to find every place that a particular term appeared when changes were needed.

Yes. It actually depends on our needs. I actually still use those both methods in many of my projects. First by defining the phrases only one place in “Language_Load”, and Second by adding the phrases into the .xml language files.Each of them has pros and cons. None of them is the best. Both should complement each other.

mobhar wrote:

To call your own defined language phrases above, then simply use, for example:
echo Language()->phrase(“QA_Title”);

Hi,I get the error “PHP Notice: Undefined variable: Language” when I apply the above example as follows.Server events: Page_DataRendering:$header = ‘

‘.$Language()->phrase(“QA_Title”).’

mavel wrote:

$header = ‘

‘.$Language()->phrase(“QA_Title”).’

You need to remove “$”.

It’s working.