9

We're building a multi-language site, focusing on Experience Editor. When browsing to a page that doesn't have a version in the current language, you are given the option to add a language version:

enter image description here

This functionality doesn't appear to extend to any components in use on the page. If I add a rendering and datasource it against an existing component that doesn't have a version for the current language, it is displayed in the fallback language as read-only.

The only way I can see to add a new language version is to switch to Content Editor, find the component, and then add the new language using the versions drop-down. Is there an easier way of allowing editors to do this without leaving Experience Editor?

3 Answers 3

4

You could probably write a custom event handler for the item:versionAdded event. In the event handler you can extract the item the event was fired for and inspect for any data source items below it in the tree, adding versions to the data source items as you go.

Just be careful you don't end up in a loop, as saving an item from an event handler will cause event handlers to fire for that item, quite possibly the same event handler again, so you'll need to ensure you've got appropriate guarding on the event handler code, like checking to ensure the target item inherits from some given template.

The benefit the event handler has is that it will also work in the Content Editor. Create a new language version of an item in the Content Editor and the event handler is still fired, so you're language versions of the data sources would also be created there.

0

I just faced with the same issue and I have implemented a new webedit command and button. At the end it looks like this:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <commands>
      <command name="webedit:adddatasourcelanguage" type="MyProject.Foundation.EditorExtensions.Commands.ExperienceEditor.AddDatasourceLanguage,MyProject.Foundation.EditorExtensions"/>
    </commands>
  </sitecore>
</configuration>

Code of the command:

namespace MyProject.Foundation.EditorExtensions.Commands.ExperienceEditor
{
    using System;
    using Sitecore.Shell.Applications.WebEdit.Commands;
    using Sitecore.Shell.Framework.Commands;

    [Serializable]
    public class AddDatasourceLanguage : WebEditCommand
    {
        public override void Execute(CommandContext context)
        {
            if (context == null || context.Items == null)
            {
                return;
            }

            foreach (var item in context.Items)
            {
                if (item.Versions.Count != 0)
                {
                    continue;
                }

                item.Versions.AddVersion();
            }
        }
    }
}

Then you just need to open core database and create the following item here: /sitecore/content/Applications/WebEdit/Default Rendering Buttons/Add datasource language

enter image description here

At the end with this new button you can create new language versions in Experience Editor for datasources one by one.

-4

you should be able to add a new button on the component ribbon that allows you to add a new language version for the current context language. Can't be that hard to realize

1
  • Please elaborate your answer, with examples or related documentation.
    – Kasper
    Oct 18, 2016 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.