Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed culture property on ITextResource

  • Loading branch information...
commit b3333f3548c1034a33efd70c3afc00fc726017f1 1 parent 2e81980
@jchannon jchannon authored
View
8 src/Nancy.ViewEngines.Razor/DefaultTextResource.cs
@@ -6,6 +6,7 @@ namespace Nancy.ViewEngines.Razor
public class DefaultTextResource : ITextResource
{
+ private readonly IRenderContext renderContext;
private readonly IDictionary<string, IDictionary<string, string>> dictionary;
public DefaultTextResource()
@@ -24,7 +25,7 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}
- public string this[string key]
+ public string this[string key, string culture]
{
get
{
@@ -34,12 +35,11 @@ IEnumerator IEnumerable.GetEnumerator()
}
- return dictionary[key].ContainsKey(CurrentCulture.Name) ? dictionary[key][CurrentCulture.Name] : null;
+ return dictionary[key].ContainsKey(culture) ? dictionary[key][culture] : null;
}
- set { dictionary[key][CurrentCulture.Name] = value; }
+ set { dictionary[key][culture] = value; }
}
- public CultureInfo CurrentCulture { get; set; }
}
}
View
3  src/Nancy.ViewEngines.Razor/ITextResource.cs
@@ -6,7 +6,6 @@ namespace Nancy.ViewEngines.Razor
public interface ITextResource : IEnumerable<KeyValuePair<string, IDictionary<string, string>>>
{
- string this[string key] { get; set; }
- CultureInfo CurrentCulture { get; set; }
+ string this[string key, string culture] { get; set; }
}
}
View
1  src/Nancy.ViewEngines.Razor/Nancy.ViewEngines.Razor.csproj
@@ -117,6 +117,7 @@
<Compile Include="ITextResource.cs" />
<Compile Include="IRazorConfiguration.cs" />
<Compile Include="IRazorViewRenderer.cs" />
+ <Compile Include="ITextResourceFinder.cs" />
<Compile Include="ModelFinder.cs" />
<Compile Include="ModelSpan.cs" />
<Compile Include="CSharp\NancyCSharpRazorCodeGenerator.cs" />
View
3  src/Nancy.ViewEngines.Razor/RazorViewEngine.cs
@@ -347,8 +347,7 @@ private NancyRazorViewBase GetOrCompileView(ViewLocationResult viewLocationResul
var view = viewFactory.Invoke();
- this.textResource.CurrentCulture = renderContext.Context.Culture;
- view.Text = new TextResourceFinder(this.textResource);
+ view.Text = new TextResourceFinder(this.textResource, renderContext.Context.Culture.Name);
view.Code = string.Empty;
View
8 src/Nancy.ViewEngines.Razor/TextResourceFinder.cs
@@ -8,18 +8,20 @@
namespace Nancy.ViewEngines.Razor
{
- public class TextResourceFinder: DynamicObject
+ public class TextResourceFinder : DynamicObject, ITextResourceFinder
{
private readonly ITextResource textResource;
+ private readonly string culture;
- public TextResourceFinder(ITextResource textResource)
+ public TextResourceFinder(ITextResource textResource, string culture)
{
this.textResource = textResource;
+ this.culture = culture;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
- result = this.textResource[binder.Name];
+ result = this.textResource[binder.Name, this.culture];
return true;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.