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

Forums / Developing with Sitefinity / Add programmatically content for diffrent culture

Add programmatically content for diffrent culture

6 posts, 0 answered
  1. DPC David
    DPC David avatar
    26 posts
    Registered:
    28 Dec 2009
    30 Jun 2010
    Link to this post
    Hi

    right now im working on a solution in which i can add translated content to an excisting article(content). For example:
    The customer add's via backend a new article right after base. SaveContent (); im calling within GetPreviewCommand my custom Method with the ID of the new Content.
            private void TestCulture(Guid ID)
            {          
                try
                {
                    CultureInfo oCulture = new CultureInfo("en");
                    System.Threading.Thread.CurrentThread.CurrentUICulture = oCulture;
                  
                    ContentManager oM3 = new ContentManager("Articles");
                  
                    IContent oTest3 = oM3.GetContent(ID);
                    if (oTest3 != null)
                        {
                            oTest3.Languages.Add("en");
                            oTest3.Language = "en";
                            oTest3.MimeType = "text/html";
                            oTest3.Content = "English rules";
                            oTest3.SetMetaData("Title", "English title");
                            oTest3.SetMetaData("CaptionTeaser", "English teaser");
                            oTest3.SetMetaData("DescriptionTeaser", "English description");
                            oTest3.SetMetaData("Picture", "English picture");

                            oM3.SaveContent(oTest3);                        
                        }               
                }
                catch (Exception)
                {

                }
    My problem is now that the english version of Article is not marked as set. I had a look at the database and it seems that SF has added the new language version to the article (table sf_GCMetaData) but the Backend doesn't show any metadata i have set. I have also searched the forum an found some threads but no one was helpfull. Question now is it possible to add programmatically content for diffrent culture to an excisting content?

    Regards David
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    30 Jun 2010
    Link to this post
    Hello DPC David,

    Below is a sample code that you can illustrate how to set up your custom metakeys for a newly created culture ( in this case "bg")

    CultureInfo backupCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
    CultureInfo cult = new CultureInfo("bg");
    System.Threading.Thread.CurrentThread.CurrentUICulture = cult;
    IContent target = this.Manager.GetStagedContent(this.DataItemId);
    target.SetMetaData("Contact_Web", "www.mywebsite1.com");
    this.Manager.SaveContent(target);
    MetaFields.ContentManager = this.Manager;
    MetaFields.Content = target;
    MetaFields.SaveContent();
    System.Threading.Thread.CurrentThread.CurrentUICulture = backupCulture;
     
    base.SaveContent();


    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. DPC David
    DPC David avatar
    26 posts
    Registered:
    28 Dec 2009
    01 Jul 2010
    Link to this post
    Hi

    i used the code and had only to set the Lanuage-Code, then saving the content works fine. The only problem which is left, if i want to add Content for the default language (en) it is saved with LCID=9. Actually that is right but after changing the lanuage to english in the backend the article is not listed because only the articles with LCID=127 for the default language are shown. As you can see in my code-example i tryed to set the current UICulture to Invariant so that the new content is saved with LCID=127 but again it was saved with LCID=9. Would be great if you can give me an hint....

                  CultureInfo backupCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
                  CultureInfo cult = new CultureInfo("");               
                  System.Threading.Thread.CurrentThread.CurrentUICulture = cult;

                  ContentManager oM1 = new ContentManager("Articles");
                  IContent target = oM1.GetStagedContent(ID);
                  target.Language = "en";
                  target.SetMetaData("Title", "English Test");
                  target.SetMetaData("CaptionTeaser", "English Teaser");
                  target.SetMetaData("DescriptionTeaser", "English Description");
                  target.Content = "English Rules";
                  oM1.SaveContent(target);

                  MetaFields.ContentManager = oM1;
                  MetaFields.Content = target;
                  MetaFields.SaveContent();
                  System.Threading.Thread.CurrentThread.CurrentUICulture = backupCulture;

    Regards David
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Jul 2010
    Link to this post
    Hello DPC David,

    When you call

    CultureInfo backupCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
    CultureInfo cult = new CultureInfo("bg");
    System.Threading.Thread.CurrentThread.CurrentUICulture = cult;

    you change the current culture (in  English language)  to a specific culture ( which you should have declared in the web.config - <localization> node) and then you are creating the item for this specific culture. After you create the item the culture is changed back to the current culture (in English language) that we have changed before proceeding with the custom code and the items is created through the base class.

    All the best,
    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. DPC David
    DPC David avatar
    26 posts
    Registered:
    28 Dec 2009
    01 Jul 2010
    Link to this post
    Hi

    and sorry maybe i have not discribed my problem clearly. I had already a look at the localization webcast and know how sitefinity handles diffrent cultures. en(english) is my default culture in the web.config file and creating new articles through the backend works fine but i noticed If i set the backend language to en and create a new article it is saved in the database with LCID=127. I guess this happens because en is the default culture.
    So if i create an article programmatically for en it is saved with LCID=9 (correct code for english) but it should be saved with LCID=127. So my articles are not listed in the articles-overview when i switch to english in the backend.
    Now is it correct that sitefinity saves content for the default culture with LCID=127? I would say yes but how can i save content programmatically for the default culture (en) with LCID=127. As i have mentioned in my earlier post i tryed to set the CurrentUiCulture to invariantculture but still the content for en is saved with LCID=9. Maybe there is a property for LCID which i can change directly, i will check this tomorrow morning?

    If i save articles for all the other cultures in the web.config file everything works fine. I hope i have explained the prob. better then before.

    Regards David
  6. DPC David
    DPC David avatar
    26 posts
    Registered:
    28 Dec 2009
    05 Jul 2010
    Link to this post
    Hi

    sorry have to get back to this thread. Im still not able to set the default content programmatically, all other language versions are fine. I found this thread and the user had a similar problem.

    http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/cultures-problem.aspx

    I have debuged now the project while saving english content via backend and noticed that the CurrentUiCulture is set to en and of course the LCID=9 but the content is saved in table sf_CmsTextContent with LCID=127. So Sitefinity must to save the content for the default language slightly diffrent ?

    Regards David
Register for webinar
6 posts, 0 answered