17

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:

The repository:

The installer for Windows:

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?

Community
  • 1
  • 1
tobias47n9e
  • 2,233
  • 3
  • 28
  • 54

2 Answers2

1

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.

Llamax
  • 313
  • 2
  • 13
  • That's not what that does... That indicates the encoding of the .py file. You need that if your source code contains UTF-8 characters. There's still a distinction between `u''` and `''` in Python 2 regardless of that header. To do what you're describing you need to use `from __future__ import unicode_literals`. – Tim Tisdall Oct 31 '19 at 19:24
0

I solved this problem by making all the string Unicode strings. To make a Unicode string, do this: u'Unicode string with fünky charàcters'.