Ticket #2584 (closed defect: fixed)

Opened 7 months ago

Last modified 2 months ago

<% _t() %> gets wrong filename namespace in includes

Reported by: ischommer Owned by: ischommer
Priority: medium Milestone: 2.3.1
Component: i18n Version: 2.2.2
Severity: medium effort / impact Keywords:
Cc: sminnee, mpeel Hours:

Description

<% _t() %> gets wrong filename namespace in includes, which essentially means you can't use translation in template includes. Example:

Outer.ss

<% _t('A') %>
<% include Inner %>

Inner.ss

<% _t('B') %>

Parsed in SSViewer into:

<% _t('A') %>
<% _t('B') %>

Which means the "B" entity is looked up under $langde_DE?Outer.ss?B? in the lang table, rather than the correct $langde_DE?Inner.ss?B?. i18n::textcollector() parses includes separately, so the master entity table has the right namespace ($langen_US?Inner.ss?B?).

As includes can be used in many templates, we can't adjust textcollector - even if we could pull it off, we'd get duplicate entities all over the place. The only solution i see is adjusting SSViewer to store compiled includes separately and use PHP include() statements in the outer templates- sam, what do you think?

Attachments

SSViewer_patch_include.diff (2.9 kB) - added by adiwidjaja 4 months ago.
Possible patch to solve this issue.

Change History

Changed 7 months ago by sminnee

I agree that SSViewer needs to be updated.

Setting aside the fact that a "complete rewrite of SSViewer" has been discussed for the last 6 months, here's a relatively simple solution:

Currently includes are processed by inlining SSViewer::getTemplateContent(). If we updated them to inline SSViewer::parseTemplateContent(), this issue would be fixed.

Alternatively, includes could be processed by actually executing a separate compiled include file. This would mean that you don't need to ?flush=1 to recache the template when you've only edited the included file, which would also be nice.

We'd need to be careful that the template's state variables were preserved properly when execution was handed off to the include.

  • Included execution shouldn't push to SSViewer::$topLevel, because that would break the semantics of what Top is.
  • Requirements shouldn't be inserted into an included template
  • # links shouldn't be corrected

In fact, pretty much everything from {{SSViewer::process()}} should be ignored. It would be whittled down to:

// Determine $cacheFile
include($cacheFile);
return $val;

Changed 4 months ago by adiwidjaja

Possible patch to solve this issue.

Changed 2 months ago by sminnee

  • priority changed from critical to medium
  • milestone set to 2.3.1

Changed 2 months ago by ischommer

  • status changed from new to closed
  • resolution set to fixed

This has been fixed in a different way: You can (and should) explicitly define your namespaces in all template code and includes now. See r65361. Thanks for your patch, Andy - the TemplateHelper? class might be useful in a rewrite effort - although that will probably happen on a larger scale anyway.

Note: See TracTickets for help on using tickets.