Page 1 of 1

Qt4 GUI: localization bugs (linux and other platforms) fixed

Posted: 24.08.2011, 18:30
by refsteff
Hello,

I hope these were the last bugs I found :wink:

1. No localizations in Linux:
The directory "locale" contains no .mo files (maybe after a make install under Windows but not in Linux).

Code: Select all

diff -urN celestia.org/src/celestia/qt/qtmain.cpp celestia/src/celestia/qt/qtmain.cpp
--- celestia.org/src/celestia/qt/qtmain.cpp   2011-08-19 16:04:59.000000000 +0200
+++ celestia/src/celestia/qt/qtmain.cpp   2011-08-24 18:47:44.493630131 +0200
@@ -63,9 +63,11 @@
     // Gettext integration
     setlocale(LC_ALL, "");
     setlocale(LC_NUMERIC, "C");
+#ifndef __linux
     bindtextdomain("celestia","locale");
-    bind_textdomain_codeset("celestia", "UTF-8");
     bindtextdomain("celestia_constellations","locale");
+#endif
+    bind_textdomain_codeset("celestia", "UTF-8");
     bind_textdomain_codeset("celestia_constellations", "UTF-8");
     textdomain("celestia");

 


That leads into the next bug.

2. I found no translatable strings from the .ui.h files.
So I try to make an " make update-po" in the po directory and get the error message: "File src/celengine/asterism.cpp not found" :o .
With wo blanks after asterism.cpp?! It should be one.
The reason was the file POTFILES.in contains Windows/DOS line endings (the only file in the whole po directory, and the whole src tree).
After converting the file, "make update-po" works, but again no translatable strings from the .ui.h files.

So I created a Rules-qt file (based on Rules-kde):

Code: Select all

