using System;
using System.Globalization;
using Abp.Dependency;
using Abp.Localization.Sources;
namespace Abp.Localization
{
///
/// This static class is used to simplify getting localized strings.
///
public static class LocalizationHelper
{
///
/// Gets a reference to the localization manager.
/// Inject and use
/// wherever it's possible, instead of this shortcut.
///
public static ILocalizationManager Manager { get { return LocalizationManager.Value; } }
private static readonly Lazy LocalizationManager;
static LocalizationHelper()
{
LocalizationManager = new Lazy(
() => IocManager.Instance.IsRegistered()
? IocManager.Instance.Resolve()
: NullLocalizationManager.Instance
);
}
///
/// Gets a pre-registered localization source.
///
public static ILocalizationSource GetSource(string name)
{
return LocalizationManager.Value.GetSource(name);
}
///
/// Gets a localized string in current language.
///
/// Name of the localization source
/// Key name to get localized string
/// Localized string
public static string GetString(string sourceName, string name)
{
return LocalizationManager.Value.GetString(sourceName, name);
}
///
/// Gets a localized string in specified language.
///
/// Name of the localization source
/// Key name to get localized string
/// culture
/// Localized string
public static string GetString(string sourceName, string name, CultureInfo culture)
{
return LocalizationManager.Value.GetString(sourceName, name, culture);
}
}
}