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

Posted by Community Admin on 04-Aug-2018 07:00

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

All Replies

Posted by Community Admin on 20-Nov-2011 00:00

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.

Posted by Community Admin on 23-Nov-2011 00:00

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

This thread is closed