Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marino Simic 16 posts 53 karma points
    Aug 24, 2009 @ 14:34
    Marino Simic
    0

    How to set the Thread.CurrentThread.CurrentCulture through template or macro?

    I have a problem with translating dictionary items.

    I have done a macro that is supposed to be called at the beginning of the Root template in my site.

    Its purpose is to set the language (intercept language selector choice).

    This is the selector:

              <ul>
                <li><a href="?lang=EN" title="English"><img src="/img/flag_greatbritain.png" alt="English" /></a></li>
                <li><a href="?lang=DE" title="Deutsch"><img src="/img/flag_germany.png" alt="Deutsch" /></a></li>
                <li><a href="?lang=IT" title="Italiano"><img src="/img/flag_italy.png" alt="Italiano" /></a></li>
                <li><a href="?lang=HR" title="Hrvatski"><img src="/img/flag_croatia.png" alt="Hrvatski" /></a></li>
              </ul>

    I use the following xslt macros for the language functions:

    <xsl:param name="initlang">EN</xsl:param>

    <xsl:variable name="dlang"><!-- EN, DE ... -->
      <xsl:choose>
        <xsl:when test="umbraco.library:RequestQueryString('lang') != '' ">
            <xsl:value-of select="umbraco.library:RequestQueryString('lang')" />
        </xsl:when>
        <xsl:when test="umbraco.library:Session('lang') != ''">
            <xsl:value-of select="umbraco.library:Session('lang')" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$initlang" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="flang"><!-- Used to get localized Fields eg. Content_EN, Content_DE ... -->
        <xsl:if test="$dlang != '' and $dlang != $initlang ">
            <xsl:value-of select="concat('_',$dlang)" />
        </xsl:if>
    </xsl:variable>

    <xsl:template name="setlang">
        <xsl:value-of select="umbraco.library:setSession('lang',$dlang) " />
    </xsl:template>

    I use the following method to get localized fields from the 1:1 multilanguage documents (eg. this gets bodyText_DE field for german):

    <xsl:variable name="pageBody" select="$currentPage/data [@alias = concat('bodyText',$flang)]" />

    I'd like to extend the setlang template to set the current UI culture to a desired choice in Asp.Net so the following works as expected:

    <xsl:value-of select="umbraco.library:GetDictionaryItem('Search')"/>

    Is there a library function to set the Culture? I cannot find one and cannot find an alternative method.

    Help is apreciated.

     

    Thanks

  • Marino Simic 16 posts 53 karma points
    Aug 24, 2009 @ 15:30
    Marino Simic
    0

    Nevermind i have modified umbraco.presentation adn added the following to the library:

            /// <summary>
            /// Set the language culture of the current page
            /// </summary>
            /// <param name="language">The language to use</param>
            /// <param name="culture">The langauge culture to use</param>
            public static void setUICulture(string language, string culture)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(language.ToLower() + "-" + culture.ToUpper());
            }

            /// <summary>
            /// Get the language culture of the current page
            /// </summary>
            public static string getUICulture()
            {
                return System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
            }

    and added the following to my setLang xslt template:

    <xsl:value-of select="umbraco.library:setUICulture($dlang,$dlang) " />

    It would be great if these functions are available out of the box in the library ;)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 24, 2009 @ 15:37
    Dirk De Grave
    100

    Why are you modifying the core for that? I'd create a new class library, add your own xslt extensions, register those in xsltExtensions.config and you're set (Find some pointers here. Currently, you'll be having issues when upgrading as you can't replace the presentation dll, or have to redo your changes!)

     

    Cheers,

    /Dirk

     

     

     

  • Marino Simic 16 posts 53 karma points
    Aug 24, 2009 @ 19:34
    Marino Simic
    0

    Thanks for the tip Dirk, I'll try to make an extension later.

    I have finally made the site totally multilingual at last.

    Now with the extension it will be perfect :)

Please Sign in or register to post replies

Write your reply to:

Draft