Repository: mdn/kuma

Issue:
Macro search results are mangled for non-en-US locales
See for example https://wiki.developer.mozilla.org/en-US/search?locale=*&kumascript_macros=WebExtAllExamples&topic=none

This lists all pages that call WebExtAllExamples, across all locales. One entry looks like:

<img width="893" alt="Screen Shot 2019-11-21 at 4 30 25 PM" src="https://user-images.githubusercontent.com/432915/69387936-3e5d4780-0c7c-11ea-9347-5916d638d12d.png">

This is the German translation of the https://wiki.developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Examples page.

But the first link, "**Beispiele für Erweiterungen**", has the en-US locale in the URL, like this: https://wiki.developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Beispiele - note the translated slug but the en-US locale. If I click it, I get "Create a new page", because that page doesn't exist.

After the short description, the entry is supposed to have "`${url} Score: 82.20941 translated from ${original}`, where `url` is the localized page, and `original` is the en-US version. But these are wrong too:

* `url`: https://wiki.developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Beispiele - nonexistent page with en-US locale but de slug
* `original`: https://developer.mozilla.org/de/docs/Mozilla/Add-ons/WebExtensions/Beispiele - the proper value for `url`

 I've seen some cases where the "`${url} Score: 82.20941 translated from ${original}` bit doesn't appear, and then there is no usable link to the actual page, and I have to guess what the locale is, to be able to fix the link.




Discussion:
Seems suspiciously so for all locales in general:
<img width="930" alt="Screen Shot 2019-11-22 at 10 11 26 AM" src="https://user-images.githubusercontent.com/26739/69437073-90e84380-0d10-11ea-8a11-5a095dd60897.png">


You can actually reproduce it with: https://wiki.developer.mozilla.org/en-US/search?locale=*
One of the first-page search results is this:
<img width="1011" alt="Screen Shot 2019-11-22 at 10 15 45 AM" src="https://user-images.githubusercontent.com/26739/69437326-1a981100-0d11-11ea-879f-723273691027.png">

This makes it basically impossible to kill macros in many cases, since given search results like https://wiki.developer.mozilla.org/en-US/search?locale=*&kumascript_macros=Preferences_System_TOC&topic=none we can't see which pages actually call the macros :(.
Yay! I can reproduce. 
<img width="1083" alt="Screen Shot 2019-12-16 at 3 40 14 PM" src="https://user-images.githubusercontent.com/26739/70941418-6ab97900-201a-11ea-8549-0bcb4035267c.png">

I manually picked an uncommon macro and went to a non-en-US page an typed it in in the source and went back to the search (right-most number link on http://wiki.mdn.localhost:8000/en-US/dashboards/macros

Resolving patch:
diff --git a/kuma/search/fields.py b/kuma/search/fields.py
--- a/kuma/search/fields.py
+++ b/kuma/search/fields.py
@@ -37,5 +37,4 @@ def to_representation(self, value):
         args = [getattr(value, arg) for arg in self.args]
         kwargs = {arg: getattr(value, arg) for arg in self.kwargs}
         locale = getattr(value, 'locale', settings.LANGUAGE_CODE)
-        path = reverse(self.url_name, locale=locale, args=args, kwargs=kwargs)
-        return '%s%s' % (settings.SITE_URL, path)
+        return reverse(self.url_name, locale=locale, args=args, kwargs=kwargs)


Test patch: