Custom Content - MVC and Resources Files
I am starting a brand new site that uses Forms Authentication. Each user
is a member of a Company. Each company has a different stylesheet applied
to the site, therefore giving a different appearance. I do this by way of
applying a custom class in the HTML tag at authentication. Then, CSS files
simply look for .customer #logonname to style elements.
I am using resources files to handle localisation because customers may
speak different languages. This is working and I have this under control.
I have each resources file using a custom namespace and this is working
quite well in my razor view.
The issue is that different customers want different content to appear.
For example, customer 1 wants the logon field label to say "Username",
whereas customer 2 wants the same label to say "Logon ID".
I was wondering if resources files would be a good way to do this. I could
create separate resources files for each customer (and language), assign a
custom namespace to each resources file and then reference that namespace
in the view to get the appropriate content. For example, I have two
resources files called Customer1.index.resx and Customer2.index.resx.
These files hold English translations for each customer.
Customer1.index.resx is using a namespace of Customer1.Translation and
Customer2.index.resx is using a namespace of Customer2.Translation.
There might be a label in the index view called lblLogon.
Customer1.index.lblLogon has a value of "UserName", whereas
Customer2.index.lblLogon has a value of "Logon ID". When I use either of
these references, the data is coming through fine - eg
<div>@Customer1.index.lblLogon</div> outputs - <div>UserName</div>
<div>@Customer2.index.lblLogon</div> outputs - <div>Logon ID</div>
Is there a way that I can create a "global" namespace at authentication
(called Translation) and map that namespace to either
Customer1.Translation or Customer2.Translation based on the user's company
membership (data returned from the authentication mechanism). Then, my
view can just say the following to generate different HTML based on the
company.
<div>@Translation.index.lblLogon</div>
Your help would be much appreciated.
Thanks Steven Woolston
w: http://www.stevenwoolston.com
No comments:
Post a Comment