babel-plugin-i18next-extract icon indicating copy to clipboard operation
babel-plugin-i18next-extract copied to clipboard

Non-destructive JSON serialization

Open gilbsgilbs opened this issue 4 years ago • 2 comments

Currently, keys in the JSON file may be reordered by the plugin. Similarly, trailing line returns and whitespaces are always discarded when exported (which is not POSIX compliant, yet arguably a de facto standard imposed by JSON serializers in many languages and tools). This can lead to edition wars and merge conflicts in translation files, where an external tool (such as Weblate or even vim) would use a different order or would append a newline at the end.

The ideal solution would be to make the exporter preserve everything and just add keys like a human would do. We could get closer to this by relying on a lexer such as moo in order to keep a tokenized version of the original JSON file that we could use to re-export it just as it was before.

The problem of trailing whitespaces and line breaks could be addressed with way less effort just by copying in memory the trailing whitespaces and line breaks in the original file and re-adding them before exporting.

See discussions in #58

gilbsgilbs avatar Aug 26 '19 23:08 gilbsgilbs

Is there any progress on the sorting/reordering? For me it still sorts alphabetically, while i would like it to be FIFO. Could not find a configuration that would enable this.

tizzle avatar Jan 17 '21 14:01 tizzle

i'm facing the same issue with sorting/reordering, i would like the new words to be placed at the end to make it easier for update.

amherrat avatar May 28 '21 12:05 amherrat