-
-
Notifications
You must be signed in to change notification settings - Fork 989
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
Add support for go-i18n v2 file #4323
Comments
Sentry issue: WEBLATE-4K3 |
Use "JSON file" as file format in this case. The go-i18n format needs structured data at least with id and translation attributes. See also #2558 |
This issue looks like a support question. We try to answer these reasonably fast, but in case you are looking for faster resolution, please consider purchasing support subscription and make Weblate stronger. |
@nijel According to the source code of
|
See #2558 for the discussion on the format. The go-i18n consumes wide range of JSON variants and what Weblate calls go-i18n is only one of these. I have no knowledge whether it is the most widely used one or not, but nobody did comment on that in #2558 (comment) |
Actually, I think the data structure Maybe the confusion comes from the different formats v1 and v2 use:
{
"id": "your_unread_email_count",
"translation": {
"one": "You have {{.Count}} unread email.",
"other": "You have {{.Count}} unread emails."
}
} v2:
{
"your_unread_email_count": {
"hash": "sha1-e23eeb209a3a322e1c1174d7816d2ccbca52080b",
"one": "You have {{.Count}} unread email.",
"other": "You have {{.Count}} unread emails."
}
} According to the docs (https://docs.weblate.org/en/latest/formats.html#go-i18n-json-files) only v2 is supported by weblate. Is the documentation correct here? |
Is this documented somewhere? All I was able to find were tests, which seem parse pretty much any JSON file, see https://github.com/nicksnyder/go-i18n/blob/949485dac070df78fc9b06c9758facf6c41a6470/v2/i18n/parse_test.go#L21-L140 What is actually supported in Weblate is what you describe as v1 (see the test data: https://github.com/translate/translate/blob/441f8ff70e0a81b99d9f133ab7a040797d24974d/translate/storage/test_jsonl10n.py#L55-L70), but I was told this is v2 when implementing this. |
The output weblate currently produces is correctly parsable by go-i18n v2. But weblates fails to read existing translation files from go-i18n v2. You can find an example for toml at https://github.com/nicksnyder/go-i18n/blob/949485dac070df78fc9b06c9758facf6c41a6470/v2/example/active.es.toml. |
Part of the problem is that go-i18n will happily parse nearly any JSON, what makes it hard to determine what is the actual current format. Especially when there is no documentation describing the formats itself besides "Supports message files of any format (e.g. JSON, TOML, YAML)". I think we can rename existing format to v1 and implement support for v2. Is there some specification for the hash field? |
Apparently, what we support is v1, see #4323
This issue has been added to the backlog. It is not scheduled on our roadmap, but it eventually might be implemented. In case you desperately need this feature, please consider helping or funding the development. |
The issue you've reported needs to be addressed in the translate-toolkit. Please file the issue there and do not forget to include links to any relevant specifications about the formats (if applicable). |
Thanks for updating the docs 👍 From the docs: |
That explains nothing. In case Weblate is supposed to update that, it needs to know how it is calculated. Yes, I can probably read the code to figure it out, but that's not what I prefer. Honestly, go-i18n is terrible in this - the formats are not documented, the changes between v1 and v2 are not documented, basically there is no documentation besides describing the API. People should first look at existing formats (there are already few dozens of them) before inventing yet another one for good reason... |
Thank you for your report; the issue you have reported has just been fixed.
|
Describe the bug
Loading a go-i18n file into a new component fails with
'str' object has no attribute 'get'
To Reproduce
Steps to reproduce the behavior:
assets/i18n/active.*.json
Expected behavior
A new component get created and the existing translation loaded.
Screenshots
Server configuration and status
Will provide this later. I'm using Weblate 4.1.1.
Weblate deploy checks
Will provide this later.
Exception traceback
None
Additional context
N/A
The text was updated successfully, but these errors were encountered: