Permalink
Browse files

Changed Localisation to Text

  • Loading branch information...
jchannon committed Dec 20, 2012
1 parent 22cae2f commit dff284061687597bb3907b68ba4755eb47fd940a
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Threading;
+using System.Web;
+
+namespace Nancy.Demo.Localisation
+{
+ public class HomeModule : NancyModule
+ {
+ public HomeModule()
+ {
+ Get["/"] = parameters =>
+ {
+ return View["Index"];
+ };
+
+ Get["/cultureview"] = parameters =>
+ {
+ return View["CultureView"];
+ };
+
+ Get["/cultureviewgerman"] = parameters =>
+ {
+ this.Context.Culture = new CultureInfo("de-DE");
+ return View["CultureView"];
+ };
+ }
+ }
+}
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>
+ </ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{396F0BCE-5B51-4B6A-931E-312880C24725}</ProjectGuid>
+ <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Nancy.Demo.Localisation</RootNamespace>
+ <AssemblyName>Nancy.Demo.Localisation</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <UseIISExpress>true</UseIISExpress>
+ <IISExpressSSLPort />
+ <IISExpressAnonymousAuthentication />
+ <IISExpressWindowsAuthentication />
+ <IISExpressUseClassicPipelineMode />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Web.DynamicData" />
+ <Reference Include="System.Web.Entity" />
+ <Reference Include="System.Web.ApplicationServices" />
+ <Reference Include="System.ComponentModel.DataAnnotations" />
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Web.Extensions" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Web" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="System.Web.Services" />
+ <Reference Include="System.EnterpriseServices" />
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="Web.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Modules\HomeModule.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="Views\Index.cshtml" />
+ <Content Include="Views\razor-layout.cshtml" />
+ <Content Include="Views\CultureView.cshtml" />
+ <Content Include="Views\CultureView-de-DE.cshtml" />
+ <None Include="Web.Debug.config">
+ <DependentUpon>Web.config</DependentUpon>
+ </None>
+ <None Include="Web.Release.config">
+ <DependentUpon>Web.config</DependentUpon>
+ </None>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Nancy.Hosting.Aspnet\Nancy.Hosting.Aspnet.csproj">
+ <Project>{15b7f794-0bb2-4b66-ad78-4a951f1209b2}</Project>
+ <Name>Nancy.Hosting.Aspnet</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Nancy.ViewEngines.Razor\Nancy.ViewEngines.Razor.csproj">
+ <Project>{2c6f51df-015c-4db6-b44c-0e5e4f25e2a9}</Project>
+ <Name>Nancy.ViewEngines.Razor</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Nancy\Nancy.csproj">
+ <Project>{34576216-0dca-4b0f-a0dc-9075e75a676f}</Project>
+ <Name>Nancy</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup />
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
+ <WebProjectProperties>
+ <UseIIS>True</UseIIS>
+ <AutoAssignPort>True</AutoAssignPort>
+ <DevelopmentServerPort>0</DevelopmentServerPort>
+ <DevelopmentServerVPath>/</DevelopmentServerVPath>
+ <IISUrl>http://localhost:61703/</IISUrl>
+ <NTLMAuthentication>False</NTLMAuthentication>
+ <UseCustomServer>False</UseCustomServer>
+ <CustomServerUrl>
+ </CustomServerUrl>
+ <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
+ </WebProjectProperties>
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,7 @@
+@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
+
+@{
+ Layout = "razor-layout.cshtml";
+}
+
+<h1>You're here based on ther German culture set in HomeModule however the HomeModule only calls return View["CultureView"]. It uses View Location Conventions therefore there must be a file called CultureView-de-DE.cshtml</h1>
@@ -0,0 +1,8 @@
+@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
+
+@{
+ Layout = "razor-layout.cshtml";
+}
+
+<h1>You're here based on your default culture</h1>
+
@@ -0,0 +1,18 @@
+@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
+@{
+ Layout = "razor-layout.cshtml";
+}
+
+<h1>The below greeting should be based on your culture:</h1>
+
+<h3>"@Text.Greeting"</h3>
+
+<p>
+ You will see:
+ <br />
+ { "en-GB", "Hello Sir" }
+ <br />
+ { "de-DE", "Guten Tag" }
+ <br />
+ { "en-US", "Howdy" }
+</p>
@@ -0,0 +1,17 @@
+@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
+<html>
+<head>
+ <title>Razor Localisation Demo</title>
+</head>
+<body>
+ <div id="container">
+ @RenderBody()
+ <br/>
+ <a href="/">Text Resource Example</a>
+ <br/>
+ <a href="/cultureview">Default Culture View Example</a>
+ <br/>
+ <a href="/cultureviewgerman">German Culture ViewExample</a>
+ </div>
+</body>
+</html>
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
+
+<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
+ <!--
+ In the example below, the "SetAttributes" transform will change the value of
+ "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
+ finds an attribute "name" that has a value of "MyDB".
+
+ <connectionStrings>
+ <add name="MyDB"
+ connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
+ xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
+ </connectionStrings>
+ -->
+ <system.web>
+ <!--
+ In the example below, the "Replace" transform will replace the entire
+ <customErrors> section of your web.config file.
+ Note that because there is only one customErrors section under the
+ <system.web> node, there is no need to use the "xdt:Locator" attribute.
+
+ <customErrors defaultRedirect="GenericError.htm"
+ mode="RemoteOnly" xdt:Transform="Replace">
+ <error statusCode="500" redirect="InternalError.htm"/>
+ </customErrors>
+ -->
+ </system.web>
+</configuration>
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
+
+<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
+ <!--
+ In the example below, the "SetAttributes" transform will change the value of
+ "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
+ finds an attribute "name" that has a value of "MyDB".
+
+ <connectionStrings>
+ <add name="MyDB"
+ connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
+ xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
+ </connectionStrings>
+ -->
+ <system.web>
+ <compilation xdt:Transform="RemoveAttributes(debug)" />
+ <!--
+ In the example below, the "Replace" transform will replace the entire
+ <customErrors> section of your web.config file.
+ Note that because there is only one customErrors section under the
+ <system.web> node, there is no need to use the "xdt:Locator" attribute.
+
+ <customErrors defaultRedirect="GenericError.htm"
+ mode="RemoteOnly" xdt:Transform="Replace">
+ <error statusCode="500" redirect="InternalError.htm"/>
+ </customErrors>
+ -->
+ </system.web>
+</configuration>
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ For more information on how to configure your ASP.NET application, please visit
+ http://go.microsoft.com/fwlink/?LinkId=169433
+ -->
+<configuration>
+ <!--
+ We can override the bootstrapper inside the config if we don't want to rely on the bootstrapper locator.
+ -->
+ <configSections>
+ <section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection" />
+ </configSections>
+
+ <razor disableAutoIncludeModelNamespace="false">
+ <assemblies>
+ <add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <add assembly="Nancy.Hosting.Aspnet" />
+ </assemblies>
+ <namespaces>
+ <add namespace="System.Xml" />
+ </namespaces>
+ </razor>
+ <system.web>
+ <compilation debug="true" targetFramework="4.0" />
+ <httpHandlers>
+ <add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
+ </httpHandlers>
+ </system.web>
+ <system.webServer>
+ <modules runAllManagedModulesForAllRequests="true" />
+ <validation validateIntegratedModeConfiguration="false" />
+ <handlers>
+ <add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
+ </handlers>
+ </system.webServer>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration>
@@ -20,13 +20,13 @@ public class RazorViewEngineFixture
private readonly IRazorConfiguration configuration;
private readonly FileSystemViewLocationProvider fileSystemViewLocationProvider;
private readonly IRootPathProvider rootPathProvider;
- private readonly ILocationlisation locationlisation;
+ private readonly ITextResource textResource;
public RazorViewEngineFixture()
{
this.configuration = A.Fake<IRazorConfiguration>();
- this.locationlisation = A.Fake<ILocationlisation>();
- this.engine = new RazorViewEngine(this.configuration, this.locationlisation);
+ this.textResource = A.Fake<ITextResource>();
+ this.engine = new RazorViewEngine(this.configuration, this.textResource);
var cache = A.Fake<IViewCache>();
A.CallTo(() => cache.GetOrAdd(A<ViewLocationResult>.Ignored, A<Func<ViewLocationResult, Func<NancyRazorViewBase>>>.Ignored))
@@ -1,56 +0,0 @@
-
-using System.Collections;
-using System.Collections.Generic;
-
-namespace Nancy.ViewEngines.Razor
-{
- using System;
- using Nancy.Culture;
- using System.Globalization;
-
- public class DefaultLocationlisation : ILocationlisation
- {
- private readonly IDictionary<string, string> dictionary;
-
- public DefaultLocationlisation()
- : this(new Dictionary<string, string>(0))
- {
- this.dictionary.Add("Greeting-en-GB", "Hello sir");
- this.dictionary.Add("Greeting-de-DE", "Guten Tag");
- this.dictionary.Add("Greeting", "Howdy");
- }
-
- public DefaultLocationlisation(IDictionary<string, string> dictionary)
- {
- this.dictionary = dictionary;
- }
-
- public string this[string key]
- {
- get
- {
- if (dictionary.ContainsKey(key + "-" + CurrentCulture))
- {
- return dictionary[key + "-" + CurrentCulture];
- }
- else
- {
- return dictionary.ContainsKey(key) ? dictionary[key] : null;
- }
- }
- set { dictionary[key] = value; }
- }
-
- public CultureInfo CurrentCulture { get; set; }
-
- public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
- {
- return dictionary.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.GetEnumerator();
- }
- }
-}
Oops, something went wrong.

0 comments on commit dff2840

Please sign in to comment.