More in this section

Forums / Developing with Sitefinity / Multingual HTML CONTENT

Multingual HTML CONTENT

5 posts, 0 answered
  1. rolls rolls
    rolls rolls avatar
    24 posts
    Registered:
    02 Nov 2002
    13 Nov 2007
    Link to this post
    Hi
    Please can someone tell me which table holds the multilingual content from Generic Content Module. I would like to be able to Loop through all the content and for each language translate the (en) then iether update or insert a record into this table.

    Thanks for your help

    Regards
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    14 Nov 2007
    Link to this post
    Hello Royce,

    There are several tables used for the Generic Content:
        sf_CmsContentBase
        sf_CmsContentMetaData
        sf_CmsTextContent
    If you are using versioning (this the default setting), the staged content is stored in:
        sf_VersionItem
        sf_VrsTxtData

    But, its not so simple since the data is not concentrated in only one table. Therefore, I suggest you use Sitefinity API to update content. Here is an example how can you iterate through all Generic Content items' language versions and update their contents:
    using Telerik.Cms.Engine;  
     
    ...  
            ContentManager manager = new ContentManager();  
     
            IList list = manager.GetContent();  
            foreach (IContent content in list)  
            {  
                // If you are going to edit this content item,   
                // you shoud get it again by ContentManager.GetContent(Guild id) method  
                // so it will be added to the transaction.  
                // This operation has no affect to performance  
                IContent editableContent = manager.GetContent(content.ID);  
     
                foreach (string lang in editableContent.Languages)  
                {  
                    editableContent.Language = lang;  
                    editableContent.Content = "Place new content here";  
                }  
     
                foreach (IMetaInfo info in manager.MetaKeys.Values)  
                {  
                    object obj = editableContent.GetMetaData(info.Key);  
                    if (obj != null)  
                    {  
                        // do something with MetaData field  
                    }  
                }  
     
                editableContent.Status = ContentStatus.Published;  
                manager.SaveContent(editableContent);  
            }  
    ... 

    Please let us know if you need further assistance.

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. rolls rolls
    rolls rolls avatar
    24 posts
    Registered:
    02 Nov 2002
    14 Nov 2007
    Link to this post
    Hello Vlad

    Thanks for the reply:

    Okay I would like 2 Utilities :


    1) to  Translate /Retranslate all English generic content to ALL instances of languages in the system

    2)On every Edit Generic Content screen, could i have a POPUP Form in the RADEditor WHich captures the ID of the Content and then retranslates for all languages for that content only.

    Is this possible?

    Many Thanks for the tip on translating all......that is right on the button.

    Regards ROLLS
  4. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    15 Nov 2007
    Link to this post
    Hi ROLLS,

    This scenario can be implemented with Sitefinity, but it requires the use some of the development features which are not tested and documented yet. Therefore, we are providing a code example bellow. While creating this example, we came across some issues, which will be fixed for the Service Pack 2 next week.

    1) Translate / Retranslate all English generic content to ALL instances of languages in the system:
        One of the solutions is to create a tool (a class which implements Telerik.ITool interface) in the App_Code, e.g. GCTranslator.cs:    
    using System;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Globalization;  
    using System.Collections;  
    using Telerik;  
    using Telerik.Localization;  
    using Telerik.Cms.Web.UI;  
    using Telerik.Cms.Engine;  
    using Telerik.Web;  
     
    public class GCTranslator : ITool  
    {  
        public GCTranslator()  
        {  
        }

        #region ITool Members  
     
        public Control CreateControlPanel(TemplateControl parent)  
        {  
            return new TranslatorPanel(this"Translator");  
        }  
     
        public string Description  
        {  
            get { return "A tool for translatig Generic Content items"; }  
        }  
     
        public string Name  
        {  
            get { return "Translator"; }  
        }  
     
        public string Title  
        {  
            get { return "Content Translator"; }  
        }

        #endregion  
     
        public void Translate()  
        {  
            IList list = this.Manager.GetContent();  
            foreach (IContent content in list)  
            {  
                content.Language = LocalizationManager.DefaultCulture.Name;  
                this.Translate(content);  
            }     
        }  
     
        public void Translate(IContent content)  
        {  
            IContent source = (IContent)content;  
              
            if (String.IsNullOrEmpty(source.Language))  
                source.Language = LocalizationManager.DefaultCulture.Name;  
     
            foreach (CultureInfo culture in LocalizationManager.Cultures)  
            {  
                if (culture.Name == source.Language)  
                    continue;  
     
                IContent editableContent = this.Manager.GetStagedContent(source.ID);  
     
                // set updated content item language  
                editableContent.Language = culture.Name;  
     
                // Translate content  
                editableContent.Content = String.Format("Translate '{0}' from {1} content {2}", source.Content, source.Language, culture.Name); ;  
     
                foreach (IMetaInfo info in this.Manager.MetaKeys.Values)  
                {  
                    if (!info.Localizable)  
                        continue;  
     
                    object obj = source.GetMetaData(info.Key);  
                    if (obj != null && obj is string)  
                    {  
                        // Translate Meta Data  
                        editableContent.SetMetaData(info.Key, ((string)obj) + "-" + culture.Name);  
                    }  
                }  
     
                // Store the current culture for later restore  
                // and change it with the updating language version culture.  
                // Remove next 2 lines after upgrading with Sitefinity 3.1 SP2  
                CultureInfo restoreCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;  
                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;  
                  
                // Actual save content  
                this.Manager.SaveContent(editableContent);  
     
              
                // Restore the original current culture.  
                // Remove next line after upgrading with Sitefinity 3.1 SP2  
                System.Threading.Thread.CurrentThread.CurrentUICulture = restoreCulture;  
            }  
        }  
     
        protected ContentManager Manager  
        {  
            get 
            {  
                if (this.manager == null)  
                    this.manager = new ContentManager();  
                return this.manager;  
            }  
        }  
     
        private ContentManager manager;  
    }  
     
    public class TranslatorPanel : ControlPanelBase  
    {  
        public TranslatorPanel(GCTranslator translator, string title)  
            : base(title)  
        {  
            this.translator = translator;  
        }  
     
        protected override HtmlTextWriterTag TagKey  
        {  
            get 
            {  
                return HtmlTextWriterTag.Div;  
            }  
        }  
     
        protected override void CreateChildControls()  
        {  
            this.Controls.Clear();  
     
            // message control  
            this.msgControl = new MessageControl();  
            this.Controls.Add(this.msgControl);  
     
            Button btnTranslate = new Button();  
            btnTranslate.Text = "Retranslate all Generic Content items";  
            btnTranslate.Command += new CommandEventHandler(btnTranslate_Command);  
            this.Controls.Add(btnTranslate);  
     
        }  
     
        void btnTranslate_Command(object sender, CommandEventArgs e)  
        {  
            try 
            {  
                translator.Translate();  
                this.msgControl.Message = "All Generic Content items have been successfully retranslated";  
                this.msgControl.Mode = MessageMode.Success;  
            }  
            catch (Exception err)  
            {  
                this.msgControl.Message = String.Format("Error translating Generic COntent items", err.Message);  
                this.msgControl.Mode = MessageMode.Error;  
            }  
        }  
     
        private GCTranslator translator;  
        private MessageControl msgControl;  
    }  
     
     

    The CGTranslator.cs file also contains a class TranslatorPanel, which is the user interface control for running the tool. The tool will appear under Administration -> Tools tab in the Sitefinity Admin.


    2) On every Edit Generic Content screen, could i have a POPUP Form in the RADEditor WHich captures the ID of the Content and then retranslates for all languages for that content only.
        I am not sure that the solution is exactly what you want, but you can give it a try.
       Most of the ManagerBase<ProviderBase> objects like ContentManager, CmsManager, etc. provide action events. These events are Executing and Executed. Such events are thrown when a  generic content items is created/updated into the database. In this case our application needs to attach a handler to the ContentManager.Executed event. Since these events are static, they should be handled by application within a static object. One of the approaches is to create a service (a class which implements Telerik.Framework.IService interface) in the App_Code, e.g. GlobalService.cs:
    using System;  
    using Telerik.Framework;  
    using Telerik.Cms.Engine;  
    using Telerik.Localization;  
     
    public class GlobalService : IService  
    {  
        public GlobalService()  
        {  
        }

        #region IService Members  
     
        public void Initialize()  
        {  
            // Attached to the ContentManager action executed event  
            ContentManager.Executed += new EventHandler<Telerik.ExecutedEventArgs>(ContentManager_Executed);  
        }  
     
        private void ContentManager_Executed(object sender, Telerik.ExecutedEventArgs e)  
        {  
            // The commented code does not work in the current version. It will be fixed for Sitefinity 3.1 SP2.  
            if ( (/*e.CommandName == "CreateContent" ||*/ e.CommandName == "UpdateContent")   
                 && (e.Data is IContent)  
                 && (String.IsNullOrEmpty(((IContent)e.Data).Language) || ((IContent)e.Data).Language.Equals(LocalizationManager.DefaultCulture.Name)))  
            {  
                GCTranslator translator = new GCTranslator();  
                translator.Translate((IContent)e.Data);  
            }  
        }

        #endregion  
    }  
     

    Also, the service should be registered in the web.config (this action will not be required in v3.1 SP2):
    <telerik> 
        <framework> 
            <services> 
                <add type="GlobalService, app_code"/>  
     


    The full code is in the attached archive. You just need to unzip it, copy all files into your web site and register the service in the web.config.
    Do let us know if you need any further assistance.

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. rolls rolls
    rolls rolls avatar
    24 posts
    Registered:
    02 Nov 2002
    15 Nov 2007
    Link to this post
    Seriously Vlad I love you

    ThanksR
Register for webinar
5 posts, 0 answered