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

JSON format breaks i18next files due to automatic restructuring [$120 awarded] #775

Closed
wichert opened this issue Jul 10, 2015 · 21 comments
Closed
Assignees
Labels
enhancement Adding or requesting a new feature. translate-toolkit Issues which need to be fixed in the translate-toolkit
Milestone

Comments

@wichert
Copy link
Contributor

wichert commented Jul 10, 2015

I just had an interesting experience: I configured Weblate to manage translations for an Aurelia project, which uses i18next to handle translations. This worked wonderfully well, until I started testing with updated translations and found that half the translations had stopped working.

The problem turned out to be due to handling JSON structure: Weblate (via Translate Toolkit I guess?) always uses a flat structure for the data. So where my translation.json used to look like this:

{
    "navbar": {
        "reward": "Rewards",
        "about": "About"
    }
}

it got transformed into this:

{
    "navbar.reward": "Rewards",
    "navbar.about": "About"
}

This breaks the translation lookup.

@nijel nijel added enhancement Adding or requesting a new feature. translate-toolkit Issues which need to be fixed in the translate-toolkit labels Jul 10, 2015
@nijel
Copy link
Member

nijel commented Jul 10, 2015

Indeed these files are not properly supported by translate-toolkit so far. There already is issue #650 on same topic, but given that the file mentioned there no longer exists, I will close it in favour of this issue.

@wichert
Copy link
Contributor Author

wichert commented Jul 10, 2015

Is there some way I can help to improve support for that format?

@nijel
Copy link
Member

nijel commented Jul 14, 2015

Improving translate-toolkit support. Currently JsonFile._extract_translatables is able to load these, but the JsonFile.str method used for serialization does not recognize these specially formatted keys. So saves them as they are without parsing.

@phw
Copy link
Contributor

phw commented Jul 14, 2015

Just for completeness: The old ticket #650 also included another issue, since Chrome web store localization files include fields that are not supposed to be translated (the description which is a description of the translation itself similar to the comments found in some other formats). Not sure how to handle this special case in translate toolkit, though. I think that would be a special file format based on the existing JSON implementation.

@nijel
Copy link
Member

nijel commented Jul 14, 2015

Indeed, these are different problems, just happen to be based on same file format.

@nazar-pc
Copy link

I have a bit similar use case.
Sometimes translations are in form of the tree:
https://github.com/nazar-pc/CleverStyle-CMS/blob/master/components/modules/Shop/languages/English.json

Each key of parent structure is used as prefix for inner structures,
for instance:

"shop_" : {
  "type_" : {
    "int_set" : "Integer set",

effectively results in key "shop_type_int_set" : "Integer set".
So it is similar to what is described in this issue, but actually without any additional separator in form of dot.

@saily
Copy link
Contributor

saily commented Apr 27, 2016

@nijel any news on this? Do you need some help?

@saily
Copy link
Contributor

saily commented Apr 27, 2016

@nijel i just debugged translate-toolkit, it seems it can handle nested json files.

@nijel
Copy link
Member

nijel commented Apr 27, 2016

It can parse them, but it will write them differently (see first comment in this issue).

See https://github.com/translate/translate/blob/master/translate/storage/jsonl10n.py#L157

@saily
Copy link
Contributor

saily commented Apr 28, 2016

Ok, after a lot of discussions i stopped working on translate-toolkit and wrote a small pre-commit hook python script which converts this back. @nijel do you like to ship this within your examples?

@nijel
Copy link
Member

nijel commented Apr 28, 2016

Shipping that with Weblate is certainly okay.

@saily
Copy link
Contributor

saily commented May 6, 2016

here's a gist how to fix this with a pre-commit hook: https://gist.github.com/saily/f8a9f72c6b064d51f09040d66e981240

nijel added a commit that referenced this issue May 9, 2016
Thanks to Daniel Widerin.

Issue #775

Signed-off-by: Michal Čihař <michal@cihar.com>
@nijel
Copy link
Member

nijel commented May 9, 2016

Thanks, I've included the above script in examples.

@wichert
Copy link
Contributor Author

wichert commented Jun 2, 2017

@nijel what kind of bounty would you want to have to get this added natively to weblate (either through translate-toolkit or directly - as a user I don't care how it is implemented)?

@saily
Copy link
Contributor

saily commented Jun 2, 2017

@wichert we could just ship the script with weblate by default.

@wichert
Copy link
Contributor Author

wichert commented Jun 2, 2017

That does not work, since the pre-commit hook is global and would break badly if you also use other formats. You would need a flag per repository that indicates if that hook needs to be run, so more integration is necessary as far as I can see.

@nijel
Copy link
Member

nijel commented Jun 7, 2017

I think that adding support for this to translate-toolkit (and then Weblate) should be quite easy, I just haven't found time to do that (there are always more important things to do). Having similar bounty as on the WebExtension JSON format (#1380) would probably make me look into both of them rather sooner than later though ;-).

@wichert
Copy link
Contributor Author

wichert commented Jun 7, 2017

@nijel I added a $120 bounty.

@nijel nijel added this to TODO in File format support Jun 8, 2017
@wichert
Copy link
Contributor Author

wichert commented Jun 16, 2017

@denim2x Did you really start working on this? I noticed you claimed the bounty with a completion date of last Monday, but I don't see any activity on your github account indicating you did anything.

@nijel
Copy link
Member

nijel commented Jun 16, 2017

Unless there will be some progress here, I can look at this last week in June.

@nijel nijel added this to the 2.16 milestone Jun 30, 2017
@nijel nijel self-assigned this Jun 30, 2017
@nijel
Copy link
Member

nijel commented Jun 30, 2017

Support for translate-toolkit has been submitted for review: translate/translate#3662

nijel added a commit to WeblateOrg/test that referenced this issue Jul 3, 2017
See WeblateOrg/weblate#775

Signed-off-by: Michal Čihař <michal@cihar.com>
nijel added a commit that referenced this issue Jul 3, 2017
New JSON variant added.

Issue #775

Signed-off-by: Michal Čihař <michal@cihar.com>
@nijel nijel closed this as completed in 0788f6f Jul 3, 2017
@nijel nijel moved this from TODO to Done in File format support Jul 3, 2017
@nijel nijel moved this from TODO to Done in File format support Jul 18, 2017
@nijel nijel changed the title JSON format breaks i18next files due to automatic restructuring JSON format breaks i18next files due to automatic restructuring [$120 awarded] Mar 5, 2018
@nijel nijel added the bounty label Mar 5, 2018
@nijel nijel changed the title JSON format breaks i18next files due to automatic restructuring [$120 awarded] JSON format breaks i18next files due to automatic restructuring May 3, 2018
@nijel nijel changed the title JSON format breaks i18next files due to automatic restructuring JSON format breaks i18next files due to automatic restructuring [$120 awarded] May 3, 2018
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. translate-toolkit Issues which need to be fixed in the translate-toolkit
Projects
Development

No branches or pull requests

5 participants