Sitecore: Character restriction for the names of item sent to XTM Cloud for translation
Introduction
The Sitecore CMS has a certain restriction relating to the characters used in the names of all item types that exist within it. The name of any item must match a particular character pattern, which looks like this:
^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$ |
In other words, the pattern above does not permit the use of these characters: \, /, :, *, ?, ", <, >, |, {, }. Nor does the pattern permit the use of characters that are not supported by XML format.
How does this character restriction affect the use of the XTM connector?
Naturally, the Sitecore CMS does not permit the creation of item names that contain forbidden characters. Any attempt to do so will be unsuccessful. For this reason, you cannot simply send content items to XTM Cloud with any name of your choosing.
However, this restriction does not only concern Sitecore items. It also affects the names of both projects and project templates that you use when sending content to XTM Cloud for translation, since related items are also created in the Sitecore CMS.
As far as project templates are concerned, the issue is described in a separate article: Sitecore: What determines which XTM project templates are available during content submission to XTM Cloud?.
As for projects, you need to enter a valid name in the New project name field, in the Add to queue form. The example below contains some invalid characters.
If you try to send content with a project name like this to the translation queue or straight to XTM Cloud, you will get the following error in the log trace:
Job started: XTM Creating the translation
#Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Sitecore.Exceptions.InvalidItemNameException: An item name must satisfy the pattern: ^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$ (controlled by the setting ItemNameValidation) at Sitecore.Data.Items.ItemUtil.AssertItemName(Item destinationItem, Item sourceItem, String name) at Sitecore.Data.Items.Item.Add(String name, TemplateID templateID) at Xtm.Connector.Sitecore.AddForTranslation.GetLanguageQueueFolder.CreateFolder(Item queueFolderItem, String folderName, TranslationProperties translationProperties) at Xtm.Connector.Sitecore.AddForTranslation.GetLanguageQueueFolder.GetFolder(String folderName, TranslationProperties translationProperties) at Xtm.Connector.Sitecore.AddForTranslation.TranslationQueue.AddToQueue(TranslationItem itemToTranslate, String sourceLangauge, List`1 targetLanguages, String xtmTemplate, String addedBy, String projectName, String dueDate, String baseUrl, Boolean copyFinalLayout, String xtmProjectId, Boolean ignoreTranslationInProgress) at Xtm.Connector.Sitecore.Services.ProjectService.AddToQueueAsync(ArgumentContainerForAsync argumentsContainer, Boolean ignoreTranslationInProgress) at Xtm.Connector.Sitecore.Services.ProjectService.FullSendForTranslationJobHandler(ArgumentContainerForAsync argumentsContainer, QueueBaseDto queueToSend, String contextUser) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj) at Sitecore.Jobs.JobRunner.RunMethod(JobArgs args) at (Object , Object ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) at Sitecore.Jobs.DefaultJob.DoExecute() at Sitecore.Abstractions.BaseJob.ThreadEntry(Object state)
The most important part of the log is this information:
An item name must satisfy the pattern: ^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$ (controlled by the setting ItemNameValidation)