From 4a55802b18262500ffcac80fc3c71bb73cdb840a Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Thu, 1 Dec 2016 11:59:44 +0100 Subject: [PATCH] Allow passing a LOCALE variable in the package list This allows for installing locale packages. This can be achieved by adding a entry of the format packagename-${LOCALE} in the packages configuration module. --- src/modules/locale/LocaleConfiguration.cpp | 2 ++ src/modules/locale/LocaleConfiguration.h | 1 + src/modules/locale/LocalePage.cpp | 2 ++ src/modules/packages/main.py | 17 ++++++++++++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index 096d0dc4e..bf9d940de 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -17,6 +17,7 @@ */ #include "LocaleConfiguration.h" +#include LocaleConfiguration::LocaleConfiguration() { @@ -41,6 +42,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale, { LocaleConfiguration lc = LocaleConfiguration(); QString language = languageLocale.split( '_' ).first(); + lc.myLanguageLocaleBcp47 = QLocale(language).bcp47Name(); QStringList linesForLanguage; for ( const QString &line : availableLocales ) diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index 230e8bdbf..54e498c40 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -38,6 +38,7 @@ public: // avoid confusion with locale.h. QString lang, lc_numeric, lc_time, lc_monetary, lc_paper, lc_name, lc_address, lc_telephone, lc_measurement, lc_identification; + QString myLanguageLocaleBcp47; QMap< QString, QString > toMap(); }; diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 88b030ffe..4b4638215 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -474,6 +474,8 @@ LocalePage::updateGlobalStorage() ->insert( "locationRegion", location.region ); Calamares::JobQueue::instance()->globalStorage() ->insert( "locationZone", location.zone ); + Calamares::JobQueue::instance()->globalStorage() + ->insert( "locale", m_selectedLocaleConfiguration.myLanguageLocaleBcp47); // If we're in chroot mode (normal install mode), then we immediately set the // timezone on the live system. diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index f0f7b38a3..3ec60ff2d 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -21,7 +21,7 @@ import subprocess import libcalamares from libcalamares.utils import check_target_env_call, target_env_call - +from string import Template class PackageManager: """ Package manager class. @@ -109,6 +109,20 @@ class PackageManager: check_target_env_call(["equo", "update"]) +def subst_locale(list): + ret = [] + locale = libcalamares.globalstorage.value("locale") + if locale: + for e in list: + if locale != "en": + entry = Template(e) + ret.append(entry.safe_substitute(LOCALE=locale)) + elif 'LOCALE' not in e: + ret.append(e) + else: + ret = list + return ret + def run_operations(pkgman, entry): """ Call package manager with given parameters. @@ -116,6 +130,7 @@ def run_operations(pkgman, entry): :param entry: """ for key in entry.keys(): + entry[key] = subst_locale(entry[key]) if key == "install": pkgman.install(entry[key]) elif key == "try_install":