]> git.ozlabs.org Git - petitboot/commitdiff
discover: Add setlocale calls in discover server
authorJeremy Kerr <jk@ozlabs.org>
Mon, 28 Jul 2014 04:09:14 +0000 (12:09 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 28 Jul 2014 06:23:11 +0000 (14:23 +0800)
We want the discover server to respect the configured language, so we'll
need to add appropriate setlocale() calls. We use the config->lang
setting to use any previously-saved language.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/Makefile.am
discover/device-handler.c
discover/pb-discover.c

index 5d5f5b42787df172e5804f6c08678f1ac512bd88..01c29d790ef842bc8bf4b3d9d4ad9c03ab97e5a6 100644 (file)
@@ -16,7 +16,9 @@ pkgsysconfdir = @sysconfdir@/@PACKAGE@
 
 SUBDIRS = grub2
 
-AM_CPPFLAGS = -I$(top_srcdir)/lib $(DEFAULT_CPPFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/lib \
+       -DLOCALEDIR='"$(localedir)"' \
+       $(DEFAULT_CPPFLAGS)
 
 AM_CFLAGS = $(DEFAULT_CFLAGS)  \
        -DPREFIX='"$(prefix)"' \
index 22866e6600e29cb869c6196055447fa74b1619f8..e7990e7ab05f288331c8c09b54b9c3ef70b94319 100644 (file)
@@ -16,6 +16,7 @@
 #include <system/system.h>
 #include <process/process.h>
 #include <url/url.h>
+#include <i18n/i18n.h>
 
 #include "device-handler.h"
 #include "discover-server.h"
@@ -59,6 +60,8 @@ static int umount_device(struct discover_device *dev);
 static int device_handler_init_sources(struct device_handler *handler);
 static void device_handler_reinit_sources(struct device_handler *handler);
 
+static void device_handler_update_lang(const char *lang);
+
 void discover_context_add_boot_option(struct discover_context *ctx,
                struct discover_boot_option *boot_option)
 {
@@ -824,11 +827,26 @@ void device_handler_update_config(struct device_handler *handler,
                return;
 
        discover_server_notify_config(handler->server, config);
+       device_handler_update_lang(config->lang);
        device_handler_reinit(handler);
 }
 
 #ifndef PETITBOOT_TEST
 
+static void device_handler_update_lang(const char *lang)
+{
+       const char *cur_lang;
+
+       if (!lang)
+               return;
+
+       cur_lang = setlocale(LC_ALL, NULL);
+       if (cur_lang && !strcmp(cur_lang, lang))
+               return;
+
+       setlocale(LC_ALL, lang);
+}
+
 static int device_handler_init_sources(struct device_handler *handler)
 {
        /* init our device sources: udev, network and user events */
@@ -1025,6 +1043,10 @@ void device_release_write(struct discover_device *dev, bool release)
 
 #else
 
+static void device_handler_update_lang(const char *lang __attribute__((unused)))
+{
+}
+
 static int device_handler_init_sources(
                struct device_handler *handler __attribute__((unused)))
 {
index f876a3d3f517e98eee2e074042717e96b7c1fd2f..81c582dcf201425a8fca7149a16832adba456a49 100644 (file)
@@ -13,6 +13,7 @@
 #include <log/log.h>
 #include <process/process.h>
 #include <talloc/talloc.h>
+#include <i18n/i18n.h>
 
 #include "discover-server.h"
 #include "device-handler.h"
@@ -127,6 +128,10 @@ int main(int argc, char *argv[])
        struct opts opts;
        FILE *log;
 
+       setlocale(LC_ALL, "");
+       bindtextdomain(PACKAGE, LOCALEDIR);
+       textdomain(PACKAGE);
+
        if (opts_parse(&opts, argc, argv)) {
                print_usage();
                return EXIT_FAILURE;
@@ -177,6 +182,9 @@ int main(int argc, char *argv[])
        if (opts.no_autoboot == opt_yes)
                config_set_autoboot(false);
 
+       if (config_get()->lang)
+               setlocale(LC_ALL, config_get()->lang);
+
        system_info_init(server);
 
        handler = device_handler_init(server, waitset, opts.dry_run == opt_yes);