Jump to content

addToStack lang returning md5 hashes


Jon Erickson

Recommended Posts

Thought I'd turn to here since I can't quite figure out why this keeps happening, but when trying to insert language into one of my objects using addToStack method, seen in the 'text' property, I am returned with the md5 hashes of the lang key rather than the language that is defined in my lang.php. It also occurs in the formatInterval method - the string that is returned is a md5 hash. However, if I use get(), I can retrieve the language strings defined in lang.php. Anyone know why this is happening? Is it because it is not apart of the output stack? Thanks!

 

// Add the service record
$record = new \IPS\perscom\Records\ServiceRecord;
$record->date = time();
$record->soldier = $soldier->id;
$record->text = \IPS\Member::loggedIn()->language()->addToStack('perscom_text_tis') . \IPS\DateTime::formatInterval( \IPS\DateTime::create()->diff( $oldenlistment, TRUE ) );
$record->document = 0;
$record->save();

 

Link to comment
Share on other sites

If you want to store the translated text in your text column, use:

$record->text = \IPS\Member::loggedIn()->words['perscom_text_tis']

If you want to store a language key for later translation into the user's language, use:

$record->text = 'perscom_text_tis';

The reason the addToStack() method returns an MD5 is that the MD5 represents a unique key into the language stack. When the page is parsed for output, the MD5 keys are replaced with the text stored in the language stack. As @Adriano Faria replied, you can take the MD5 key and call the parseOutputForDisplay() method to retrieve the text stored in the language stack, if that is what you want. Note that it would be better if you added the whole text, including time interval to the language stack because the time interval could be inserted in the middle of the text and not simply appended to the text (making the text translatable into other languages where the interval would better be inserted somewhere else in the text).

Link to comment
Share on other sites

I would use get() if I could, but I am trying to store the date interval text returned from formatInterval(). It's an IPS definition that uses addToStack. I guess the better option would be to store the language string, then parse it when outputted as KT has said. Thanks for the answers. The parseOutForDisplay() is what I was looking for!

Link to comment
Share on other sites

On 8/12/2018 at 3:50 PM, KT Walrus said:

If you want to store the translated text in your text column, use:


$record->text = \IPS\Member::loggedIn()->words['perscom_text_tis']

If you want to store a language key for later translation into the user's language, use:

 

That is only for IN_DEV installations, and the correct syntax is "\IPS\Member::loggedIn()->language()->words". See \IPS\Lang::languageInit().
$words would only be populated with word keys from the outputStack, with their unique ID instead of the translated text.

image.png.7174e71c8908514b1b3901dad2840922.png

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...