From ea64727f90a5f9a66c2fa81612e46ecdae438303 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/input-device/main.vala | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/input-device/main.vala') diff --git a/src/input-device/main.vala b/src/input-device/main.vala index 372418e..487c028 100644 --- a/src/input-device/main.vala +++ b/src/input-device/main.vala @@ -18,40 +18,43 @@ Device devScanner; Device devRfid; public static int main(string[] args) { + Intl.setlocale(LocaleCategory.ALL, ""); + Intl.textdomain("shopsystem"); + try { Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); devScanner = new Device(cfg.get_string("INPUT", "barcodescanner")); devRfid = new Device(cfg.get_string("INPUT", "rfidreader")); } 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); } catch(DBusError e) { - error("DBus Error: %s\n", e.message); + error(_("DBus Error: %s\n"), e.message); } Bus.own_name( BusType.SYSTEM, "io.mainframe.shopsystem.InputDevice", 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/device/scanner", devScanner); } catch(IOError e) { - stderr.printf("Could not register service\n"); + stderr.printf(_("Could not register service\n")); } try { con.register_object("/io/mainframe/shopsystem/device/rfid", devRfid); } catch(IOError e) { - stderr.printf("Could not register service\n"); + stderr.printf(_("Could not register service\n")); } } -- cgit v1.2.3