Update LocalizedString to also store the textHint, scopy and args

This is so that OrchardException classes which expose a LocalizedString
can be examined for the language neutral text if needed.

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-06-22 12:17:39 -07:00
parent 5db91c1689
commit 7c19d01d3e
2 changed files with 24 additions and 2 deletions

View File

@@ -4,11 +4,21 @@ using System.Web;
namespace Orchard.Localization { namespace Orchard.Localization {
public class LocalizedString : MarshalByRefObject, IHtmlString { public class LocalizedString : MarshalByRefObject, IHtmlString {
private readonly string _localized; private readonly string _localized;
private readonly string _scope;
private readonly string _textHint;
private readonly object[] _args;
public LocalizedString(string localized) { public LocalizedString(string localized) {
_localized = localized; _localized = localized;
} }
public LocalizedString(string localized, string scope, string textHint, object[] args) {
_localized = localized;
_scope = scope;
_textHint = textHint;
_args = args;
}
public static LocalizedString TextOrDefault(string text, LocalizedString defaultValue) { public static LocalizedString TextOrDefault(string text, LocalizedString defaultValue) {
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))
return defaultValue; return defaultValue;
@@ -16,6 +26,18 @@ namespace Orchard.Localization {
return new LocalizedString(text); return new LocalizedString(text);
} }
public string Scope {
get { return _scope; }
}
public string TextHint {
get { return _textHint; }
}
public object[] Args {
get { return _args; }
}
public string Text { public string Text {
get { return _localized; } get { return _localized; }
} }

View File

@@ -27,8 +27,8 @@ namespace Orchard.Localization {
var localizedFormat = _resourceManager.GetLocalizedString(_scope, textHint, currentCulture); var localizedFormat = _resourceManager.GetLocalizedString(_scope, textHint, currentCulture);
return args.Length == 0 return args.Length == 0
? new LocalizedString(localizedFormat) ? new LocalizedString(localizedFormat, _scope, textHint, args)
: new LocalizedString(string.Format(GetFormatProvider(currentCulture), localizedFormat, args.Select(Encode).ToArray())); : new LocalizedString(string.Format(GetFormatProvider(currentCulture), localizedFormat, args.Select(Encode).ToArray()), _scope, textHint, args);
} }
private static IFormatProvider GetFormatProvider(string currentCulture) { private static IFormatProvider GetFormatProvider(string currentCulture) {