<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -5,6 +5,11 @@ from translate.search import match
 from translate.storage import base
 from xmlrpclib import ServerProxy
 
+# TODO: move this into Pootle as soon as it's usable
+try:
+   import json
+except ImportError:
+   import simplejson as json
 
 class opentran(match.matcher):
     &quot;&quot;&quot;A class to communicate and receive suggestions from open-tran.eu&quot;&quot;&quot;
@@ -47,20 +52,18 @@ class opentran(match.matcher):
         return result
 
 
-def unit2json(store):
+# TODO: move this into Pootle
+def store2json(store):
     &quot;&quot;&quot;
-    Converts units retrieved from a suggestion service to a suitable format.
+    Converts a store retrieved from a suggestion service to JSON format.
     &quot;&quot;&quot;
-    #TODO: use the simplejson module to return data in JSON format
-    response = &quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;UTF-8\&quot; standalone=\&quot;yes\&quot; ?&gt;\n&quot;
-    response +=  &quot;&lt;entries&gt;\n&quot;
+    response = {&quot;num_results&quot;: len(store.getunits()),
+                &quot;source_lang&quot;: store.sourcelanguage,
+                &quot;target_lang&quot;: store.targetlanguage,
+                &quot;units&quot;: []}
     for unit in store.getunits():
-        response += &quot; &lt;entry&gt;\n&quot;
-        response += &quot;  &lt;source lang=\&quot;%s\&quot;&gt;%s&lt;/source&gt;\n&quot; % (store.sourcelanguage,
-                                                             unit.source)
-        response += &quot;  &lt;target lang=\&quot;%s\&quot;&gt;%s&lt;/target&gt;\n&quot; % (store.targetlanguage,
-                                                             unit.target)
-        response += &quot; &lt;/entry&gt;\n&quot;
-    response +=  &quot;&lt;/entries&gt;\n&quot;
-    return response
+        newunit = {&quot;source&quot;: unit.source,
+                   &quot;target&quot;: unit.target}
+        response[&quot;units&quot;].append(newunit)
+    return json.dumps(response, sort_keys=True, indent=4)
 </diff>
      <filename>search/suggestions.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>24c466f4605dc7f61b1fc4d02b9a312e1dc81aee</id>
    </parent>
  </parents>
  <author>
    <name>Julen Ruiz Aizpuru</name>
    <email>julenx@gmail.com</email>
  </author>
  <url>http://github.com/julen/translate/commit/e05b7b25a7dc733353b233b66ed4789bc6b78000</url>
  <id>e05b7b25a7dc733353b233b66ed4789bc6b78000</id>
  <committed-date>2008-11-22T04:54:00-08:00</committed-date>
  <authored-date>2008-11-22T04:54:00-08:00</authored-date>
  <message>Replace dirty XML code with JSON.

This inserts a dependency with the simplejson module. The simplejson module is available in Python 2.6 as json.</message>
  <tree>2f35d4167f20124a704660e993e241f231ced101</tree>
  <committer>
    <name>Julen Ruiz Aizpuru</name>
    <email>julenx@gmail.com</email>
  </committer>
</commit>
