Page 1 of 1

Use Language_Load server event to set footer text

Posted: Thu Mar 23, 2023 7:05 pm
by mfabbri71

I'm using phpmaker v2023.10. In editor I found Language_Load() public function. When generated in src/Language.php I found languageLoad() public function
The issue is that? Because this code is never applied...

  $footertext = getCopyYear();
  $this->setPhrase("footertext", $footertext);
 ....
 ....

The same code Work perfect in v2022
Where is the issue ?
Thanks


Re: Language_Load() or languageLoad() ... issue ?

Posted: Fri Mar 24, 2023 8:57 am
by mobhar

That is not the issue. PHPMaker will generate the function in the generated code becomes languageLoad(), even in the Editor Code of PHPMaker project its name is Language_Load().

As long as you have seen your code in the generated src/Language.php file, then it should work.

Make sure you have already put that getCopyYear() global function under Server Events -> Global -> All Pages -> Global Code.


Re: Language_Load() or languageLoad()?

Posted: Mon Mar 27, 2023 5:33 pm
by mfabbri71

The issue is in language.php I can't see the output generated by the function:

function GetCurrentCopyYear() {
   $output ="©";
   $copyYear= 2022;
   $curYear = date("Y");
   $output .= $copyYear.(($copyYear !=$curYear) ? "-".$curYear : "");
   $output .= " Università degli Studi della Tuscia - USIC - Ufficio Servizi Informatici di Comunicazione";
   return $output;
}

this is never applied:

// Language Load event
    public function languageLoad()
    {
        // Example:
        //$this->setPhrase("MyID", "MyValue"); // Refer to language file for the actual phrase id
        //$this->setPhraseClass("MyID", "fas fa-xxx ew-icon");
        // Refer to https://fontawesome.com/icons?d=gallery&m=free [^] for icon name
        $footertext = GetCurrentCopyYear();
        //$this->setPhrase("List","List");
        //$this->setPhrase("1","List");
            $this->setPhrase("footertext",$footertext);
        if (CurrentLanguageID() == "en" || CurrentLanguageID() == "us") {
        	$this->setPhrase("footertext",$footertext);
......
.....

Re: Language_Load() or languageLoad()?

Posted: Mon Mar 27, 2023 5:38 pm
by mobhar

mobhar wrote:

Make sure you have already put that getCopyYear() global function under Server Events -> Global -> All Pages -> Global Code.

It will be generated into src/userfn.php file, not src/Language.php file.


Re: Language_Load() or languageLoad()?

Posted: Mon Mar 27, 2023 6:16 pm
by mfabbri71

GetCurrentCopyYear() is in userfn.php


Re: Language_Load() or languageLoad()?

Posted: Mon Mar 27, 2023 7:26 pm
by mfabbri71

the code above is never applied. Instead is loaded the default string defined in lang/italian.xml
even if It is null.

// Language Load event
    public function languageLoad() {
        $footertext = GetCurrentCopyYear();
       $this->setPhrase("footertext",$footertext);
...
...

Re: Language_Load() or languageLoad()?

Posted: Mon Mar 27, 2023 10:06 pm
by arbei

mfabbri71 wrote:

if (CurrentLanguageID() == "en" || CurrentLanguageID() == "us") {
$this->setPhrase("footertext",$footertext);

If you are still checking "en" or "us", be reminded that the language IDs are changed, it should be, e.g. "en-US".


Re: Language_Load() or languageLoad()?

Posted: Tue Mar 28, 2023 8:39 am
by mobhar

So, simply change this code:

if (CurrentLanguageID() == "en" || CurrentLanguageID() == "us") {

to:

if (CurrentLanguageID() == "en-US") {

Re: Language_Load() or languageLoad()?

Posted: Fri Mar 31, 2023 6:18 pm
by mfabbri71

The issue is not the if statement. This is the code:

public function languageLoad()
{
        $footertext = GetCurrentCopyYear();
        $this->setPhrase("footertext",$footertext);
}

the custom phrase is never loaded.


Re: Language_Load() or languageLoad()?

Posted: Fri Mar 31, 2023 6:22 pm
by mobhar

You may post your latest/updated code for more discussion.


Re: Language_Load

Posted: Fri Mar 31, 2023 6:36 pm
by arbei

Be reminded that "footertext" is not a global phrase, it is a project phrase, so you need to use setProjectPhrase().


Re: Language_Load

Posted: Fri Mar 31, 2023 6:38 pm
by mfabbri71

Thanks mobhar but this is the latest update and I have the same issue.
It is loaded the phrase generated in lang/english.xml and lang/italian.xml
and not the custom phrases
Thanks


Re: Use Language_Load server event to set footer text

Posted: Fri Mar 31, 2023 6:41 pm
by mfabbri71

@arbel
you are right
wich are project phrases to look up ?
or where i can found these in documentation ?
Thanks


Re: Use Language_Load server event to set footer text

Posted: Fri Mar 31, 2023 7:57 pm
by arbei

Global phrases are those you find in the language files. Table/Field/Chart/Project phrases are those you set in the Multi-Language Property Editor.