1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Displaying metafield based on CurrentUICulture name

Displaying metafield based on CurrentUICulture name

6 posts, 0 answered
  1. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    28 Nov 2008
    Link to this post
    hello Telerik Team

    Because the Images & Documents module doesn't support localization I defined 3 new metafields for describing the name of the image in 3 different languages. The name of the fields are ENTitle, DETitle and NLTitle.

    Localization settings are set and work great

    The definition of the value of these metafields works fine too. But now I want to show the correct image name on the public site dependent on the selected language.
    First of all I made a change in the GalleryListViewTemplate.ascx in the ~/Sitefinity/ControlTemplates/Libraries folder:

    <asp:Repeater ID="repeater" runat="server">
    <HeaderTemplate><ol class="sf_listAndPage"></HeaderTemplate>
    <ItemTemplate>
    <li>
    <dl>
    <dd class="sf_image"><asp:HyperLink ID="DownloadLink" runat="server" /></dd>
    <dd ID="Dd1" runat="server" visible='<%# (System.Threading.Thread.CurrentThread.CurrentUICulture.Name = "en") %>'>
        <asp:HyperLink ID="ENTitle" runat="server" />
    </dd>
    <dd ID="Dd2" runat="server" visible='<%# (System.Threading.Thread.CurrentThread.CurrentUICulture.Name = "de") %>'>
        <asp:HyperLink ID="DETitle" runat="server" />
    </dd>
    <dd ID="Dd3" runat="server" visible='<%# (System.Threading.Thread.CurrentThread.CurrentUICulture.Name = "nl") %>'>
        <asp:HyperLink ID="NLTitle" runat="server" />
    </dd>
    <dt ID="TitleWrap" runat="server">
    ......

    In this control defining the visible property (with visible='<%# (System.Threading.Thread.CurrentThread.CurrentUICulture.Name = "en") %>'>
    ) of the dd tag works perfect.

    However when I try the same thing in the GalleryListViewItemTemplate.ascx like:

    <p ID="P1" runat="server" class="sf_singleImageCaption" Visible='<%# (System.Threading.Thread.CurrentThread.CurrentUICulture.Name = "en") %>'>
    <strong><asp:Literal ID="ENTitle" runat="server" /></strong>
    </p>

    it doesn't work anymore. The visible proprty is always true and all metafields (independent of the selected language) are shown in this control.

    Have you any idea why this is? Or should I implement it in another way? Hope you can help.

    Regards
    Luc

  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    02 Dec 2008
    Link to this post
    Hi Luc Baeten,

    I am going to give you an other solution. You can turn on the localization for the Images and Documents module, but we are still a couple of things in that area. Still, I believe you can work like that for now. Here is what you have to do:

    1. Set the localization option in your web.config file and <localization> node.
    2. Create a new metafield, named for example MyField. Define localizable=True attribute for that metafield:
    <add key="Libraries.MyField"  
     localizable="True"  
     valueType="ShortText"  
     visible="True"  
     searchable="True"  
     sortable="True"  
     defaultValue="" /> 

    3. Assign this metafield to libraries with type "Images" (in the web.config file):
    <libraryInfo> 
            <add name="Image" 
             title="Image Library"  
             defaultExtenstions=".png, .jpg, .jpeg, .gif"  
             metaKeys="Author, AlternateText, Extension, Name, Height, Width, Size, 
                                  Category, MyField"> 
            </add> 

    4. Make your changes in ControlPanelEdit_Image.ascx control template in order to include this metafield.
    5. Commentout the following container in the control template ControlPanelEdit_Image.ascx:
    <%--<div class="info"
                    <asp:PlaceHolder ID="languagePanel" runat="server"
    ............. 
    </h3> 
    </div>--%> 

    Attached is my ControlPanelEdit_Image.ascx after commenting out the necessary code. You can compare/use it with your project.

    6. Attached is what you should see in the View tab in your library item screen.

    Here is what I did to localize this item. I suggest you following the same steps:
    1. Selected an Eglish version from the upper right corner of the screen.
    2. Uploaded an item to the library.
    3. Filled all fields with the desired values
    4. Clicked on a language in the lower right corner, from the newly appeared "Change Language" section.
    At this point, a new content item version is created.

    5. Click on "Edit" and fill the information for the new language.

    An important is not to change the Title metafield for the item having different language version. That is why I created a new metafield for that purpose. You should also know that the Libraries are showing only these items which have the currently selected language version available. Step 4 (with bold) is actually creating a language version of the item.

    I hope this helps you.

    Greetings,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    03 Dec 2008
    Link to this post

    Hi Georgi

    I did exactly the same thing as you described for the metafields ENTitle, DETitle and NLTitle. I didn't change anything in the metafield Title but added my own metafields.
    And I also changed the ControlPanelEdit_Image.aspx as described (for your info: the language panel placeholder was already commented out).

    That part works fine: I can edit those metafields.

    Buit I also changed  GalleryListViewTemplate.ascx and  GalleryListViewItemTemplate.ascx as described in an earlier post. And in the  GalleryListViewItemTemplate.ascx especially it doesn't work like I want.

    I want to present the metafield that corresponds with the selected language. This works in GalleryListViewTemplate.ascx with the code

    <asp:Repeater ID="repeater" runat="server">
    <HeaderTemplate><ol class="sf_listAndPage"></HeaderTemplate>
    <ItemTemplate>
    <li>
    <dl>
    <dd class="sf_image"><asp:HyperLink ID="DownloadLink" runat="server" /></dd>
    <dd ID="Dd1" runat="server" visible='<%# (System.Threading.Thread.CurrentThread.CurrentUICulture.Name = "en") %>'>
        <asp:HyperLink ID="ENTitle" runat="server" />
    </dd>
    <dd ID="Dd2" runat="server" visible='<%# (System.Threading.Thread.CurrentThread.CurrentUICulture.Name = "de") %>'>
        <asp:HyperLink ID="DETitle" runat="server" />
    </dd>
    <dd ID="Dd3" runat="server" visible='<%# (System.Threading.Thread.CurrentThread.CurrentUICulture.Name = "nl") %>'>
        <asp:HyperLink ID="NLTitle" runat="server" />
    </dd>
    <dt ID="TitleWrap" runat="server">
    ......

    but not in GalleryListViewItemTemplate.ascx. And I have no idea why.

    Regards
    Luc

  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    23 Dec 2008
    Link to this post
    Hello Luc,

    We are sorry for the late response.

    The expression defining the Visible property can be evaluated only in a databound control (for example repeater). That is the reason why your code works in List mode but does not work in Single Item mode of the Image Gallery control.

    A possible solution is to override ImageGallery control and check the current culture in SetSingleItemMetadata method like this:

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Telerik.Libraries.WebControls; 
    using Telerik.Cms.Engine; 
     
    namespace Telerik.Libraries.WebControls 
            protected override void SetSingleItemMetadata(Control itemContainer, IContent contentItem) 
            { 
                base.SetSingleItemMetadata(itemContainer, contentItem); 
                HtmlGenericControl p1 = itemContainer.FindControl("P1"as HtmlGenericControl; 
     
                if (p1 != null
                { 
                    p1.Visible = (System.Threading.Thread.CurrentThread.CurrentUICulture.Name == "en"); 
                } 
            } 
        } 

    Then, you should register the new control in the project web.config to display it in Add Controls toolbox:

    <toolboxControls> 
            ... 
            <add name="ImageGalleryExtender" section="Images &amp; Documents" type="Telerik.Libraries.WebControls.ImageGalleryExtender, App_Code" /> 
            ... 

    Hope this helps.

    All the best,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. dimiter
    dimiter avatar
    13 posts
    Registered:
    25 Apr 2007
    15 Jun 2009
    Link to this post
    Hi

    I have a problem with localization of the image library. When I write in web.config allowLocalization=true all images disappeared. Could you help me?

     
     
  6. Stoyanka Assenova
    Stoyanka Assenova avatar
    113 posts
    Registered:
    01 Dec 2016
    15 Jun 2009
    Link to this post
    Hello dimiter,

    This is a known issue in Sitefinity 3.6 SP1. It will be fixed in Sitefinity 4.0. Unfortunately, we cannot provide you with any work around so far.

    We apologize for the inconvenience.

    All the best,
    Stoyanka Assenova
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
6 posts, 0 answered