UMB-CS682-Team-02 / tracker

0 stars 1 forks source link

Translate linked values in charts. #51

Closed rouilj closed 6 months ago

rouilj commented 6 months ago

The linked values in charts should be translated using the current @language parameter.

Make chart.py call translation functions to translate the values.

Use db.i18n methods to translate the property values.

See https://docs.python.org/3/library/gettext.html#gnu-gettext-api for the methods available to gettext and translate it.

rouilj commented 6 months ago

Ashrith, it looks like this should work:

db.i18n.gettext(k)

did you remember to restart the server after the change. I often forget myself.

ashrith-UMB commented 6 months ago

I am using gettext() as below : chart.title = db.i18n.gettext("Tickets grouped by %s \n(%s)" % (arg['group'][0][1], db.config.TRACKER_NAME))

and yes, I did restart the server too !

I am still trying to figure out the reason why it is not being translated to the language selected.

rouilj commented 6 months ago

(eek, forced it to be verbatim as GitHub was mushing everything together. And it is still mushing it all together. Look at it in edit mode or quote it?? It looked ok in the preview mode of the editor though.)

Hi Ashrith:

In message ***@***.***>, Ashrith Ponugoti writes:

>I am using gettext() as below :
>chart.title = db.i18n.gettext("Tickets grouped by %s \n(%s)" % (arg['group'][0][1],
>                                                        db.config.TRACKER_NAME))

The intent of the issue was to translate the linked values (i.e. the
property values/names). In the index view, the group property values
in the dividers that span the table are translated. E.G. chatting ->
in Diskussion or bug -> Fehler. Translating the property names
priority -> Priorität was included as well and is what your example
addresses.

Try:

  chart.title = "Tickets grouped by %s \n(%s)" % (
                     db.i18n.gettext(arg['group'][0][1]),
                     db.config.TRACKER_NAME)

that is translate *just* the group parameter.

>I am still trying to figure out the reason why it is not being
>translated to the language selected.

The way translation works is the value passed to gettext is a lookup
key. There has to be a translation in the .po (and thus the .mo) file
corresponding to the key.

While the various properties (priority, status ...) and their values
are translated, a string like:

  "Tickets grouped by priority \n(Roundup Issue Tracker)"

which your original example was looking up, isn't in the .po file.

  grep priority locale/de.po

returns

  msgid "priority"

shows that "priority" is a known message key.

The gettext system doesn't use translation services like google or
anything to do the translation on the fly on arbitrary strings.  The
developer extracts the translation tokens to a .pot file and that is
merged with the .po file for a human to translate. This is described
in the Roundup source directory in doc/developers.txt.

An older version of developer.txt is online at:
  https://roundup-tracker.org/docs/developers.html#internationalization-notes

The better way to mark up your example is:

  chart.title = db.i18n.gettext("Tickets grouped by %s \n(%s)") % (
                     db.i18n.gettext(arg['group'][0][1]),
                     db.config.TRACKER_NAME))

This creates a translation key with the substitution tokens:

   "Tickets grouped by %s \n(%s)"

that can be translated for any property and leverages the existing
property name translations.

The best way to mark up your example would use:

   "Tickets grouped by %(propertyName)s \n(%(trackerName)s)"

where the entire code block looks like:

  chart.title = db.i18n.gettext("Tickets grouped by %(propertyName)s \n(%(trackerName)s)") % {
      'propertyName' : db.i18n.gettext(arg['group'][0][1]),
      'trackerName':   db.config.TRACKER_NAME }

which uses a dictionary (after the %) for interpolation, not a tuple.

Using a dictionary lets the translator change the order of the tracker
name and property in the translated string. So it could be rewritten
as:

      "%(trackerName)s\nGrouping by %s(propertyName) of issues"

It also gives the translator some context as to what is substituted by
the %(...)s token.

Let me know if my example works.

--
                -- rouilj
ashrith-UMB commented 6 months ago

The example given by you does work, translating just the group parameter does produce the result. Thank you for the suggestion! Commit : https://github.com/UMB-CS682-Team-02/tracker/commit/bda2964eaf512a55fb4da43a06cf04b9362448f0