lgi-devs / lgi

Dynamic Lua binding to GObject libraries using GObject-Introspection
MIT License
440 stars 70 forks source link

Does lgi call gtk_init on require? #237

Closed v1993 closed 5 years ago

v1993 commented 5 years ago

I'm thinking about adding gettext support into lgi (I think it is appropriate as it is used by GTK internally). However, it seems that one should call a bunch of functions before gtk_init (not so clear about ) to make UI properly localized, so if require 'lgi' already calls it, there is no way to add localization functions in lgi.

psychon commented 5 years ago

Yup, it does call init when you load GTK: https://github.com/pavouk/lgi/blob/ff50e59e85fe808a3bf6783005041449ec2a6bb8/lgi/override/Gtk.lua#L22-L26 So, require("lgi") does not, but require("lgi").GTK does call the init functions.

v1993 commented 5 years ago

So basically adding translations is very possible. To properly use them, user would have to

  1. Load lgi
  2. Call os.setlocale(), bindtextdomain and textdomain
  3. Load Gtk

Thank you. I'll work on adding basic gettext support in next few weeks (I'm very busy right now so even simple job will take quite some time). Speaking of which, many GLib-specific translation functions are already here bridged using proper bindings, so I see no need to manually bind their original inferior versions (take a look at https://developer.gnome.org/glib/stable/glib-I18N.html for information on differences).

What would be the best location for translation-related functions, by the way? Would lgi.gettext.funcname be fine?

psychon commented 5 years ago

What would be the best location for translation-related functions, by the way?

Sorry, no idea. This kind of thing would need input from @pavouk, I think.