Skip to content

Commit

Permalink
Merge branch 'nzdev-v8/bugfix/localizedtextservice-memory' into v8/co…
Browse files Browse the repository at this point in the history
…ntrib
  • Loading branch information
Shazwazza committed Jun 23, 2021
2 parents ae379cb + 30d5712 commit d9f92ec
Show file tree
Hide file tree
Showing 61 changed files with 1,216 additions and 416 deletions.
5 changes: 3 additions & 2 deletions src/Umbraco.Core/Compose/RelateOnTrashComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private static void ContentService_Trashed(IContentService sender, MoveEventArgs
item.Entity.Id,
ObjectTypes.GetName(UmbracoObjectTypes.Document),
string.Format(textService.Localize(
"recycleBin/contentTrashed"),
"recycleBin","contentTrashed"),

item.Entity.Id, originalParentId));
}
}
Expand Down Expand Up @@ -132,7 +133,7 @@ private static void MediaService_Trashed(IMediaService sender, MoveEventArgs<IMe
item.Entity.Id,
ObjectTypes.GetName(UmbracoObjectTypes.Media),
string.Format(textService.Localize(
"recycleBin/mediaTrashed"),
"recycleBin", "mediaTrashed"),
item.Entity.Id, originalParentId));
}
}
Expand Down
28 changes: 27 additions & 1 deletion src/Umbraco.Core/Services/ILocalizedTextService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;

