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

Forums / Developing with Sitefinity / How to enable localization on News Module (Publication Date) ??

How to enable localization on News Module (Publication Date) ??

6 posts, 0 answered
  1. David Martinez
    David Martinez avatar
    13 posts
    Registered:
    24 May 2010
    04 Jan 2011
    Link to this post
    Hi, the language to date for any control News View is always the same (in this case Spanish), no matter if the site location is used for pages in English all display the date in Spanish, is there any way to enable the location for this control?

    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Jan 2011
    Link to this post
    Hello David,

    The control gets the date time value from the database - sf_GCMetaData  table - Publication_Date and Expiration_Date which are metafileds for News provider.  The date is displayed by Literal control inside ListPageMaster template. Possible solution would be replacing the Literal with DateTimeLiteral control which has DateFormatString which can be set in the control template of using server side code - dynamically depending on the current UI culture.

    <telerik:DateTimeLiteral ID="DateTimeLiteral1" runat="server" DateFormatString="" />

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. David Martinez
    David Martinez avatar
    13 posts
    Registered:
    24 May 2010
    06 Jan 2011
    Link to this post
    Hi, thanks for reply, I replaced the Literal control on the DateTimeLiteral suggest the template, but I can not access it through server code, so I can not assign the content dynamically according to culture, any other idea?, this is my code

     <asp:Repeater ID="repeater" runat="server">
            <HeaderTemplate>
                <ul class="NewsLineUL">
            </HeaderTemplate>
            <ItemTemplate>
                <li>
                    <div class="LeftNewsLineLayoutInner">
                        <div class="LeftNewsLineLeftArea">
                            <div class="LeftNewsCategory">
                                <asp:HyperLink ID="Category" runat="server" />
                            </div>
                            <div class="LeftNewsLineTitle">
                                <h4 class="LeftNewsTitleText">
                                    <asp:HyperLink ID="fullContent1" runat="server">
                                        <asp:Literal ID="Title" runat="server"></asp:Literal>
                                    </asp:HyperLink>
                                </h4>
                                <p class="NewsDate">                           
                                    <telerik:DateTimeLiteral ID="Publication_Date" runat="server" DateFormatString="dddd, MMMM dd,  yyyy" />
                                    <%--<asp:Literal ID="Publication_Date" runat="server" Text="{0}" />--%>
                                </p>
                            </div>
                            <div class="NewsLineSummaryHome">
                                <div class="LeftNewsLineSummary">
                                    <asp:Literal runat="server" ID="Summary" />
                                </div>
                            </div>
                        </div>
                    </div>
                </li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Jan 2011
    Link to this post
    Hi David,

    You can access all controls inside the ItemTemplate of the repeater by subscribing for ItemDataBound event of the Repeater inside Page_Load. Then you can use FindControl to get a control declared inside ItemTemplate.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. David Martinez
    David Martinez avatar
    13 posts
    Registered:
    24 May 2010
    08 Jan 2011
    Link to this post
    I tried to assign the culture and the format from the ItemDataBound event, but when trying to access control properties throws an exception, it should be noted that I use the foreach that FindControl does not work, I'm missing something, any ideas?
  6. David Martinez
    David Martinez avatar
    13 posts
    Registered:
    24 May 2010
    08 Jan 2011
    Link to this post
    I'm missing the code server side

    public partial class Sitefinity_ControlTemplates_News_LeftNewsListLine : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                 
        }

        protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //CultureInfo info = new CultureInfo(CultureInfo.CurrentCulture.TwoLetterISOLanguageName); 
            string fecha = string.Empty;
            if (e.Item.Controls != null)
            {
                foreach (Control ctrl in e.Item.Controls)
                {
                    if (ctrl.ID == "Publication_Date")
                    {
                        DateTime dt = new DateTime();
                        dt = DateTime.ParseExact(((DateTimeLiteral)ctrl).Text, "dddd, MMMM dd, yyyy", CultureInfo.CurrentCulture);
                        ((DateTimeLiteral)ctrl).DateFormatString = "dddd, MMMM dd, yyyy";
                    }
                }
            }
        }
    }

Register for webinar
6 posts, 0 answered