I am building an application that will use Nancy as a service with the Razor view engine. This application will have to be be globalized for multiple languages.

I used the demo that I found on Github https://github.com/NancyFx/Nancy/tree/master/src/Nancy.Demo.Razor.Localization as a starting point. I don't understand why a different view should be required for each language when using resource files. If I need a different view for each language then why bother with resource files and just hard code the different resource strings directly into each view?

I realise that in the HomeModule a route is required for each language but I assumed that the /cultureviewgerman route would just return the CultureView with the German text substituted where the resource string is inserted, however the /cultureviewgerman just returns the German view which kind of defeats the purpose of having resource files.

Am I missing something here?

I appreciate any help

有帮助吗?

解决方案

It tuns out what I was doing was correct. You can have one view and use resource strings for any view elements that need to be translated. You just need a route for each culture so that you can set the culture on the context. I`m developing this application on Mono and the initial issue turned out to be the resource files not being read so the default text was getting displayed regardless of culture chosen

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top