Help with translations in Gramps

Gramps 5.1.5

I am not looking for help with creating dictionaries (English-French) stc. I’m not that clever.
I am looking to implement translation in an Add-On Report.

The only thing I have been able to translate is the date, and I think Gramps does that for me. Is there some kind soul who knows how to do it, who could give me a few pointers.

Could you specify which add-on report?

Then we can link to specific lines in the code on GitHub and how to make the strings work with Weblate translation. Whether that means tagging the string to be translateable with Weblate translation or finding an existing string in the weblate that can be used instead.

And then maybe someone can run through examples of translating a new string to a existing language dictionary or create a new language dictionary.

Existing reports - no. I am trying to improve reports so existing ones will not do.
In Gramps Modules
from gramps.gen.const import GRAMPS_LOCALE as glocale
_trans = glocale.get_addon_translator(file)
except ValueError:
_trans = glocale.translation
_ = _trans.gettext

In the add_menu_options I have this which gives rise to a box on the menu of the report asking for a language
locale_opt = stdoptions.add_localization_option(menu, “Report Options”)

In the init()

And in the program
tagcheck = _(“Failed”) always outputs Failed

What am I doing wrong ?

The narrative web is a good example.
If you want to use specific language for a report, You have to do the following:‘trans’).get_value()
        self.rlocale = self.set_locale(the_lang) # The lang you want to use (i.e. fr, de_AT...)
        self._ = self.rlocale.translation.sgettext

... and then you can use:

        self._("Your message")

@GBaynes You’re getting good guidance already and in addition to that, here is a good place to start in the Gramps dev wiki: Writing a plugin - Internationalize it. This para links to other pages which have much more detail.

But, you don’t have the method to write a report in another language than the default language gramps used at startup.

With the example describe above, you have two choices:

_("Your message")      => The message is translated in the lang gramps use at startup.
self._("Your message") => The message translated for your report.

Thanks for the help. I am definitely making progress. I was wondering about the “(" and "self.(”. But I think you have answered it. Thanks again.
George Baynes

Off topic but I had noticed this use of the underscore in Gramps. I saw quite recently his implementation of the style:
_ = method to do the translation

This means that the generally agreed-upon usage or convention by python programmers of the underscore as a substitution variable - e.g. to unpack something: a, _ = (“x”, “y”) - has been hijacked to assign a translation function to it, with the risk, I suppose, that entails.

In gramps this has another meaning. It is used to replace a fonction name by something shorter.

When we use _(“string”), the real method shoud be glocale.translation.sgettext(“string”)
It is more readable to use the “_” method. We could have use other names as _pd for place_display, _nd for name_display…

When used in reports, I think it might be faster if all the translations are done at once creating a dictionary, then just using a dictionary lookup when outputting. The number of words is limited as only headings and english words used by Gramps within the database are required to be translated.
This is only applicable to the report output, not the options.

I think this is how it works.
For each addon, you have a po directory in which you have a file by translated language. If this file does not exist, you don’t have the messages translated.

I am not sure I made myself clear. If we do this in init().
then substitution of individual words remove the overhead involved in calling the translation function each time
word = (“Gramps ID”, “Description”, “Mime Type”, “Media Path”, “Privacy”,
“Attributes”, “Tags”, “Notes”, “Citations”, “People”, “Date”, “Unknown”,
“Public”, “Private”, “None”, “Copyright”, ‘File does not exist’)
self.tword = {}
for each in word:
teach = self._(each)
self.tword[each] = teach

translating a word is merely a case of interrogating the dictionary.


Still talking about translations…
Does Gramps translate things like “Note Type” which stored within gramps as a number but output as a string. Similarly with “Event Type” and probably other “Types”

Yes. This is the case for the narrative web.
See ‘HTML code’ notes in a Narrated Web report - #2 by SNoiraud

1 Like

Last 2 questions hopefully.
Does the Translation Object, in Reports, affect Gramps translation?
If not is there a way to force it to use the selected language?

No. If a string is translated into a gramps language , It can be reused in reports and vice versa.

This answer is in Help with translations in Gramps - #4 by SNoiraud and Help with translations in Gramps - #6 by SNoiraud

Those options do not affect the language used by Gramps when translating things like “Note Type”
“self.underline” does use the option language
but “underline” used by Gramps continues to use the Operating System language of choice.

Yeah, that’s how it works. You can look at the narrative web sources for 5.2 where the report can use up to 6 different languages.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.