WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.35k stars 971 forks source link

Support Weblate Flags in Gettext Files via Extracted Comments #11655

Open anubeon opened 1 month ago

anubeon commented 1 month ago

Describe the problem

We use GNU gettext for translating strings for embedded systems, with our programmers providing human-readable cues for things like maximum character length via the extracted comments feature (example below).

#.
#. STARTUP TYPEWRITER TEXT
#. ------------------------------------------------------------------
#. EEPROM BLANK (Maxlen=12)
msgid "BLANK"
msgstr "VIDE"

#. (DO NOT TRANSLATE!)
msgid "EEPROM"
msgstr ""

For our use case, this could potentially be a far more efficient means of setting weblate-flags such as max-length:N than manually setting said flags via Weblate's UI. Presently, however, only certain XML based formats support storage and synchronisation of weblate-flags.

Describe the solution you would like

We suggest supporting storage and synchronisation of weblate-flags within gettext's extracted comments, in a similar vain to the non-standard weblate-flags attribute supported for XLIFF.

As the extracted comments feature of GNU gettext is designed to allow programmers to provide cues to translators, this would seem the ideal means of conveying machine-readable instructions to a translation tool such as Weblate.

Example:

#.
#. STARTUP TYPEWRITER TEXT
#. ------------------------------------------------------------------
#. EEPROM BLANK weblate-flags="max-length:12, priority:50"
msgid "BLANK"
msgstr "VIDE"

#. weblate-flags="read-only"
msgid "EEPROM"
msgstr ""

In the example above, weblate-flags are:

  1. Appended to the end of the extracted comments.
  2. Signified via the keyword/prefix weblate-flags=.
  3. Encapsulated by double quotes.
  4. Comma-delimited.

These would seem like reasonable conventions to follow?

Describe alternatives you have considered

No response

Screenshots

No response

Additional context

No response

nijel commented 1 month ago

Weblate does extract flags from Gettext type comments:

#: weblate/addons/forms.py:541
#, python-format
msgid "Could not parse CSS selector: %s"
msgstr "Nepodařilo se zpracovat CSS selektor: %s"

Will get python-format flag. The issue with that is that there is no way to generate custom flags using gettext and I think that gettext tools will complain about unknown flags.

nijel commented 1 month ago

It makes sense to support extracting Weblate flags from the comments, but the syntax has to be carefully designed. For example, the flags itself can contain quotes, so using quotes to delimit them doesn't sound like a good idea.

github-actions[bot] commented 1 month ago

This issue has been put aside. It is currently unclear if it will ever be implemented as it seems to cover too narrow of a use case or doesn't seem to fit into Weblate.

Please try to clarify the use case or consider proposing something more generic to make it useful to more users.

anubeon commented 4 weeks ago

It makes sense to support extracting Weblate flags from the comments, but the syntax has to be carefully designed. For example, the flags itself can contain quotes, so using quotes to delimit them doesn't sound like a good idea.

@nijel Of course, I'm not wedded to the use of quotes as delimitore. Can you foresee any issues with using curly brackets? Again, I'm not wedded to this.

#.
#. STARTUP TYPEWRITER TEXT
#. ------------------------------------------------------------------
#. EEPROM BLANK weblate-flags{ max-length:12, priority:50" }
msgid "BLANK"
msgstr "VIDE"

#. weblate-flags{ "read-only }
msgid "EEPROM"
msgstr ""

Please try to clarify the use case or consider proposing something more generic to make it useful to more users.

The use case would be identical to that which (presumably) warranted the implementation of weblate-flags in XML based formats such as XLIFF.

Of course one could argue "Why not just use XLIFF?", but there are presumably plenty of projects out there which rely on gettext, and which aren't in a position to migrate, that might find the ability to communicate weblate-flags such as read-only, and min-length:N useful?