From 8e60fa48a8535da9eaa34ef35b5040c2eb68fc3b Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Thu, 28 Jun 2018 21:35:23 +0200 Subject: all: I18N support This adds I18N support using standard gettext system together with an initial German translation. This can be used to search locales in some directory: Intl.bindtextdomain("shopsystem", "/home/sre/src/serial-barcode-scanner"); And this can be used to switch language at runtime: Intl.setlocale(LocaleCategory.ALL, ""); --- src/pgp/Makefile | 2 +- src/pgp/main.vala | 18 ++++++++++-------- src/pgp/pgp.vala | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/pgp') diff --git a/src/pgp/Makefile b/src/pgp/Makefile index 6292111..5faa80f 100644 --- a/src/pgp/Makefile +++ b/src/pgp/Makefile @@ -2,7 +2,7 @@ all: pgp @echo > /dev/null pgp: main.vala pgp.vala pgp-interface.vala ../config/config-interface.vala - valac --Xcc="-D_FILE_OFFSET_BITS=64" -X -w -o $@ --vapidir ../../vapi -X -lgpgme --pkg gpgme --pkg gio-2.0 --pkg libarchive $^ + valac -X -D'GETTEXT_PACKAGE="shopsystem"' --Xcc="-D_FILE_OFFSET_BITS=64" -X -w -o $@ --vapidir ../../vapi -X -lgpgme --pkg gpgme --pkg gio-2.0 --pkg libarchive $^ clean: rm -rf pgp diff --git a/src/pgp/main.vala b/src/pgp/main.vala index 332bcd5..74bcf0e 100644 --- a/src/pgp/main.vala +++ b/src/pgp/main.vala @@ -21,35 +21,37 @@ PGPKeyArchive pgp; Config cfg; public static int main(string[] args) { + Intl.setlocale(LocaleCategory.ALL, ""); + Intl.textdomain("shopsystem"); + try { cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); pgp = new PGPKeyArchive(cfg.get_string("PGP", "keyring")); } catch(DBusError e) { - error("DBusError: %s\n", e.message); + error(_("DBus Error: %s\n"), e.message); } catch(IOError e) { - error("IOError: %s\n", e.message); + error(_("IO Error: %s\n"), e.message); } catch(KeyFileError e) { - error("Config Error: %s\n", e.message); + error(_("Config Error: %s\n"), e.message); } - Bus.own_name( BusType.SYSTEM, "io.mainframe.shopsystem.PGP", BusNameOwnerFlags.NONE, - on_bus_aquired, + on_bus_acquired, () => {}, - () => stderr.printf("Could not aquire name\n")); + () => stderr.printf(_("Could not acquire name\n"))); new MainLoop().run(); return 0; } -void on_bus_aquired(DBusConnection con) { +void on_bus_acquired(DBusConnection con) { try { con.register_object("/io/mainframe/shopsystem/pgp", pgp); } catch(IOError e) { - stderr.printf("Could not register service\n"); + stderr.printf(_("Could not register service\n")); } } diff --git a/src/pgp/pgp.vala b/src/pgp/pgp.vala index 2a5b160..6d9bed0 100644 --- a/src/pgp/pgp.vala +++ b/src/pgp/pgp.vala @@ -120,7 +120,7 @@ public class PGPKeyArchive { keydata.read(data); return (string) data; } else { - stdout.printf("error!\n"); + stdout.printf(_("Error!\n")); return ""; } } -- cgit v1.2.3