Search code examples
asp.net-mvcmultilingualcurrentculture

how to prefix a culture string such as "en-gb" before the {controller} position in the url in asp.net mvc?


so basically I want to achieve a multi-lingual website with the following scenarios:

  • Using ASP.NET MVC 3
  • most language are using resource files so they are using same views, however there are also many views that are country-specific (i.e. language culture specific) and not available for all.
  • example url: http://localhost/en-us/{area}/{controller}/{action}/{id}

The MVC folder structure as here:

- Areas
    - Channel1
        - Controllers
        - Content
        - Views
            - en-us
                - View1.cshtml
                - View2.cshtml
            - zh-cn
                - View1.cshtml
                - View2.cshtml
                <b>- Special.cshtml</b>

    - Channel2
       ....(similar folder structure)
- ....

I think there must be a way to define the "en-us" into a parameter like {lang} and make decision in a default Controller outside the Areas - however I'm asp.net MVC newbie, how can I do that?


Solution

  • You can always write your own viewengine to look at folders based on what comes in. There's code out there for a ThemedViewengine that does just that.