Jon Erickson Posted August 12, 2018 Posted August 12, 2018 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();
Adriano Faria Posted August 12, 2018 Posted August 12, 2018 Try ... $lang = \IPS\Member::loggedIn()->language()->addToStack('perscom_text_tis') . \IPS\Member::loggedIn()->language()->parseOutputForDisplay( $lang ); ...
DawPi Posted August 12, 2018 Posted August 12, 2018 3 hours ago, Adriano Faria said: \IPS\Member::loggedIn()->language()->parseOutputForDisplay( $lang ); Whole big method to get one lang word phrase? I think it isn't best idea. get() would be enough.
KT Walrus Posted August 12, 2018 Posted August 12, 2018 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).
Jon Erickson Posted August 12, 2018 Author Posted August 12, 2018 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!
bfarber Posted August 13, 2018 Posted August 13, 2018 Just to clarify, the behavior here is for performance reasons. Rather than load ALL lanugage strings even if we don't need them, or querying each string as it is used, we store a stack of requested strings and fetch them all with one query at the end of page execution.
Martin A. Posted August 14, 2018 Posted August 14, 2018 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.
KT Walrus Posted August 14, 2018 Posted August 14, 2018 9 hours ago, Martin A. said: That is only for IN_DEV installations, and the correct syntax is "\IPS\Member::loggedIn()->language()->words". See \IPS\Lang::languageInit(). Thanks. I didn't know this was the case.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.