GNOME Bugzilla – Bug 690705
Call setlocale from GApplication initialiser
Last modified: 2018-05-24 14:55:04 UTC
gtk_init() (or one of its friends) is needed so that setlocale() is called and gettext is set up correctly (see gettext_initialization() and setlocale_initialization() in gtkmain.c). GtkApplication is encouraging applications to drop their use of gtk_init() in favour of local command line parsing (for example, none of the examples in the GApplication/GtkApplication documentation call gtk_init()). It would make sense to call gtk_init() from somewhere in GtkApplication’s initialisation code.
See bug #690682 for an example of problems caused by this.
gtk_init() should only be called in the primary instance and we don't know if we are the primary instance until we have finished registration. To that end, the base implementation for GtkApplication.startup() does already call gtk_init(). As for gettext -- the best thing to do for now is to do the setlocale() business from main() alongside your bindtextdomain() for your package (which Gtk could not possibly do for you). Later we should try to have a better way for dealing with this from inside of GApplication...
(In reply to comment #2) > As for gettext -- the best thing to do for now is to do the setlocale() > business from main() alongside your bindtextdomain() for your package (which > Gtk could not possibly do for you). Later we should try to have a better way > for dealing with this from inside of GApplication... What stopped me from just calling setlocale() is that GTK+ has a lump of helper code for it which is used on Windows. Totem isn’t packaged for Windows, so that isn’t a problem for us; but it would be nice if that code (in setlocale_initialization()) could be exposed for applications to use even if they can’t call gtk_init(). Maybe move it to GLib?
I think it makes sense for this to be part of GApplication, indeed... We have some functions in GLib for this type of thing already -- the "package install dir" stuff, if I recall correctly. I really don't know too much about the best practices for dealing with installing executables on Windows...
I think this is a GApplication feature request
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/648.