Adds notes, obsoletes old localize methods
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
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
|
||||
{
|
||||
@@ -41,6 +45,7 @@ namespace Umbraco.Core.Services
|
||||
/// <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>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -9,8 +8,6 @@ using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Core.Services.Implement
|
||||
{
|
||||
// TODO: Convert all of this over to Niels K's localization framework one day
|
||||
|
||||
public class LocalizedTextService : ILocalizedTextService2
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
@@ -27,9 +24,9 @@ namespace Umbraco.Core.Services.Implement
|
||||
/// <param name="logger"></param>
|
||||
public LocalizedTextService(Lazy<LocalizedTextServiceFileSources> fileSources, ILogger logger)
|
||||
{
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
_logger = logger;
|
||||
if (fileSources == null) throw new ArgumentNullException("fileSources");
|
||||
if (fileSources == null) throw new ArgumentNullException(nameof(fileSources));
|
||||
_dictionarySourceLazy = new Lazy<IDictionary<CultureInfo, IDictionary<string, IDictionary<string, string>>>>(() => FileSourcesToAreaDictionarySources(fileSources.Value));
|
||||
_noAreaDictionarySourceLazy = new Lazy<IDictionary<CultureInfo, IDictionary<string, string>>>(() => FileSourcesToNoAreaDictionarySources(fileSources.Value));
|
||||
_fileSources = fileSources;
|
||||
@@ -78,9 +75,9 @@ namespace Umbraco.Core.Services.Implement
|
||||
/// <param name="logger"></param>
|
||||
public LocalizedTextService(IDictionary<CultureInfo, Lazy<XDocument>> source, ILogger logger)
|
||||
{
|
||||
if (source == null) throw new ArgumentNullException("source");
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
_logger = logger;
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
_dictionarySourceLazy = new Lazy<IDictionary<CultureInfo, IDictionary<string, IDictionary<string, string>>>>(() => XmlSourcesToAreaDictionary(source));
|
||||
_noAreaDictionarySourceLazy = new Lazy<IDictionary<CultureInfo, IDictionary<string, string>>>(() => XmlSourceToNoAreaDictionary(source));
|
||||
|
||||
@@ -150,7 +147,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
/// <returns></returns>
|
||||
public IDictionary<string, string> GetAllStoredValues(CultureInfo culture)
|
||||
{
|
||||
if (culture == null) throw new ArgumentNullException("culture");
|
||||
if (culture == null) throw new ArgumentNullException(nameof(culture));
|
||||
|
||||
// TODO: Hack, see notes on ConvertToSupportedCultureWithRegionCode
|
||||
culture = ConvertToSupportedCultureWithRegionCode(culture);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -12,6 +13,8 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
public static class LocalizedTextServiceExtensions
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
if(manager is ILocalizedTextService2 manager2)
|
||||
@@ -23,8 +26,11 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
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)
|
||||
@@ -36,8 +42,11 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
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>
|
||||
@@ -57,8 +66,11 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
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>
|
||||
@@ -78,10 +90,11 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
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>
|
||||
@@ -102,7 +115,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
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>
|
||||
@@ -125,8 +140,11 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
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>
|
||||
/// Localize using the current thread culture
|
||||
/// </summary>
|
||||
@@ -134,6 +152,7 @@ namespace Umbraco.Core.Services
|
||||
/// <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);
|
||||
@@ -146,6 +165,7 @@ namespace Umbraco.Core.Services
|
||||
/// <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);
|
||||
@@ -159,6 +179,7 @@ namespace Umbraco.Core.Services
|
||||
/// <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));
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace Umbraco.Web.Editors
|
||||
: CultureInfo.GetCultureInfo(GlobalSettings.DefaultUILanguage)
|
||||
: CultureInfo.GetCultureInfo(culture);
|
||||
|
||||
|
||||
// TODO: Remove this check in v9 when these interfaces merge
|
||||
if(Services.TextService is ILocalizedTextService2 localizedText2)
|
||||
{
|
||||
var nestedDictionary2 = localizedText2.GetAllStoredValuesByAreaAndAlias(cultureInfo);
|
||||
|
||||
@@ -101,6 +101,8 @@ namespace Umbraco.Web.Search
|
||||
string type;
|
||||
var indexName = Constants.UmbracoIndexes.InternalIndexName;
|
||||
var fields = _umbracoTreeSearcherFields.GetBackOfficeFields().ToList();
|
||||
|
||||
// TODO: Remove these checks in v9 when these interfaces merge
|
||||
ISet<string> fieldsToLoad = _umbracoTreeSearcherFields is IUmbracoTreeSearcherFields2 searcherFields2
|
||||
? new HashSet<string>(searcherFields2.GetBackOfficeFieldsToLoad())
|
||||
: null;
|
||||
|
||||
Reference in New Issue
Block a user