andrew1906
06-28-2006, 10:36 PM
I'm at a bit of a loss with customizing the ASP.NET resource locator. My goal is this - I want to have custom XML files that act as resource files for a given page. I'm using Model-View-Controller - so one view might have 10 different functions, and thus have ten separate XML resource files that provide labels for buttons, headers, etc. For instance - I might have a <B>Bulleted List</B> view that displays a list of items, but in my application, I might have to display a Grocery List, a Todo List, and a DVD list. Thus, the header and buttons on that view would have to change each time, and since I'm supporting localization, then have the take into account culture. Not to mention, for a given client, I MIGHT want to overload the text.
Given that, my goal is to take an XML file from a database and APPLY it to a view a run-time. I've tried to implement ILocalizer and did the following:
/// <summary>
/// Provides localization via XML command files
/// </summary>
public class XmlLocalizer : AbstractLocalizer
{
/// <summary>
/// The template to use for localization
/// </summary>
private XmlDocument _template;
public XmlLocalizer( XmlDocument template )
{
_template = template;
}
protected override System.Collections.IList LoadResources( object target, global::Spring.Context.IMessageSource messageSource, System.Globalization.CultureInfo culture )
{
Debug.Assert( _template != null, "No template has been defined" );
ArrayList resources = new ArrayList();
XmlElement resourceNode = (XmlElement) _template.SelectSingleNode( "//Invariant" );
foreach( XmlElement xe in resourceNode.ChildNodes )
{
Resource r = new Resource( Expression.Parse( xe.GetAttribute( "Name" ) ), xe.GetAttribute("Value" ) );
resources.Add( r );
}
return resources;
}
}
I pass it the following XML:
<Localization>
<Invariant>
<Resource Name="btnAdd.Text" Value="Add your name here"/>
</Invariant>
</Localization>
This works fine. But now, I want to internationalize it. So I want to pass it something like:
<Localization>
<Invariant>
<Resource Name="btnAdd.Text" Value="Add your name here"/>
</Invariant>
<Culture name='en'>
<Resource Name="btnAdd.Text" Value="Add your name here"/>
</Culture>
<Culture name='en-us'>
<Resource Name="btnAdd.Text" Value="Add your name here, dude"/>
</Culture>
</Localization>
... and then have my code correctly resolve to the appropriate culture. I looked through your <B>AbstractLocalizer</B> and I see that you somehow do this with a ResourceManager and ResourceSet, but I don't think those are applicable to me because I'm not using Resource files.
How do you all suggest I proceed?
Also... what is the IMessageSource in the ILocalizer for?
Given that, my goal is to take an XML file from a database and APPLY it to a view a run-time. I've tried to implement ILocalizer and did the following:
/// <summary>
/// Provides localization via XML command files
/// </summary>
public class XmlLocalizer : AbstractLocalizer
{
/// <summary>
/// The template to use for localization
/// </summary>
private XmlDocument _template;
public XmlLocalizer( XmlDocument template )
{
_template = template;
}
protected override System.Collections.IList LoadResources( object target, global::Spring.Context.IMessageSource messageSource, System.Globalization.CultureInfo culture )
{
Debug.Assert( _template != null, "No template has been defined" );
ArrayList resources = new ArrayList();
XmlElement resourceNode = (XmlElement) _template.SelectSingleNode( "//Invariant" );
foreach( XmlElement xe in resourceNode.ChildNodes )
{
Resource r = new Resource( Expression.Parse( xe.GetAttribute( "Name" ) ), xe.GetAttribute("Value" ) );
resources.Add( r );
}
return resources;
}
}
I pass it the following XML:
<Localization>
<Invariant>
<Resource Name="btnAdd.Text" Value="Add your name here"/>
</Invariant>
</Localization>
This works fine. But now, I want to internationalize it. So I want to pass it something like:
<Localization>
<Invariant>
<Resource Name="btnAdd.Text" Value="Add your name here"/>
</Invariant>
<Culture name='en'>
<Resource Name="btnAdd.Text" Value="Add your name here"/>
</Culture>
<Culture name='en-us'>
<Resource Name="btnAdd.Text" Value="Add your name here, dude"/>
</Culture>
</Localization>
... and then have my code correctly resolve to the appropriate culture. I looked through your <B>AbstractLocalizer</B> and I see that you somehow do this with a ResourceManager and ResourceSet, but I don't think those are applicable to me because I'm not using Resource files.
How do you all suggest I proceed?
Also... what is the IMessageSource in the ILocalizer for?