I'm having an issue figuring out two things in a piece of code of mine.
In essence, I work on a website that has multiple languages, and multiple countries. Depending on your location, you may see different content, prices etc.
The nodes for the countries are found at:
Home -> Localization -> [countries (like Sweden, Denmark etc)]
All countries are setup properly in English language, however we now need to fill in the German names for them. All German nodes are unpublished, and will need the "Name" value as well as a property called "countryName" set.
An extract of my code is below:
for (int x = 0; x < match.Count; x++) //match is an array of each country in the world, containing name and iso2 code
{
if (match[x].Success)
{
string countryname = Common.Helper.RegularExpressions.GetFirstValue(match[x].Value, @"<span style=""display:none"">(.*)</span>");
string countrycode = Common.Helper.RegularExpressions.GetFirstValue(match[x].Value, @"<td>(..)</td>");
if (string.IsNullOrEmpty(countryname) || string.IsNullOrEmpty(countrycode))
{
continue;
}
countrycode = countrycode.ToLower();
var countries = local.ChildrenForAllCultures;
var country = countries.FirstOrDefault(a => a.Value<string>("countryCode").Equals(countrycode));
if (country == null)
{
continue;
}
//Converting IPublishedContent to IContent, as required by content service
IContent c = _contentService.GetById(country.Id);
c.Name = countryname;
c.SetValue("countryName", countryname, "de");
_contentService.SaveAndPublish(c, "de", -1, false);
}
}
There are two things that I cannot get my head around:
The c.Name does not appear to work
The language variant is not saved and published.
I've checked for validation errors that could have prevented this, but no.
If I publish the language variant beforehand, lets say for Sweden, so it has a published German node with name "S", the:
Publishing language variant via API
Hello everyone,
I'm having an issue figuring out two things in a piece of code of mine.
In essence, I work on a website that has multiple languages, and multiple countries. Depending on your location, you may see different content, prices etc.
The nodes for the countries are found at:
Home -> Localization -> [countries (like Sweden, Denmark etc)]
All countries are setup properly in English language, however we now need to fill in the German names for them. All German nodes are unpublished, and will need the "Name" value as well as a property called "countryName" set.
An extract of my code is below:
There are two things that I cannot get my head around:
I've checked for validation errors that could have prevented this, but no. If I publish the language variant beforehand, lets say for Sweden, so it has a published German node with name "S", the:
works, however c.Name is not set.
It's driving me a bit crazy, so any help would be greatly appreciated!
Best regards
Peter
Hi again,
Sometimes I guess it helps simply asking the problem out loud to yourself... I completely missed the "iContent.CultureInfos".
If anyone else runs into this, hopefully it will save someone some time :)
Also, sorry for the ugly code, but it's intended to run once, then hit the trash bin.
Best regards
Peter
is working on a reply...