po: Add failing test for Debian bug #911356
[ikiwiki] / doc / todo / Re-use_translated_content_instead_of_skipping_if_previously_translated.mdwn
1     From: Chris Lamb <lamby@debian.org>
2     Date: Thu, 28 Jun 2018 19:30:15 +0100
3     Subject: [PATCH] Re-use translated content instead of skipping if previously
4      translated.
5     
6     This fixes an issue where an initial `inline` directive would be translated
7     correctly, but subsequent inlines of the same would result in the raw
8     contents of the `.po` file being inserted into the page instead.
9     
10     For example, given a `index.mdwn` containing:
11     
12         \[[!inline pages="inline" raw="yes"]]
13         \[[!inline pages="inline" raw="yes"]]
14     
15     .. and an `index.de.po` of:
16     
17         msgid "\[[!inline pages=\"inline\" raw=\"yes\"]]\n"
18         msgstr "\[[!inline pages=\"inline.de\" raw=\"yes\"]]\n"
19     
20     .. together with an `inline.mdwn` of:
21     
22        This is inlined content.
23     
24     .. and an `inline.de.po` of:
25     
26         msgid "This is inlined content."
27         msgstr "This is German inlined content."
28     
29     .. would result in the following translation:
30     
31         This is the inlined content.
32         # SOME DESCRIPTIVE TITLE
33         # Copyright (C) YEAR Free Software Foundation, Inc.
34         # This file is distributed under the same license as the PACKAGE package.
35         # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
36     
37     .. instead of, of course:
38     
39         This is the inlined content.
40         This is the inlined content.
41     ---
42      IkiWiki/Plugin/po.pm | 15 +++++++++------
43      1 file changed, 9 insertions(+), 6 deletions(-)
44     
45     diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
46     index 418e8e58a..ecd1f5499 100644
47     --- a/IkiWiki/Plugin/po.pm
48     +++ b/IkiWiki/Plugin/po.pm
49     @@ -303,9 +303,12 @@ sub filter (@) {
50         my $page = $params{page};
51         my $destpage = $params{destpage};
52         my $content = $params{content};
53     -   if (istranslation($page) && ! alreadyfiltered($page, $destpage)) {
54     -           $content = po_to_markup($page, $content);
55     -           setalreadyfiltered($page, $destpage);
56     +   if (istranslation($page)) {
57     +           if (!defined(alreadyfiltered($page, $destpage))) {
58     +                   $content = po_to_markup($page, $content);
59     +                   setalreadyfiltered($page, $destpage, $content);
60     +           }
61     +           $content = alreadyfiltered($page, $destpage);
62         }
63         return $content;
64      }
65     @@ -747,15 +750,15 @@ sub myisselflink ($$) {
66                 my $page=shift;
67                 my $destpage=shift;
68      
69     -           return exists $filtered{$page}{$destpage}
70     -                    && $filtered{$page}{$destpage} eq 1;
71     +           return $filtered{$page}{$destpage};
72         }
73      
74         sub setalreadyfiltered($$) {
75                 my $page=shift;
76                 my $destpage=shift;
77     +           my $content=shift;
78      
79     -           $filtered{$page}{$destpage}=1;
80     +           $filtered{$page}{$destpage}=$content;
81         }
82      
83         sub unsetalreadyfiltered($$) {
84     -- 
85     2.18.0
86     
87 [[!tag patch]]
88
89 > Thank you Chris! I've reviewed the patch (with my "original author of the po plugin" hat on) and it looks good to me. I'm not 100% sure about `alreadyfiltered` being the best name for something that's not a predicated anymore but it's good enough. Then I wore my end-user hat and confirmed that with Chris' patch applied, the reproducer we had for this bug at Tails works fine. So IMO we're good to go and I recommend to apply this patch. Thanks in advance! -- [[intrigeri]]
90
91
92 > Any update on getting this merged? — [[lamby]], Fri, 24 Aug 2018 12:36:37 +0200
93
94 > Indeed, would love to see this merged! What might be the next steps here? — [[lamby]],  Thu, 18 Oct 2018 17:57:37 -0400
95
96 > I've filed this in Debian GNU/Linux at https://bugs.debian.org/911356 — [[lamby]], Thu, 18 Oct 2018 20:18:58 -0400
97
98 >> As I said on the Debian bug, I think we badly need test coverage for
99 >> this sort of thing, otherwise it *will* regress. The po plugin is
100 >> relatively complicated and hooks into lots of places in ikiwiki,
101 >> and I don't think any of the active ikiwiki maintainers use it
102 >> themselves, which means it can easily break (or have pre-existing
103 >> bugs) without anyone realising.
104 >>
105 >> For now I've added a failing test-case for this particular bug.
106 >> I'll try to review this soon and understand the po plugin, the patch,
107 >> why the bug exists and why the patch fixes it. --[[smcv]]