?
avatar cheesegrits
cheesegrits
27 Jun 2018

Steps to reproduce the issue

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 ...

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 ...

Actual result

... is you get the untranslated FOO_BAR string.

System information (as much as possible)

3.8.10

Additional comments

The problem seems to stem from the cache workarounds ...

https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Cache/Cache.php#L529

... which calls setHeadData() in the document, which then does ...

https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Document/HtmlDocument.php#L257

And there's the problem. That line seems to assume you can set the language string to an already translated string, by doing JText::script($key, $string) ... but you can't ... that second arg is 'jsSafe', not a translated string. The translation happens inside JText::script(). And because we're doing this from the cache handler, the extension hasn't run, and its language isn't loaded. So a) we're passing a random 'jsSafe' value, and b) no translation.

As far as I can tell, there is no way to set a specific translated string, so the only way round this would be to add another method to JText, like JText::setScript($key, $string, ...) which does let you specify an already translated string to use.

Am I missing something obvious?

avatar cheesegrits cheesegrits - open - 27 Jun 2018
avatar joomla-cms-bot joomla-cms-bot - labeled - 27 Jun 2018
avatar cheesegrits
cheesegrits - comment - 27 Jun 2018

PS ... the only other workaround would seem to be for me to load all my language in the controller before I call the cache on my view ... but for my extension that is (very) problematic, because my views can load any number of other plugins, with their own language files. So I'd pretty much have to just give up on caching and always run my display().


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20903.
avatar cheesegrits cheesegrits - change - 27 Jun 2018
The description was changed
avatar cheesegrits cheesegrits - edited - 27 Jun 2018
avatar ggppdk
ggppdk - comment - 28 Jun 2018

@cheesegrits

please read discussion here:
#20843

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 2 Jul 2018

@cheesegrits can this Issue be closed?

avatar franz-wohlkoenig franz-wohlkoenig - change - 2 Jul 2018
Status New Information Required
avatar ggppdk
ggppdk - comment - 2 Jul 2018

Discussion in #20843 is related but it is not a fix for issue reported here

avatar Fedik
Fedik - comment - 4 Jul 2018

I had similar issue, but with script options. It hard to reproduce.
Yes, it somehow related to Cache "workaround",
which is ignore (or wrongly parse/interpret) <script type="application/json" class="joomla-script-options">.
I not often use the cache enabled, do not really had a time to debug.

I do not see how #20843 is related

avatar ggppdk
ggppdk - comment - 4 Jul 2018

@Fedik

yes #20843 does not try to fix any caching issues so the purpose of #20843 is not related

But the discussion in #20843, about the 2nd parameter is discussed and analyzed there

And there's the problem. That line seems to assume you can set the language string to an already translated string, by doing JText::script($key, $string) ... but you can't ... that second arg is 'jsSafe', not a translated string. The translation happens inside JText::script(). And because we're doing this from the cache handler, the extension hasn't run, and its language isn't loaded. So a) we're passing a random 'jsSafe' value, and b) no translation.

avatar Fedik
Fedik - comment - 4 Jul 2018

I guess need to debug how Cache "workaround" works for <script> and fix it for our options tag,
just need a brave man and a time :neckbeard:

avatar Fedik
Fedik - comment - 7 Jul 2018

please test #21007

avatar joomla-cms-bot joomla-cms-bot - change - 7 Jul 2018
Closed_Date 2018-07-07 08:02:18 2018-07-07 08:02:19
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 7 Jul 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 7 Jul 2018
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2018-07-07 08:02:18
Closed_By franz-wohlkoenig
avatar joomla-cms-bot
joomla-cms-bot - comment - 7 Jul 2018
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 7 Jul 2018

closed as having Pull Request #21007

Add a Comment

Login with GitHub to post a comment