WordPress / openverse-frontend

The gateway to the Openverse. Openverse is a search tool for CC-licensed and public domain content across the internet.
https://wordpress.org/openverse
MIT License
72 stars 64 forks source link

Using JSON5 for `en.json` #1815

Closed dhruvkb closed 2 years ago

dhruvkb commented 2 years ago

Due date: 2022-09-29 (a fortnight)

Assigned reviewers

Tagging @WordPress/openverse-frontend, please feel free to add your name below if you have some feedback (good or bad) or ideas.

Description

We use JSON to write the main i18n locale file: en.json. This file is completely written by hand and maintained manually, for which JSON is a pretty poor format. This might come across as a hot-take so let me elaborate.

Comments

My main complaint with using JSON for en.json is lack of comments. It's very hard to describe context for any i18n key in the en.json file. For a file that's written by and for people, that's a huge miss. There is duplication in the file, many keys are written deeply nested and then used outside of where they're defined (happens during refactors when code is moved around) and then there's no way to know if an i18n key is deprecated/superseded.

Comments wouldn't solve the problems above but they would be very helpful. That's why POT files (like openverse.pot) have comments (the #: before each msg)! And since our en.json file doesn't have comments, our POT comments end up being just .vue references. I believe we are under-utilising a powerful tool for communicating intent and context with the translators.

Syntax

I also have several personal gripes with the JSON syntax but that's secondary.

Why JSON5?

JSON5 is a superset of JSON which has many advantages over plain JSON. I'll let their webpage explain what those are. Switching to JSON5 is as easy as a rename (superset of JSON) and we can adopt changes incrementally.

Migration path

Feel free to chime in with alternatives.

Alternatives

YAML, although almost universally reviled, is imo a great format. But moving to YAML is not the right move.

References

krysal commented 2 years ago

there's no way to know if an i18n key is deprecated/superseded.

There is indeed a vue-i18n rule to warn about unused keys. I agree would be great to add it and to have comments in JSONs 😃

zackkrida commented 2 years ago

I support this, especially if we can find a way to get the json5 comments into the pot file and subsequently into glotpress.