Background:
I am working on a site that will be available in multiple regions. Each region can have a different language, or different spellings for the same language. We are planning on using an XML label file which will contain all the text that will be displayed for any given region.
So regionA will load RegionALabels.xml and all of its text will come from that. RegionB will load RegionBLabels.xml, and so on.
I'm thinking of implementing this by structuring the XML file so that it follows the same structure as my application. For example,
<Base> <!--BaseController-->
<Home> <!--HomeController-->
<HomePartial1>
<lblFirstName>text for label with ID lblFirstName</lblFirstName>
<lblLastName>text for label with ID lblLastName</lblLastName>
</HomePartial1>
<HomePartial2>
<!--a bunch of labels-->
</HomePartial2>
</Home>
<Accounts>
<AccountsPartial1>
<!--a bunch of labels-->
</AccountsPartial1>
<AccountsPartial2>
<!--a bunch of labels-->
</AccountsPartial2>
</Accounts>
</Base>
The reason I want to do it this way is because I want to imploy Convention over Configuration, so it becomes implicit where to find the text for any given partial view.
using this structure, I can use Linq-to-XML to select the text relevant to the partial view I'm going to Render. For example, if I'm rendering the partial view HomePartial1, I can get the labels associated with that partial view with something like:
var nodes = from f in
(from res in this.XmlConfiguration.Descendants("Base")
select res).Descendants("Home")
select f;
var HomePartial1Labels = nodes.Elements("HomePartial1").ToList();
Question:
So this being the case, basically what I want to ask is if anyone can point out any obvious holes in this approach before I attempt to implement this? Can anyone who has dealt with this before suggest something better?
also, I have one specific requriement to render a partial view with a number of tabs, each of which has to display text & a number of results associated with that tab. For example, I have 3 tabs:
Fund
Company
Group
If somebody does a search, the tabs have to display the number of results the search term returns for the tab, so if I search for 'JP Morgan' they become:
Fund (10) // 10 funds contain the name 'JP Morgan'
Company (12) // 12 companies contain the name 'JP Morgan'
Group (15) // 15 groups contain the name 'JP Morgan'
In order to contain the text "Fund", "Company" and "Group" in the label file, I'm going to have to supply the "(" and ")" also, which means I think I'll have to use a place holder and replace it with the actual value when I'm rendering the partial. So the XML will begin to look like:
<Base> <!--BaseController-->
<Home> <!--HomeController-->
<Tabs>
<lblFundTab>Funds (#value#)</lblFundTab>
<lblCompanyTab>Company (#value#)</lblCompanyTab>
<lblGroupTab>Group (#value#)</lblGroupTab>
</Tabs>
</Home>
</Base>
but I think this is going to start to look messy and a little hackish. Can somebody suggest something better? Thanks.