It's difficult to give a test case for this, so I just wanted to get a sanity check before creating a test case and submitting a PR.
The problem is ... in an extension with cacheable views, if you add JS language strings with ...
JText::script('FOO_BAR');
The expected result ...
... is that when your view loads from cache, you still have your translated strings in Joomla.JText in the Javascript.
But the actual result ...
.. is you get the untranslated FOO_BAR string.
Joomla 4.3.4
If turn off cache features, then string loading right. First time string can be loaded, but after refresh page string will be missed in joomla.jtext array.
Labels |
Added:
No Code Attached Yet
|
Standart System Cache -> ON - Conservative caching
Platform Specific Caching - OFF
First test:
Cache Handler - File
Second test:
Cache Handler - Redis
Both fail?
Both fail?
Yes, same problem in both variants. I checked hosting version, then local server backup version. Same result in 2 different servers - text without translation. If I'm turning off "Standart System Cache" then all working right - I have translated JavaScript strings.
I can replicate this. Here were my steps:
Conservative
\Joomla\CMS\Language\Text::script('MOD_MENU_FIELD_TAG_ID_LABEL');
Joomla.Text._('MOD_MENU_FIELD_TAG_ID_LABEL')
and got back MOD_MENU_FIELD_TAG_ID_LABEL
Worth noting that the cached file contains the translated strings but those are not added to the JSON object thus not available in the browser:
Labels |
Added:
bug
|
Interesting, Script Options works as expected, and Text not, but it also part of ScriptOptions.
To reproduce use following PHP, in components/com_content/src/View/Article/HtmlView.php
in display()
:
Text::script('JYES');
$this->document->addScriptOptions('yes', 'Yes');
$this->document->getWebAssetManager()
->addInlineScript('console.log(Joomla.getOptions("yes", "nope") + " " + Joomla.Text._("JYES", "Nope"))', [], ['type' => 'module']);
And check browser console:
Expected: Yes Yes
After cache enabled:
First request: Yes Yes
All following requests: Yes Nope
Which merge do you mean?
Called here:
It already use array_replace_recursive
I do not find problem in mergeHeadData()
it do not called for me, at all.
Hovewer setHeadData()
set all corectly, and then all gone.
Ah, I know, it do not restore Text::$strings
, it stay empty,
and any further call of Text::script()
, override everything in scriptOptions.
hmhm
I think the mergeHeadData
needs also the code for passing the text to script options:
joomla-cms/libraries/src/Document/HtmlDocument.php
Lines 167 to 170 in 17585ed
Nope, that should be deleted in future, it not in use.
I have some ideas, need to test.
It just a trash in the cache, it not used later ?
You can ignore that. I will do some test and will make a PR.
If I right, the probblem in the Text class.
I'll bet my money here:
joomla-cms/libraries/src/Cache/Cache.php
Line 496 in 17585ed
How much? ?
100 EUR ?
I will send you my Bank account info ?
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-09-01 15:57:06 |
Closed_By | ⇒ | Fedik |
How are you creating the cached pages?