diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs
index 26f2f89241..0621c83a72 100644
--- a/src/Umbraco.Core/Models/UserExtensions.cs
+++ b/src/Umbraco.Core/Models/UserExtensions.cs
@@ -16,6 +16,8 @@ namespace Umbraco.Core.Models
///
public static CultureInfo GetUserCulture(this IUser user, ILocalizedTextService textService)
{
+ if (user == null) throw new ArgumentNullException("user");
+ if (textService == null) throw new ArgumentNullException("textService");
return GetUserCulture(user.Language, textService);
}
diff --git a/src/Umbraco.Core/Services/LocalizedTextService.cs b/src/Umbraco.Core/Services/LocalizedTextService.cs
index fceb8951d9..22d57928f9 100644
--- a/src/Umbraco.Core/Services/LocalizedTextService.cs
+++ b/src/Umbraco.Core/Services/LocalizedTextService.cs
@@ -134,7 +134,12 @@ namespace Umbraco.Core.Services
var keys = area.XPathSelectElements("./key");
foreach (var key in keys)
{
- result.Add(string.Format("{0}/{1}", (string) area.Attribute("alias"), (string) key.Attribute("alias")), key.Value);
+ var dictionaryKey = string.Format("{0}/{1}", (string) area.Attribute("alias"), (string) key.Attribute("alias"));
+ //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files
+ if (result.ContainsKey(dictionaryKey) == false)
+ {
+ result.Add(dictionaryKey, key.Value);
+ }
}
}
}
@@ -150,7 +155,12 @@ namespace Umbraco.Core.Services
{
foreach (var key in area.Value)
{
- result.Add(string.Format("{0}/{1}", area.Key, key.Key), key.Value);
+ var dictionaryKey = string.Format("{0}/{1}", area.Key, key.Key);
+ //i don't think it's possible to have duplicates because we're dealing with a dictionary in the first place, but we'll double check here just in case.
+ if (result.ContainsKey(dictionaryKey) == false)
+ {
+ result.Add(dictionaryKey, key.Value);
+ }
}
}
}
diff --git a/src/Umbraco.Tests/Services/LocalizedTextServiceTests.cs b/src/Umbraco.Tests/Services/LocalizedTextServiceTests.cs
index ba1ad70b8c..97ed516846 100644
--- a/src/Umbraco.Tests/Services/LocalizedTextServiceTests.cs
+++ b/src/Umbraco.Tests/Services/LocalizedTextServiceTests.cs
@@ -89,6 +89,28 @@ namespace Umbraco.Tests.Services
}
+ [Test]
+ public void Using_XDocument_Gets_All_Stored_Values_With_Duplicates()
+ {
+ var culture = CultureInfo.GetCultureInfo("en-US");
+ var txtService = new LocalizedTextService(
+ new Dictionary>
+ {
+ {
+ culture, new Lazy(() => new XDocument(
+ new XElement("language",
+ new XElement("area", new XAttribute("alias", "testArea1"),
+ new XElement("key", new XAttribute("alias", "testKey1"), "testValue1"),
+ new XElement("key", new XAttribute("alias", "testKey1"), "testValue1")))))
+ }
+ });
+
+ var result = txtService.GetAllStoredValues(culture);
+
+ Assert.AreEqual(1, result.Count());
+
+ }
+
[Test]
public void Using_Dictionary_Returns_Text_With_Area()
{