diff -urN celestia.org/po/Rules-qt celestia/po/Rules-qt
--- celestia.org/po/Rules-qt   1970-01-01 01:00:00.000000000 +0100
+++ celestia/po/Rules-qt   2011-08-24 18:43:02.447754472 +0200
@@ -0,0 +1,15 @@
+# Additional Makefile rule to extract strings from Qt ui files.
+
+Makefile: Rules-qt
+
+XGETTEXT_OPTIONS += --qt
+
+celestia.pot-update: ../src/celestia/qt/rc.cpp
+
+../src/celestia/qt/rc.cpp:
+   extractrc ../src/celestia/qt/*.ui > ../src/celestia/qt/rc.cpp
+
+clean: clean-qt
+
+clean-qt:
+   rm -f ../src/celestia/qt/rc.cpp

The line "XGETTEXT_OPTIONS += --qt" is needed to mark format strings like "%L1" as qt format.

then I have to patch POTFILES.in to reflect the changes.
(don't forget to convert POTFILES.in to Unix/Linux format)

Code: Select all

diff -urN celestia.org/po/POTFILES.in celestia/po/POTFILES.in
--- celestia.org/po/POTFILES.in   2011-08-19 16:05:45.000000000 +0200
+++ celestia/po/POTFILES.in   2011-08-24 18:45:37.089629689 +0200
@@ -123,10 +123,6 @@
 src/celestia/qt/qtsettimedialog.cpp
 src/celestia/qt/qtsolarsystembrowser.cpp
 src/celestia/qt/qttimetoolbar.cpp
+src/celestia/qt/rc.cpp
 src/celestia/qt/xbel.cpp
 
-# Qt headers generated from reading UI files
-src/celestia/qt/ui/ui_addbookmark.h
-src/celestia/qt/ui/ui_newbookmarkfolder.h
-src/celestia/qt/ui/ui_organizebookmarks.h
-src/celestia/qt/ui/ui_preferences.h

Now I get translatable strings and the next bug was rising :?

3. The EventFinder doesn't work anymore - this bug affects all platforms with localizations
I always got an "... is not a valid object" error message.
I found the use of the "simple" method of addItem in the planetSelect combobox was wrong.

Code: Select all

--- celestia.org/src/celestia/qt/qteventfinder.cpp   2011-08-19 16:04:59.000000000 +0200
+++ celestia/src/celestia/qt/qteventfinder.cpp   2011-08-24 18:47:18.330628794 +0200
@@ -598,12 +598,12 @@
     layout->addWidget(subgroup);
 
     planetSelect = new QComboBox();
-    planetSelect->addItem(_("Earth"));
-    planetSelect->addItem(_("Jupiter"));
-    planetSelect->addItem(_("Saturn"));
-    planetSelect->addItem(_("Uranus"));
-    planetSelect->addItem(_("Neptune"));
-    planetSelect->addItem(_("Pluto"));
+    planetSelect->addItem(_("Earth"), "Earth");
+    planetSelect->addItem(_("Jupiter"), "Jupiter");
+    planetSelect->addItem(_("Saturn"), "Saturn");
+    planetSelect->addItem(_("Uranus"), "Uranus");
+    planetSelect->addItem(_("Neptune"), "Neptune");
+    planetSelect->addItem(_("Pluto"), "Pluto");
     layout->addWidget(planetSelect);
 
     QPushButton* findButton = new QPushButton(_("Find eclipses"));

Now it works again.

That's all for today :)

See you

Re: Qt4 GUI: localization bugs (linux and other platforms) f

Posted: 24.08.2011, 22:27
by Fenerit
Thank-you for your help here. 8)

Re: Qt4 GUI: localization bugs (linux and other platforms) f

Posted: 26.08.2011, 08:22
by Vincent
Hi refsteff,

Thanks for your precious help on debugging the localization code.
I've added i18n support to the qt4 version of Celestia, but since I'm
on windows exclusively, I can't track the linux bugs.

I've been personnaly building the ui.h files using the qt integrated ui compiler:

Code: Select all

uic -tr _ addbookmark.ui -o ui/ui_addbookmark.h
uic -tr _ newbookmarkfolder.ui -o ui/ui_newbookmarkfolder.h
uic -tr _ organizebookmarks.ui -o ui/ui_organizebookmarks.h
uic -tr _ preferences.ui -o ui/ui_preferences.h

Then I've been extracting the translation files, e.g., fr.po, using:

Code: Select all

xgettext -j --omit-header --keyword=_ -o fr.po -f POTFILES_qt.in
And everything went fine...

But adding the Rules-qt file is definitely the right thing to do to get the ui.h files
extracted with a "make update-po", since this is the process we've been using until now.
I unable test your change, though, because I can't get the autotools working on windows...

As to the EventFinder issue, I didn't get any compilation error with MSVC++ 2008 Express,
not even a compiler warning, which is quite strange...

I'll submit all your i18n fixes to the devs list, and I'll be commiting them ASAP if our linux devs are
ok with them. Also, Chris L. may add you to the devs mailing list, which would be an even better option. :)

Re: Qt4 GUI: localization bugs (linux and other platforms) f

Posted: 26.08.2011, 12:19
by refsteff
Hello Vincent,
Vincent wrote:As to the EventFinder issue, I didn't get any compilation error with MSVC++ 2008 Express,
not even a compiler warning, which is quite strange...
Maybe I have to point out clearer what I mean. The error message came from celestia.
The method is not wrong , you get what you want :wink:
If you leave the second parameter out, it returns (in this case) the translated string and celestia expected an untranslated object name.
There are a lot of classes and methods in Qt that behave the same. If you leave a parameter out, it takes a default value.
That's sometimes a little bit confusing, to be sure you have to read the docs.

Vincent wrote:I'll submit all your i18n fixes to the devs list, and I'll be commiting them ASAP if our linux devs are
ok with them. Also, Chris L. may add you to the devs mailing list, which would be an even better option. :)
Maybe, but I'm really not a programmer. I can adapt code from others, see if it fits my needs and if it works.
I don't know anything about c++, but years ago I spent my time with 8/16 bit assembler and use Turbo Vision from Borland for a little GUI programming.
A GUI toolkit like Qt is similar to Turbo Vision, that's helps a lot and the Celestia source is (partially :wink: ) readable as a book.
For me it's fun to test a program that I like (my friends say "He is bug hunting, don't disturb" :lol: ).
So, if I can help I will do.

See you