[gnome-boxes] Don't try to use unsupported languages in autoinstalls



commit 3dc5d0aee89c4b2a9ef3ef8d2f77660138f22819
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Thu Dec 13 14:14:53 2012 +0100

    Don't try to use unsupported languages in autoinstalls
    
    Now that libosinfo has an API to report which languages are
    supported by an ISO, we can fix a long-standing bug with Windows
    unattended installations: Windows ISOs only support one language
    most of the time, and we need to specify this language as the
    one to use for installation, otherwise Windows will ask a question.
    
    This commit will first check if the current installer supports one
    of the languages from the user locale and use that if found.
    Otherwise it will fallback to using one of the languages supported
    by the media. If the media does not have any associated language,
    it will use the user locale as the installation language.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685826

 src/unattended-installer.vala |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 5760fa9..9c8b316 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -102,6 +102,31 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
         }
     }
 
+    private string get_preferred_language (InstallerMedia media) {
+        var system_langs = Intl.get_language_names ();
+        var media_langs = new HashTable<string, unowned string> (str_hash, str_equal);
+        var media_langs_list = media.os_media.languages;
+
+        foreach (var lang in media_langs_list)
+            media_langs.add (lang);
+
+        foreach (var lang in system_langs) {
+            if (lang in media_langs) {
+                debug ("matched %s", lang);
+                return lang;
+            }
+        }
+
+        if (media_langs_list != null) {
+            debug ("Failed to match system locales with media languages, falling back to %s media language", media_langs_list.nth_data (0));
+            return media_langs_list.nth_data (0);
+        }
+
+        debug ("No media language, using %s locale", system_langs[0]);
+
+        return system_langs[0];
+    }
+
     public async UnattendedInstaller.from_media (InstallerMedia media, InstallScriptList scripts) throws GLib.Error {
         os = media.os;
         os_media = media.os_media;
@@ -125,8 +150,7 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
         var date = new DateTime.from_timeval_local (time);
         timezone = date.get_timezone_abbreviation ();
 
-        var langs = Intl.get_language_names ();
-        lang = langs[0];
+        lang = get_preferred_language (media);
         kbd = lang;
         product_key_format = get_product_key_format ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]