Closed ColdHeat closed 2 years ago
There is no specific tool for our file format. But since the format is simple with messageKey: messageValue any PO to JSON converter will work. But the placeholder, plural and such syntax will require non-trivial work to convert.
Generally, such conversion is not possible, since Gettext does not have stable message identifiers. Could you elaborate what you are trying to do?
I have a project written in Flask that basically has three areas (Python, Jinja, Javascript) where translation could be useful. It's an open issue here: https://github.com/CTFd/CTFd/issues/570. I'm mostly doing research about how I would pull this off.
From my research it seems like in Python translation via .po files is the standard whereas in Javascript custom JSON formats is more common. Unless I can share the .po between Python and JS, I would probably have to maintain multiple formats.
To pull that off I believe I should have a single source of truth and then generate the other files. Because of the standardization, it seemed like I should probably use the po files as truth and then generate the banana files from them. Thus I'm investigating ways to do that.
I'm not necessarily afraid of using the banana format as the source of truth, but po seems to be more standard and likely what more tools/libraries would support outside of JS.
Plenty of tools support Gettext, but it is an old tool and not designed for web development. I have written more elaborately about it a while ago: https://laxstrom.name/blag/2013/11/20/review-of-gettext-pot-file-format/
It's certainly possibleâand not too difficultâto use format other than Gettext in Python. It's also possible to use Gettext with JavaScript, but I'm not sure how easy that would be. For JSON it is super trivial to write your own handling, as it is a very simple format. The only difficult thing is parsing plurals, but code for that exists in jquery.i18n/vue.i18n libraries and in bunch of other languages as well.
Also, in general, sharing strings is not a good idea unless the context for them is the same, e.g. if you are doing both server side and client side rendering of the same templates.
Finally, if you are going to use a translation platformâwhich you absolutely should useâcheck what file formats they support. For example, my project translatewiki.net fully supports both Gettext and Banana JSON.
Does there exist a tool to convert from .po files to a banana file?