Skip to content

Remove indenting within compiled templates#29

Merged
abw merged 1 commit into
cpan-authors:masterfrom
mysociety:master
Jan 8, 2014
Merged

Remove indenting within compiled templates#29
abw merged 1 commit into
cpan-authors:masterfrom
mysociety:master

Conversation

@dracos
Copy link
Copy Markdown
Contributor

@dracos dracos commented Sep 4, 2013

If a template contains a multiline string, within for example a call to a Locale::gettext template function for translation, then the compiled version of the string written to the compiled template file will contain extra indent whitespace due to the regular expressions within the as_perl() function. For example, the template fragment:

[% loc("This is a
multiline string.") %]

will be written to the compiled file as something like (note indentation):

Template::Document->new({
...
    BLOCK => sub {
...
        eval { BLOCK: {
...
    $output .=  $stash->get(['loc', [ 'This is a
    multiline string.' ]]);

This means that - once a compiled template is loaded in, after say a server restart - the translation stops working because the original string does not exactly match the translation string.

The indentation appears to be optional, and is only within compiled template files, so this commit simply removes it.

If a template contains a multiline string, within for example a call to
a Locale::gettext template function for translation, then the compiled
version of the string written to the compiled template file will contain
extra indent whitespace due to the regular expressions within the
as_perl() function. For example, the template fragment:

[% loc("This is a
multiline string.") %]

will be written to the compiled file as something like

    $output .=  $stash->get(['loc', [ 'This is a
    multiline string.' ]]);

This means that - once a compiled template is loaded in, after say a
server restart - the translation stops working because the original
string does not exactly match the translation string.

The indentation appears to be optional, and is only within compiled
template files, so this commit simply removes it.
abw added a commit that referenced this pull request Jan 8, 2014
Remove indenting within compiled templates
@abw abw merged commit 34138b4 into cpan-authors:master Jan 8, 2014
djzort pushed a commit to openlocal/fixmystreet that referenced this pull request Apr 3, 2014
Embed a local copy of Template::Document, which includes the change
of cpan-authors/Template2#29 so that multiline
quoted strings within a template are not indented and thus stop
translating.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants