diff --git a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs index 6b13358fe9..d55eeb3727 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs @@ -1076,8 +1076,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging private IReadOnlyList ImportDictionaryItems(IEnumerable dictionaryItemElementList, List languages, Guid? parentId, int userId) { var items = new List(); - foreach (var dictionaryItemElement in dictionaryItemElementList) + foreach (XElement dictionaryItemElement in dictionaryItemElementList) + { items.AddRange(ImportDictionaryItem(dictionaryItemElement, languages, parentId, userId)); + } return items; } @@ -1086,12 +1088,22 @@ namespace Umbraco.Cms.Infrastructure.Packaging { var items = new List(); + // TODO: Key is not good enough, that is the string key, we need to use GUID + IDictionaryItem dictionaryItem; - var key = dictionaryItemElement.Attribute("Key").Value; - if (_localizationService.DictionaryItemExists(key)) - dictionaryItem = GetAndUpdateDictionaryItem(key, dictionaryItemElement, languages); + var itemName = dictionaryItemElement.Attribute("Key").Value; + var itemId = Guid.Parse(dictionaryItemElement.Attribute("Id").Value); + + dictionaryItem = _localizationService.GetDictionaryItemById(itemId); + if (dictionaryItem != null) + { + dictionaryItem = UpdateDictionaryItem(dictionaryItem, dictionaryItemElement, languages); + } else - dictionaryItem = CreateNewDictionaryItem(key, dictionaryItemElement, languages, parentId); + { + dictionaryItem = CreateNewDictionaryItem(itemName, dictionaryItemElement, languages, parentId); + } + _localizationService.Save(dictionaryItem, userId); items.Add(dictionaryItem); @@ -1099,12 +1111,14 @@ namespace Umbraco.Cms.Infrastructure.Packaging return items; } - private IDictionaryItem GetAndUpdateDictionaryItem(string key, XElement dictionaryItemElement, List languages) + private IDictionaryItem UpdateDictionaryItem(IDictionaryItem dictionaryItem, XElement dictionaryItemElement, List languages) { - var dictionaryItem = _localizationService.GetDictionaryItemByKey(key); var translations = dictionaryItem.Translations.ToList(); foreach (var valueElement in dictionaryItemElement.Elements("Value").Where(v => DictionaryValueIsNew(translations, v))) + { AddDictionaryTranslation(translations, valueElement, languages); + } + dictionaryItem.Translations = translations; return dictionaryItem; } diff --git a/src/Umbraco.Infrastructure/Services/Implement/EntityXmlSerializer.cs b/src/Umbraco.Infrastructure/Services/Implement/EntityXmlSerializer.cs index 859a2b6327..a1d3d42db4 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/EntityXmlSerializer.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/EntityXmlSerializer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -242,8 +242,11 @@ namespace Umbraco.Cms.Core.Services.Implement private XElement Serialize(IDictionaryItem dictionaryItem) { - var xml = new XElement("DictionaryItem", new XAttribute("Key", dictionaryItem.ItemKey)); - foreach (var translation in dictionaryItem.Translations) + var xml = new XElement("DictionaryItem", + new XAttribute("Id", dictionaryItem.Key), + new XAttribute("Key", dictionaryItem.ItemKey)); + + foreach (IDictionaryTranslation translation in dictionaryItem.Translations) { xml.Add(new XElement("Value", new XAttribute("LanguageId", translation.Language.Id),