<?xml version="1.0"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>CKAN: Ticket #2802: Need to tweak the JSON formatting of the localisations</title>
    <link>http://localhost/ticket/2802</link>
    <description>&lt;p&gt;
This is what we need the JSON to look like. Taken from the Jed documentation (&lt;a class="ext-link" href="http://slexaxton.github.com/Jed/"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;http://slexaxton.github.com/Jed/&lt;/a&gt;).
&lt;/p&gt;
&lt;pre class="wiki"&gt;{
      // The empty string key is used as the configuration
      // block for each domain
      "" : {
        // Domain name
        "domain" : "the_domain",
        // Language code
        "lang" : "en",
        // Plural form function for language
        "plural_forms" : "nplurals=2; plural=(n != 1);"
      },
      // Other keys in a domain contain arrays as values
      // that map to the translations for that key.
      // Gettext suggests that you use english as your keys
      // in case the key isn't found, and it can just pass
      // the value directly through.
      // Note: by convention, the 0-index location of the translations
      // is never accessed. It's just a thing, I guess.
      "a key" : [ null, "the translation", "the plural translations", ... ],
      // The plural form string is converted into a function
      // and the value that's passed into the gettext call
      // is passed into the plural form function. It's result
      // (plus 1) is the index that the translation comes from.
      // We're using sprintf interpolation on our keys so we can
      // then sub in the _actual_ values into the result.
      "%d key" : [ null, "%d key", "%d keys" ],
      // Contexts are keys that are just prefixed with a context string
      // with a unicode \u0004 as the delimiter.
      // You can use it for anything. Usually it's just for being content aware
      // in some way (e.g. male vs. female, product vs. category)
      "context\u0004%d key": [ null, "context %d key", "context %d keys" ]
    }
&lt;/pre&gt;&lt;p&gt;
This looks like an appropriate python library to do the formatting. &lt;a class="ext-link" href="http://pypi.python.org/pypi/pojson/"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;http://pypi.python.org/pypi/pojson/&lt;/a&gt; but I'll leave to your discretion.
&lt;/p&gt;
&lt;p&gt;
Finally an API endpoint that returns the appropriate request would save us making requests to the i18n directory.
&lt;/p&gt;
&lt;pre class="wiki"&gt;/api/i18n/{locale}
&lt;/pre&gt;&lt;p&gt;
For example if the current url is &lt;a class="ext-link" href="http://localhost:5000/pl/dataset"&gt;&lt;span class="icon"&gt;​&lt;/span&gt;http://localhost:5000/pl/dataset&lt;/a&gt; then the client would request:
&lt;/p&gt;
&lt;pre class="wiki"&gt;http://localhost:5000/api/i18n/pl
&lt;/pre&gt;&lt;p&gt;
This should return the Content-Type: application/json and a 200 with an appropriate JSON body (this can be the language requested or an appropriate fallback). I think that if the fallback is the default language (in most cases English) then we just return a 204 No Content to save data.
&lt;/p&gt;
</description>
    <language>en-us</language>
    <image>
      <title>CKAN</title>
      <url>http://assets.okfn.org/p/ckan/img/ckan_logo_shortname.png</url>
      <link>http://localhost/ticket/2802</link>
    </image>
    <generator>Trac 0.12.3</generator>
    <item>
      
        <dc:creator>toby</dc:creator>

      <pubDate>Mon, 06 Aug 2012 13:03:53 GMT</pubDate>
      <title>owner, status changed</title>
      <link>http://localhost/ticket/2802#comment:1</link>
      <guid isPermaLink="false">http://localhost/ticket/2802#comment:1</guid>
      <description>
          &lt;ul&gt;
            &lt;li&gt;&lt;strong&gt;owner&lt;/strong&gt;
              changed from &lt;em&gt;toby&lt;/em&gt; to &lt;em&gt;aron.carroll&lt;/em&gt;
            &lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;status&lt;/strong&gt;
                changed from &lt;em&gt;new&lt;/em&gt; to &lt;em&gt;assigned&lt;/em&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;p&gt;
@aron
&lt;/p&gt;
&lt;p&gt;
I've done most of this
&lt;/p&gt;
&lt;p&gt;
to test
&lt;/p&gt;
&lt;p&gt;
get strings
&lt;tt&gt; python setup.py extract_messages &lt;/tt&gt;
&lt;/p&gt;
&lt;p&gt;
mangle the zh_TW creates .po/.mo files - I may need to fix plurals
&lt;tt&gt; paster trans mangle -c .ini &lt;/tt&gt;
&lt;/p&gt;
&lt;p&gt;
create .js files only zh_TW will be correct due to other .po/.mo files being 1.7 ones
&lt;tt&gt; paster trans js -c .ini &lt;/tt&gt;
&lt;/p&gt;
&lt;p&gt;
/api/i18n/zh_TW should be correct
&lt;/p&gt;
&lt;p&gt;
please note we do not have en.js I'm returning {} I think this is the correct response (maybe something else as we should just use the default _('...') strings - maybe we need to do something else
&lt;/p&gt;
&lt;p&gt;
for what it's worth pojson does not provide the format you wanted so I adapted it
&lt;/p&gt;
&lt;p&gt;
reassign if you need fixes
&lt;/p&gt;
      </description>
      <category>Ticket</category>
    </item><item>
      
        <dc:creator>aron.carroll</dc:creator>

      <pubDate>Mon, 06 Aug 2012 16:10:46 GMT</pubDate>
      <title>status changed; resolution set</title>
      <link>http://localhost/ticket/2802#comment:2</link>
      <guid isPermaLink="false">http://localhost/ticket/2802#comment:2</guid>
      <description>
          &lt;ul&gt;
            &lt;li&gt;&lt;strong&gt;status&lt;/strong&gt;
                changed from &lt;em&gt;assigned&lt;/em&gt; to &lt;em&gt;closed&lt;/em&gt;
            &lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;resolution&lt;/strong&gt;
                set to &lt;em&gt;fixed&lt;/em&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;p&gt;
Cool, this is in as of 8b72d1f8e9ba
&lt;/p&gt;
      </description>
      <category>Ticket</category>
    </item>
 </channel>
</rss>