Preventing NRE in Text.cs

When WorkContext.Current is null
This commit is contained in:
Volodymyr Usarskyy
2013-10-06 17:05:22 +02:00
committed by Sebastien Ros
parent 4c16256245
commit 33648208f3

View File

@@ -24,12 +24,17 @@ namespace Orchard.Localization {
Logger.Debug("{0} localizing '{1}'", _scope, textHint); Logger.Debug("{0} localizing '{1}'", _scope, textHint);
var workContext = _workContextAccessor.GetContext(); var workContext = _workContextAccessor.GetContext();
var currentCulture = workContext.CurrentCulture;
var localizedFormat = _localizedStringManager.GetLocalizedString(_scope, textHint, currentCulture); if (workContext != null) {
var currentCulture = workContext.CurrentCulture;
var localizedFormat = _localizedStringManager.GetLocalizedString(_scope, textHint, currentCulture);
return args.Length == 0 return args.Length == 0
? new LocalizedString(localizedFormat, _scope, textHint, args) ? new LocalizedString(localizedFormat, _scope, textHint, args)
: new LocalizedString(string.Format(GetFormatProvider(currentCulture), localizedFormat, args), _scope, textHint, args); : new LocalizedString(string.Format(GetFormatProvider(currentCulture), localizedFormat, args), _scope, textHint, args);
}
return new LocalizedString(textHint, _scope, textHint, args);
} }
private static IFormatProvider GetFormatProvider(string currentCulture) { private static IFormatProvider GetFormatProvider(string currentCulture) {