namespace Umbraco.Core.Services
{
// TODO: This needs to be merged into one interface in v9, but better yet
// the Localize method should just the based on area + alias and we should remove
// the one with the 'key' (the concatenated area/alias) to ensure that we never use that again.

public interface ILocalizedTextService2 : ILocalizedTextService
{
/// <summary>
/// Localize a key with variables
/// </summary>
/// <param name="area"></param>
/// <param name="alias"></param>
/// <param name="culture"></param>
/// <param name="tokens">This can be null</param>
/// <returns></returns>
string Localize(string area, string alias, CultureInfo culture, IDictionary<string, string> tokens = null);


/// <summary>
/// Returns all key/values in storage for the given culture
/// </summary>
/// <returns></returns>
IDictionary<string, IDictionary<string, string>> GetAllStoredValuesByAreaAndAlias(CultureInfo culture);
}

/// <summary>
/// The entry point to localize any key in the text storage source for a given culture
/// </summary>
Expand All @@ -20,6 +45,7 @@ public interface ILocalizedTextService
/// <param name="culture"></param>
/// <param name="tokens">This can be null</param>
/// <returns></returns>
[Obsolete("Use LocalizedTextServiceExtensions.Localize or ILocalizedTextService2.Localize instead")]
string Localize(string key, CultureInfo culture, IDictionary<string, string> tokens = null);

/// <summary>
Expand Down
341 changes: 210 additions & 131 deletions src/Umbraco.Core/Services/Implement/LocalizedTextService.cs

Large diffs are not rendered by default.

136 changes: 133 additions & 3 deletions src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
Expand All @@ -12,10 +13,136 @@ namespace Umbraco.Core.Services
/// </summary>
public static class LocalizedTextServiceExtensions
{
public static string Localize(this ILocalizedTextService manager, string area, string key)
// TODO: Remove these extension methods checking for ILocalizedTextService2 in v9 when these interfaces merge

public static string Localize(this ILocalizedTextService manager, string area, string alias, CultureInfo culture)
{
var fullKey = string.Join("/", area, key);
if(manager is ILocalizedTextService2 manager2)
{
return manager2.Localize(area, alias, culture);
}
var fullKey = alias;
if (area != null)
{
fullKey = string.Concat(area, "/", alias);
}
#pragma warning disable CS0618 // Type or member is obsolete
return manager.Localize(fullKey, culture);
#pragma warning restore CS0618 // Type or member is obsolete
}

public static string Localize(this ILocalizedTextService manager, string area, string alias)
{
if (manager is ILocalizedTextService2 manager2)
{
return manager2.Localize(area, alias, Thread.CurrentThread.CurrentUICulture);
}
var fullKey = alias;
if (area != null)
{
fullKey = string.Concat(area, "/", alias);
}
#pragma warning disable CS0618 // Type or member is obsolete
return manager.Localize(fullKey, Thread.CurrentThread.CurrentUICulture);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
/// Localize using the current thread culture
/// </summary>
/// <param name="manager"></param>
/// <param name="area"></param>
/// <param name="alias"></param>
/// <param name="tokens"></param>
/// <returns></returns>
public static string Localize(this ILocalizedTextService manager, string area, string alias, string[] tokens)
{
if (manager is ILocalizedTextService2 manager2)
{
return manager2.Localize(area, alias, Thread.CurrentThread.CurrentUICulture, ConvertToDictionaryVars(tokens));
}
var fullKey = alias;
if (area != null)
{
fullKey = string.Concat(area, "/", alias);
}
#pragma warning disable CS0618 // Type or member is obsolete
return manager.Localize(fullKey, Thread.CurrentThread.CurrentUICulture, tokens);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
/// Localize using the current thread culture
/// </summary>
/// <param name="manager"></param>
/// <param name="area"></param>
/// <param name="alias"></param>
/// <param name="tokens"></param>
/// <returns></returns>
public static string Localize(this ILocalizedTextService manager, string area, string alias, IDictionary<string, string> tokens = null)
{
if (manager is ILocalizedTextService2 manager2)
{
return manager2.Localize(area, alias, Thread.CurrentThread.CurrentUICulture, tokens);
}
var fullKey = alias;
if (area != null)
{
fullKey = string.Concat(area, "/", alias);
}
#pragma warning disable CS0618 // Type or member is obsolete
return manager.Localize(fullKey, Thread.CurrentThread.CurrentUICulture, tokens);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
/// Localize a key without any variables
/// </summary>
/// <param name="manager"></param>
/// <param name="area"></param>
/// <param name="alias"></param>
/// <param name="culture"></param>
/// <param name="tokens"></param>
/// <returns></returns>
public static string Localize(this ILocalizedTextService manager, string area, string alias, CultureInfo culture, string[] tokens)
{
if (manager is ILocalizedTextService2 manager2)
{
return manager2.Localize(area, alias, Thread.CurrentThread.CurrentUICulture, tokens);
}
var fullKey = alias;
if (area != null)
{
fullKey = string.Concat(area, "/", alias);
}
#pragma warning disable CS0618 // Type or member is obsolete
return manager.Localize(fullKey, culture, ConvertToDictionaryVars(tokens));
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
/// Localize a key without any variables
/// </summary>
/// <param name="manager"></param>
/// <param name="area"></param>
/// <param name="alias"></param>
/// <param name="culture"></param>
/// <param name="tokens"></param>
/// <returns></returns>
public static string Localize(this ILocalizedTextService manager, string area, string alias, CultureInfo culture, IDictionary<string, string> tokens)
{
if (manager is ILocalizedTextService2 manager2)
{
return manager2.Localize(area, alias, culture, tokens);
}
var fullKey = alias;
if (area != null)
{
fullKey = string.Concat(area, "/", alias);
}
#pragma warning disable CS0618 // Type or member is obsolete
return manager.Localize(fullKey, culture, tokens);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
Expand All @@ -25,6 +152,7 @@ public static string Localize(this ILocalizedTextService manager, string area, s
/// <param name="key"></param>
/// <param name="tokens"></param>
/// <returns></returns>
[Obsolete("Use the overload specifying an area and alias instead of key")]
public static string Localize(this ILocalizedTextService manager, string key, string[] tokens)
{
return manager.Localize(key, Thread.CurrentThread.CurrentUICulture, tokens);
Expand All @@ -37,6 +165,7 @@ public static string Localize(this ILocalizedTextService manager, string key, st
/// <param name="key"></param>
/// <param name="tokens"></param>
/// <returns></returns>
[Obsolete("Use the overload specifying an area and alias instead of key")]
public static string Localize(this ILocalizedTextService manager, string key, IDictionary<string, string> tokens = null)
{
return manager.Localize(key, Thread.CurrentThread.CurrentUICulture, tokens);
Expand All @@ -50,6 +179,7 @@ public static string Localize(this ILocalizedTextService manager, string key, ID
/// <param name="culture"></param>
/// <param name="tokens"></param>
/// <returns></returns>
[Obsolete("Use the overload specifying an area and alias instead of key")]
public static string Localize(this ILocalizedTextService manager, string key, CultureInfo culture, string[] tokens)
{
return manager.Localize(key, culture, ConvertToDictionaryVars(tokens));
Expand Down
Loading

0 comments on commit d9f92ec

Please sign in to comment.