]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/bugs/Re-use_translated_content_instead_of_skipping_if_previously_translated/20180628-patch.txt
update for rename of todo/Re-use_translated_content_instead_of_skipping_if_previously...
[git.ikiwiki.info.git] / doc / bugs / Re-use_translated_content_instead_of_skipping_if_previously_translated / 20180628-patch.txt
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.
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.
10 For example, given a `index.mdwn` containing:
12     \[[!inline pages="inline" raw="yes"]]
13     \[[!inline pages="inline" raw="yes"]]
15 .. and an `index.de.po` of:
17     msgid "\[[!inline pages=\"inline\" raw=\"yes\"]]\n"
18     msgstr "\[[!inline pages=\"inline.de\" raw=\"yes\"]]\n"
20 .. together with an `inline.mdwn` of:
22    This is inlined content.
24 .. and an `inline.de.po` of:
26     msgid "This is inlined content."
27     msgstr "This is German inlined content."
29 .. would result in the following translation:
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.
37 .. instead of, of course:
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(-)
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