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

Forums / Developing with Sitefinity / Use script/API to add other languages for news or events

Use script/API to add other languages for news or events

2 posts, 0 answered
  1. Toh
    Toh avatar
    16 posts
    Registered:
    15 Jun 2011
    20 Nov 2011
    Link to this post
    Currently the news and events content is mix with english and chinese, and recently client want to add chinese language to the site. Is that any way to use script to add chinese version of news/events? or anyway to let the chinese version to view news/events content from english version?

    ps. I don't need to change any content or properties.
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    23 Nov 2011
    Link to this post
    Hi Toh,

    You can use the GetString() method and pass the desired culture. For example:
    GetString("Content")["en"]
    I believe the below sample code, which exemplifies the creation of an item, and modification of its different language versions, would be useful.
    var contentTitle = "Test content " + DateTime.Now.ToString();
         
    // create English version of the content
    Guid itemID = Guid.Empty;
    App.WorkWith().ContentItem().CreateNew()
        .Do(cI =>
        {
            itemID = cI.Id;
            cI.Title["en"] = contentTitle;
            cI.GetString("Content")["en"] = "Original content (en)";
        })
        .Publish()
        .SaveChanges();
         
    // update English content
    App.WorkWith().ContentItem(itemID)
        .Do(i =>
        {
            i.GetString("Content")["en"] = "Update content (en)";
            i.LastModified = DateTime.UtcNow;
        })
        .Publish()
        .SaveChanges();
         
    // add French translation
    App.WorkWith().ContentItem(itemID)
        .Do(c =>
        {
            //c.Content["fr"] = "Initial French content";  // this also doesn't work
            c.GetString("Content")["fr"] = "Initial French content";
            c.Title["fr"] = contentTitle + "-fr";
        })
        .Publish()
        .SaveChanges();


    Best wishes,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered