Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-ASCII symbols in translation of GTK-GUI in Windows not working?

I have a small python program that shows how to do translations of GTK (pygobject) GUIs for Linux and Windows. Everything works in Linux, but in Windows non-ASCII symbols are not rendered in the translation.

I assume that the both the Glade file and the *.mo file are decoded correctly because:

  • The English interface shows non-ASCII symbols fine
  • Both English and the translations show non-ASCII characters in print-statements

Here is what the interface looks like in the English original:

enter image description here

And the German translation using no environment variable or PANGOCAIRO_BACKEND=win32:

enter image description here

The German translation using the environment variable PANGOCAIRO_BACKEND=fontconfig (PANGOCAIRO_BACKEND=fc). The first label is set to use Calibri using Pango. And that is certainly a font that has "ö", "ä" and "ü" on Windows.

enter image description here

In the console this warning appears for the translation: Pango-Warning **: Invalid UTF-8 string passed to pango_layout_set_text().

Some details about getting the translations to work were already discussed here:

  • Load GTK-Glade translations in Windows using Python/PyGObject

The repository:

  • https://github.com/tobias47n9e/pygobject-locale

The installer for Windows:

  • https://www.dropbox.com/s/hyvgslafa76qppo/pygibank_2.0.exe?dl=0

Is it possible that builder.set_translation_domain("pygibank") pushes the translations with the wrong encoding? Is it possible to debug this or does anyone know how to fix this?

like image 343
tobias47n9e Avatar asked Aug 24 '15 12:08

tobias47n9e


1 Answers

It looks like you are using Python 2. Python 2 uses ASCII by default, however you can tell it to use Unicode by putting this on your first line.

# -*- coding: utf-8 -*-

This saves you prefixing every string with u, as suggested below, which you might forget to do, potentially creating bugs.

Alternatively, if you move to Python 3, it uses Unicode by default, so you do not need to do either.

like image 186
Llamax Avatar answered Oct 18 '22 04:10

Llamax