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/web/main.vala | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/web/main.vala') diff --git a/src/web/main.vala b/src/web/main.vala index e249d81..f7b0c30 100644 --- a/src/web/main.vala +++ b/src/web/main.vala @@ -21,6 +21,9 @@ public AudioPlayer audio; string templatedir; public static int main(string[] args) { + Intl.setlocale(LocaleCategory.ALL, ""); + Intl.textdomain("shopsystem"); + TlsCertificate? cert = null; string certificate = ""; string privatekey = ""; @@ -30,7 +33,7 @@ public static int main(string[] args) { db = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Database", "/io/mainframe/shopsystem/database"); pgp = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.PGP", "/io/mainframe/shopsystem/pgp"); cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - audio = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.AudioPlayer", "/io/mainframe/shopsystem/audio"); + audio = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.AudioPlayer", "/io/mainframe/shopsystem/audio"); templatedir = cfg.get_string("WEB", "filepath"); port = cfg.get_integer("WEB", "port"); @@ -38,19 +41,19 @@ public static int main(string[] args) { certificate = cfg.get_string("WEB", "cert"); privatekey = cfg.get_string("WEB", "key"); } catch(KeyFileError e) { - warning("KeyFileError: %s\n", e.message); + warning(_("KeyFile 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("KeyFileError: %s\n", e.message); + error(_("KeyFile Error: %s\n"), e.message); } catch(DBusError e) { - error("DBusError: %s\n", e.message); + error(_("DBus Error: %s\n"), e.message); } - stdout.printf("Web Server Port: %u\n", port); - stdout.printf("TLS certificate: %s\n", certificate); - stdout.printf("TLS private key: %s\n", privatekey); + stdout.printf(_("Web Server Port: %u\n"), port); + stdout.printf(_("TLS certificate: %s\n"), certificate); + stdout.printf(_("TLS private key: %s\n"), privatekey); /* attach WebServer to MainLoop */ try { @@ -58,7 +61,7 @@ public static int main(string[] args) { cert = new TlsCertificate.from_files(certificate, privatekey); new WebServer(port, cert); } catch(Error e) { - error("Could not start Webserver: %s\n", e.message); + error(_("Could not start Webserver: %s\n"), e.message); } /* start MainLoop */ -- cgit v1.2.3