Bug 18162 - Don't translate JSON keys
Summary: Don't translate JSON keys
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: I18N/L10N (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-23 10:11 UTC by Magnus Enger
Modified: 2017-05-04 14:07 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Magnus Enger 2017-02-23 10:11:08 UTC
Symptoms: 

When Swedish or Norwegian was selected as the interface language in the staff client, patron searches that were only returning a single result would redirect to /cgi-bin/koha/members/moremember.pl?borrowernumber=undefined, which of course gives the message "This patron does not exist. Find another patron?"

Cause: 

In koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt we have this: 

34                "dt_action":
35                    "<a href='/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% data.borrowernumber %]' class='btn btn-default btn-xs'><i class='fa fa-pencil'></i> Edit</a>",
36                "borrowernumber":
37                    "[% data.borrowernumber %]"
38            }[% UNLESS loop.last %],[% END %]

borrowernumber here is meant to be a key in some JSON data, but it had been translated, which means the JS in koha-tmpl/intranet-tmpl/prog/nb-NO/modules/members/member.tt that redirects when there is only one result could not find the borrowernumnber: 

196        // redirect if there is only 1 result.
197        if ( json.aaData.length == 1 ) {
198            var borrowernumber = json.aaData[0].borrowernumber;
199            document.location.href="/cgi-bin/koha/members/moremember.pl?borrowernumber="+borrowernumber;
200            return false;
201        }

In Pootle, the string that had been translated looks like this: 

", "borrowernumber": "%s" }%s,%s %s ] } %s %s %s%s%s %s%s%s %s%s%s %s %s 

Quick fix: 

Find the relevant string in *-staff-prog.po and untranslate it. 

Permanent fix: 

Is there some way to mark a string so it does not get picked up for translation? 

If not, perhaps it would make sense to rename borrowernumber here to something that is more obviously not meant to be translated? Why are the other keys in the JSON prefixed with dt_? Is there some special magic to it, or could we do the same for borrowernumber? 

Thanks to oha on #koha for nudging me in the right direction to figure this out.
Comment 1 Julian Maurice 2017-02-23 10:48:34 UTC
> Is there some way to mark a string so it does not get picked up for translation? 
In my opinion, it would be better to do the opposite: mark the strings that have to be translated, that would avoid the "%s" hell we have in some strings like this one and more generally that would prevent the translation to break things.

But to be practical, I think the right way to do it is to not return any html in this JSON. The rendering code can be put in DataTables configuration (mRender property). For an example usage of mRender, see bug 15219
Comment 2 Magnus Enger 2017-02-23 10:50:49 UTC
(In reply to Julian Maurice from comment #1)
> But to be practical, I think the right way to do it is to not return any
> html in this JSON.

Not sure I see how this would stop the string "borrowernumber" from being translated?
Comment 3 Julian Maurice 2017-02-23 10:56:08 UTC
(In reply to Magnus Enger from comment #2)
> (In reply to Julian Maurice from comment #1)
> > But to be practical, I think the right way to do it is to not return any
> > html in this JSON.
> 
> Not sure I see how this would stop the string "borrowernumber" from being
> translated?

Sorry for not being clear I was just about to write another comment to explain it better :)

By "not returning any html in this JSON" I also meant that we should not use Template::Toolkit to generate JSON. This way, its content won't go into PO files.
Comment 4 Magnus Enger 2017-02-23 12:20:32 UTC
(In reply to Julian Maurice from comment #3)
> By "not returning any html in this JSON" I also meant that we should not use
> Template::Toolkit to generate JSON. This way, its content won't go into PO
> files.

Yeah, that makes sense!
Comment 5 Jonathan Druart 2017-02-23 15:51:46 UTC
(In reply to Julian Maurice from comment #3)
> By "not returning any html in this JSON" I also meant that we should not use
> Template::Toolkit to generate JSON. This way, its content won't go into PO
> files.

The problem we have is that we want some strings to be translated, things like "Edit", "Delete", "Email", etc.
Comment 6 Julian Maurice 2017-02-23 16:20:34 UTC
(In reply to Jonathan Druart from comment #5)
> (In reply to Julian Maurice from comment #3)
> > By "not returning any html in this JSON" I also meant that we should not use
> > Template::Toolkit to generate JSON. This way, its content won't go into PO
> > files.
> 
> The problem we have is that we want some strings to be translated, things
> like "Edit", "Delete", "Email", etc.

You can do that in the template that make the DataTables call (using the mRender property)