Search code examples
localizationresourcesinternationalizationembedded-resourcevala

Vala, resources and localization


What is the best way to handle resources (like images, files, ...) in vala? Is there any resource management system? And what is the best way to localize application? I have came to Vala from .NET environment, where localization and resource management is just piece of cake, but I am completely lost now in Vala.

Any suggestions?

Thanks.


Solution

  • GIO 2.32 introduced GResource. Vala documentation is at http://valadoc.org/#!api=gio-2.0/GLib.Resource and C is at http://developer.gnome.org/gio/stable/gio-GResource.html

    The idea for GResource is that you use glib-compile-resources to create C code, which can then be included in your Vala application (you'll probably want to create a trivial VAPI to go with it). I'm not aware of any examples in Vala yet (glib 2.32 was just released), but it should be pretty straightforward.

    Traditionally, though, software on Linux just keeps resources in separate files in an XDG directory. Paths are then either determined based hardcoded values and/or environment variables... GLib even includes functions to make this easy (they're in the GLib.Environment namespace).

    As for i18n/l10n, most software I'm aware of uses gettext. The functions are bound in the GLib namespace (GLib._, GLib.dgettext, GLib.dngettext, etc.). The only real complication is that you need to define GETTEXT_PACKAGE at the C level before Vala includes gi18n-lib.h. If you're compiling to an executable directly from valac you can just pass -X -DGETTEXT_PACKAGE=foo. If you're using a build system you need to figure out how to add C flags within that build system (for autotools you just add them to your *_CFLAGS variables).

    After that, most of the work lies in build system integration and works just like in C, which should be easy for you to figure out for whatever build system you're using (searching Google for "gettext autotools", for example, gets 161k hits).