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

[virt-tools-list] [libosinfo v5] install-scripts: Translate lang format when needed



Add this translation in the windows template file because the script
must have the language is being set using
https://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Locale-Names.html
While, for Windows, the standard being used is:
https://www.ietf.org/rfc/rfc4646.txt (page 56, Language-Region topic).

A practical example is:
Windows will use, for Brazilian Portuguese, pt-BR instead of pt_BR.
---
 data/install-scripts/windows-unattend.xml | 50 ++++++++++++++++++++++++++-----
 osinfo/osinfo_install_config.c            | 13 +++++++-
 2 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/data/install-scripts/windows-unattend.xml b/data/install-scripts/windows-unattend.xml
index d3b2df5..a4f58ae 100644
--- a/data/install-scripts/windows-unattend.xml
+++ b/data/install-scripts/windows-unattend.xml
@@ -32,6 +32,23 @@
           </xsl:choose>
         </xsl:template>
 
+        <xsl:template name="language">
+          <xsl:variable name="l10n-language">
+            <xsl:value-of select="config/l10n-language"/>
+          </xsl:variable>
+          <xsl:variable name="formatted-l10n-language">
+            <xsl:value-of select="translate($l10n-language,'_','-')"/>
+          </xsl:variable>
+          <xsl:choose>
+            <xsl:when test="contains($formatted-l10n-language,'.')">
+              <xsl:value-of select="substring-before($formatted-l10n-language,'.')"/>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:value-of select="$formatted-l10n-language"/>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:template>
+
 	<xsl:template name="arch">
 	  <xsl:choose>
 	    <xsl:when test="count(config/hardware-arch) &gt; 0">
@@ -99,11 +116,11 @@
 		  <xsl:call-template name="arch"/>
 		</xsl:attribute>
 		<SetupUILanguage>
-		  <UILanguage><xsl:value-of select="config/l10n-language"/></UILanguage>
+		  <UILanguage><xsl:call-template name="language"/></UILanguage>
 		</SetupUILanguage>
-		<SystemLocale><xsl:value-of select="config/l10n-language"/></SystemLocale>
-		<UILanguage><xsl:value-of select="config/l10n-language"/></UILanguage>
-		<UserLocale><xsl:value-of select="config/l10n-language"/></UserLocale>
+		<SystemLocale><xsl:call-template name="language"/></SystemLocale>
+		<UILanguage><xsl:call-template name="language"/></UILanguage>
+		<UserLocale><xsl:call-template name="language"/></UserLocale>
 	      </component>
 	    </settings>
 	    <settings pass="oobeSystem">
@@ -213,6 +230,23 @@
         </xsl:choose>
       </xsl:template>
 
+      <xsl:template name="language">
+        <xsl:variable name="l10n-language">
+          <xsl:value-of select="config/l10n-language"/>
+        </xsl:variable>
+        <xsl:variable name="formatted-l10n-language">
+          <xsl:value-of select="translate($l10n-language,'_','-')"/>
+        </xsl:variable>
+        <xsl:choose>
+          <xsl:when test="contains($formatted-l10n-language,'.')">
+            <xsl:value-of select="substring-before($formatted-l10n-language,'.')"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$formatted-l10n-language"/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:template>
+
       <xsl:template name="arch">
        <xsl:choose>
         <xsl:when test="config/hardware-arch = 'x86_64'">
@@ -283,11 +317,11 @@
           <xsl:call-template name="arch"/>
          </xsl:attribute>
          <SetupUILanguage>
-          <UILanguage><xsl:value-of select="config/l10n-language"/></UILanguage>
+          <UILanguage><xsl:call-template name="language"/></UILanguage>
          </SetupUILanguage>
-         <SystemLocale><xsl:value-of select="config/l10n-language"/></SystemLocale>
-         <UILanguage><xsl:value-of select="config/l10n-language"/></UILanguage>
-         <UserLocale><xsl:value-of select="config/l10n-language"/></UserLocale>
+         <SystemLocale><xsl:call-template name="language"/></SystemLocale>
+         <UILanguage><xsl:call-template name="language"/></UILanguage>
+         <UserLocale><xsl:call-template name="language"/></UserLocale>
         </component>
        </settings>
        <xsl:if test="os/version &gt; 6.0">
diff --git a/osinfo/osinfo_install_config.c b/osinfo/osinfo_install_config.c
index a2ee496..a7fc3c2 100644
--- a/osinfo/osinfo_install_config.c
+++ b/osinfo/osinfo_install_config.c
@@ -140,7 +140,18 @@ const gchar *osinfo_install_config_get_l10n_keyboard(OsinfoInstallConfig *config
                                          OSINFO_INSTALL_CONFIG_PROP_L10N_KEYBOARD);
 }
 
-
+/**
+ * osinfo_install_config_set_l10n_language:
+ *
+ * Sets the #OSINFO_INSTALL_CONFIG_PROP_L10N_LANGUAGE parameter.
+ *
+ * The expected format to set l10n_language follows the gettext Locale Names
+ * standard, https://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Locale-Names.html,
+ * with both encoding and variant are accepted but are optional.
+ *
+ * For example, 'pt_BR' is used to Brazilian Portuguese. 'pt_BR.utf8' is
+ * accepted but the encoding part is optional.
+ */
 void osinfo_install_config_set_l10n_language(OsinfoInstallConfig *config,
                                              const gchar *language)
 {
-- 
1.8.0


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