Add JSON format #523

Closed
swissspidy opened this Issue Aug 18, 2016 · 8 comments

Projects

None yet

3 participants

@swissspidy
Contributor

For WordPress core we are looking into adding some more JavaScript i18n tools so we can more easily translate strings in JavaScript. Instead of loading .mo files and passing only few of those strings to the JS, it would make more sense to have all JS-related strings in a single .json file.

For this, GlotPress needs a new format class to enable exporting JSON files. Ideally, these would be compatible with the format Jed expects, but I can also see how this might not be ideal. If that's the case, translate.wordpress.org could always override/extend any JSON format in GlotPress.

Looking at #297 and existing formats, implementing this should be quite easy and I would be more than happy to work on a patch for this.

@toolstack
Contributor

You might want to start this as a plugin and then we can look at integrating it in to core. Take a look at this plugin for an example.

I'd support it as part of core once all the details are worked out.

@toolstack toolstack added the feature label Aug 18, 2016
@toolstack toolstack added this to the Future milestone Aug 18, 2016
@swissspidy
Contributor

Thanks for your feedback. Set up https://github.com/swissspidy/glotpress-json now. Let's see where it goes :-)

@swissspidy
Contributor

The plugin I set up now has full test coverage and exports and imports data in the Jed 1.x format.

If anyone's got time to test it, that would be awesome.

@swissspidy
Contributor

@atimmer (Yoast) has successfully tested the plugin on their install. There was only one bug with plural forms which I've now fixed. The only difference between an exported POT file converted to JSON and a direct JSON export is some whitespace.

@ocean90
Member
ocean90 commented Sep 26, 2016

@swissspidy Could you clarify which JSON format the plugin supports?

I'm looking at https://github.com/mikeedwards/po2json#methods which lists four formats:

  • raw produces a "raw" JSON output
  • jed produces an output that is 100% compatible with Jed < 1.1.0
  • jed1.x produces an output that is 100% compatible with Jed >= 1.1.0
  • mf produces simple key:value output.

Is the plugin only for Jed?

@swissspidy
Contributor

The plugin currently only supports the Jed 1.x format. It would be easy to support the mf format though in a separate class. raw is simply the PO file in JSON, which I don't think is that useful. The old Jed format is similar to that, but not worth supporting IMHO as there is a new version.

@ocean90
Member
ocean90 commented Sep 27, 2016

Should this format then be called Jed(1x) and GP_Format_JSON used as a base class GP_Format_Jed1x extends GP_Format_JSON?

@ocean90 ocean90 modified the milestone: 2.3, Future Sep 27, 2016
@swissspidy
Contributor

Sure, that could work. Expect some results in time for today's meeting.

Thanks for changing the milestone 🎉

@ocean90 ocean90 closed this in #567 Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment