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

Allow strings in JSON format to use one JSON key as the ID and another as the translation #8576

Closed
SamWhited opened this issue Jan 7, 2023 · 7 comments
Assignees
Labels
enhancement Adding or requesting a new feature. translate-toolkit Issues which need to be fixed in the translate-toolkit
Milestone

Comments

@SamWhited
Copy link
Contributor

Describe the problem

The JSON formats currently supported by weblate all assume that the JSON looks something like this:

{
  "translation key": "translated string"
}

However, my JSON looks something like this:

{
  "lang": "en-US",
  "messages": [
    {
      "id": "translation key",
      "translation": "translated string"
    }
  ]
}

I can mark the "lang" key as read only, so there's no trouble there, but each field in messages shows up as a translatable string, ie. messages[0].id and messages[0].translation. This isn't the end of the world, except that to a non-technical translator it looks as if they should translate "id". If I mark the ID field as read-only it does not get copied into the JSON from the source strings file, so we end up with a broken entry that contains the translation but no ID.

Describe the solution you'd like

It would be nice if you could specify a field where its value would act as the ID instead of assuming the field name is the ID. Alternatively, Go's gotext format from https://pkg.go.dev/golang.org/x/text/cmd/gotext could be supported directly (though it's not widely used and not very well documented, so it may not be ready for native support yet and this could probably be implemented in a generic way anyways).

Describe alternatives you've considered

Right now I'm just allowing the id keys to be translated and requiring review for all translations so that I can tell people not to translate that key.

Screenshots

A screenshot of the translation interface, the string in question that has been selected for translation is an "id" that should not be translatable

Additional context

No response

@nijel
Copy link
Member

nijel commented Jan 9, 2023

@SamWhited
Copy link
Contributor Author

@nijel it's not related, that's a totally different 3rd party thing that's already supported.

@nijel
Copy link
Member

nijel commented Jan 11, 2023

I'm asking because it has similar layout of the JSON file (with id being a hash item as well).

Anyway, the best approach is to add support for this particular format.

@nijel nijel added this to TODO in File format support via automation Jan 11, 2023
@nijel nijel added enhancement Adding or requesting a new feature. translate-toolkit Issues which need to be fixed in the translate-toolkit labels Jan 11, 2023
@github-actions
Copy link

The issue you've reported needs to be addressed in the translate-toolkit. Please file the issue there, and include links to any relevant specifications about the formats (if applicable).

@SamWhited
Copy link
Contributor Author

SamWhited commented Jan 11, 2023

I see, thank you! I don't see an example of that file format, but I was under the impression it just used a flat one. I'll take a look though and file an issue upstream as indicated, thanks again!

EDIT: go-i18n uses a JSON array as the top-level element in the file, whereas gotext uses a map with a key that contains an array with all the translations, so I don't think the two would be interchangeable, but I'll mess with it and see.

@SamWhited
Copy link
Contributor Author

Oops, found translate/translate#4450 so it looks like this issue has already been filed!

@nijel nijel self-assigned this Jan 13, 2023
@nijel nijel added this to the 4.15.1 milestone Jan 13, 2023
@nijel nijel closed this as completed in 4cf5999 Jan 13, 2023
File format support automation moved this from TODO to Done Jan 13, 2023
@github-actions
Copy link

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

nijel added a commit to WeblateOrg/translation-finder that referenced this issue Jan 13, 2023
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

2 participants