]> git.ozlabs.org Git - petitboot/blobdiff - discover/device-handler.c
discover: Use translated strings for boot status messages
[petitboot] / discover / device-handler.c
index 22866e6600e29cb869c6196055447fa74b1619f8..5a5210e7956f6a5c707d12f13dff43b28220e756 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)
 {
@@ -381,7 +384,7 @@ static void countdown_status(struct device_handler *handler,
        status.progress = -1;
        status.detail = NULL;
        status.message = talloc_asprintf(handler,
-                       "Booting in %d sec: %s", sec, opt->option->name);
+                       _("Booting in %d sec: %s"), sec, opt->option->name);
 
        discover_server_notify_boot_status(handler->server, &status);
 
@@ -809,7 +812,7 @@ void device_handler_cancel_default(struct device_handler *handler)
        status.type = BOOT_STATUS_INFO;
        status.progress = -1;
        status.detail = NULL;
-       status.message = "Default boot cancelled";
+       status.message = _("Default boot cancelled");
 
        discover_server_notify_boot_status(handler->server, &status);
 }
@@ -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)))
 {