Use script/API to add other languages for news or events
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.
Hi Toh,
You can use the GetString() method and pass the desired culture. For example:
GetString(
"Content"
)[
"en"
]
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();