Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend "Customize JSON output" addon with option to remove keys with empty value #4076

Closed
rhofer opened this issue Jun 22, 2020 · 2 comments
Closed
Assignees
Labels
enhancement Adding or requesting a new feature.
Milestone

Comments

@rhofer
Copy link
Contributor

rhofer commented Jun 22, 2020

Is your feature request related to a problem? Please describe.
When having a HTML5 application and e.g. using ngx-translate as translation provider, this allows to specifcy a fallback mechanism, where in case a key is not found it falls back to the default language. Hence, if a certain value from source is not translated to a target language, this specific key should not appear in the target language's json.
This is generally the case when Template for new translations: is left open / unspecified as:

image

Still, an empty value can be created (despite of above's configuration) if a context once has been translated, later on the value has been deleted and saved again ( weblate). As example, the history of following value shows this case:

image

With this, the de.json (as per example above) ends up with an entry as following

{
    "LOGIN": {
        "ACTION": ""
    }
}

If this de.json is provided as German translation the for LOGIN.ACTION it will display an empty string "" and fallback to English won't work.

Describe the solution you'd like
Extend the Customize JSON output addon with the following option:

image

The idea is that the addon can be configured (true / false) to remove keys with empty values. Furthermore, if this results in empty objects and/or lists, also those shall be removed.

With the given example above, the extended addon may needs to run several times / recursively, where the first criteria would generate:

{
    "LOGIN": {
    }
}

and a second run would generate:

{
}

Describe alternatives you've considered
This could be done with a post processing on the repository which receives translations from weblate by using e.g. jq, with a call similar to

jq walk(if type == "object" then with_entries(select(.value != null and .value != "" and .value != [] and .value != {})) else . end)

Drawback is, that the receiving repository needs an additional "compile" step to prepare the translation resources, and hence the json's cannot be used as delivered by Weblate, out of the box.

Hence it would be preferred, if this kind of cleaned-up output could be achieved by Weblate directly.

@nijel nijel added the enhancement Adding or requesting a new feature. label Jun 22, 2020
@nijel
Copy link
Member

nijel commented Jul 8, 2020

There is also more generic variant of this in #2276

@github-actions
Copy link

Thank you for your report, the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants