Exclude "description" property from react-intl JSON files

CrowdIn docs mention there is built-in support for react-intl’s ICU Message JSON format, but when I build+download translations, it appears to unnecessarily include English descriptions for all strings.

Example input:

  "buttonCredits": {
    "defaultMessage": "Credits",
    "description": "Text shown on the button to open the credits message box"
  },

Produced output:

  "buttonCredits": {
    "defaultMessage": "Разработчики",
    "description": "Text shown on the button to open the credits message box"
  }

Ideally, I would like to omit the “description” property for each message (messages are just properties of the root JSON object), i.e.:

  "buttonCredits": {
    "defaultMessage": "Разработчики"
  }

I tried using the “Configurable JSON & YAML” tool, but aside from not apparently doing anything, it seems to be geared toward filtering JSON input, whereas I’m trying to filter the output.

I’ve spent quite a bit of time searching and I can’t seem to find a solution.

Anyone run into this? Got any suggestions?

Thanks!

Edit: My current plan is to just post-process the downloaded translations myself, but I suspect CrowdIn can do this for me… I just have to figure out how :slight_smile:

1 Like

Hi @jaredkrinke

Please try to disable this option in Project settingsExport

1 Like

Thanks! Unfortunately, that didn’t appear to have any effect on the “Build & Download” output.

1 Like

It looks like regex app can do the trick and customize exported files:

Install the app => go to the project settings => File Processors and start setting up the post-processor.

Rules:

Remember to check “Unescape special characters”:

We need to search for (note there should be 4 spaces before description but Discourse doesn’t show it below in preview…):
",\n "description": "(.*?)"\n

and replace it with:
"\n

Hope it helps!

2 Likes

This sounds like what I need, but I can’t seem to get it to do anything. Does this run when I use the Translations → Build & Download button? Or do I need to go through some other entry point?

I setup a rule to change “description” to “hello”, and it doesn’t appear to modify the output JSON file at all, so I’m kind of stumped.

1 Like

Ok, I figured it out. Adding a file processor or changing its configuration only affects translation files that have subsequently been updated, so I wasn’t seeing any effect because I wasn’t also modifying any translations.

Honestly, that’s not how I’d expect it to work. I wonder if that’s expected? Regardless, it’s easy to work around.

For the record, I ended up using a slightly different configuration:

2 Likes

Hi Jared,

Glad to hear that you’ve figured it out and everything works fine

Let us know if you need further assistance!

1 Like

Turns out some of my strings with values don’t work with the above regular expression, so I wouldn’t recommend anyone else copy it since it’s not robust!

I’ll just post-process the files myself.

Hello, I have a json file that looks like that. I want to translate all the keys except some of them like “id” and “type”. I use the API to upload the files.
Can I achieve that with the regexp ?

In the output I want to get all the keys. I just want the translator not to change some specific protected keys.

Input:

[{"id":"cdb09c97-fd5e-4cd2-91b7-f4720ef90c74","name":"What is the problem you are solving?","type":"MediaContent","payload":{"title":"the title","description":"World","mediaSource":{"url":"https://api-ninjas.com/images/cats/abyssinian.jpg","type":"image"},"socialProof":{"content":"I'm a social proof","authorName":"John Doe","numberOfStar":5}},"displayProgressHeader":true},{"id":"f30d9f25-d879-4be8-bda2-1793e06adfa3","name":"What is the value you are providing?","type":"Question","payload":{"title":"Hello","answers":[],"multipleAnswer":false},"displayProgressHeader":false}]

ouput:

[{"id":"cdb09c97-fd5e-4cd2-91b7-f4720ef90c74","name":"j'aime le fromage","type":"MediaContent","payload":{"title":"Du fromage","description":"Le","mediaSource":{"url":"https://api-ninjas.com/images/cats/abyssinian.jpg","type":"image"},"socialProof":{"content":"Je suis fromage","authorName":"John Doe","numberOfStar":5}},"displayProgressHeader":true},{"id":"f30d9f25-d879-4be8-bda2-1793e06adfa3","name":"Du francais,"type":"Question","payload":{"title":"Bonjour","answers":[],"multipleAnswer":false},"displayProgressHeader":false}]

Hi @Swammy

Yes, you can use regular expressions (regex) to specify which keys should not be translated when uploading files via the API. Alternatively, you use the pre-post export module to cut them off during import and bring them back on the export.

But, if it’s only a question of translation, I’d say you can simply label those keys and mark them hidden. As only managers can access hidden strings, they will remain untranslated.