ASP.NET Localized Website - Update on the Go
I think I have a solution to this, but is there a better way, or will this break on me?
I am creating a localized website using global / local resx files. This is a requirement for non-technical users to be able to edit strings and add new languages ββthrough the web application.
This seems simple enough - I have a form to display strings, and changes are saved with code like this snippet:
string filename = MapPath("App_GlobalResources/strings.hu.resx");
XmlDocument xDoc = new XmlDocument();
XmlNode xNode;
xDoc.Load(filename);
xNode = xDoc.SelectSingleNode("//root/data[@name='PageTitle']/value");
xNode.InnerText = txtNewTitle.Text;
xDoc.Save(filename);
Will this cause problems on the loaded site? If it causes an instant delay for recompilation, it doesn't really matter. And realistically, this form won't see constant, heavy use. What does the community think?
source to share
Have you considered creating a Resource object? You will need to wrap your settings in a single object that will use all the client code. Something like:
public class GuiResources
{
public string PageTitle
{
get return _pageTitle;
}
// Fired once when the class is first created.
void LoadConfiguration()
{
// Load settings from config section
_pageTitle = // Value from config
}
}
You can make it a single or a provider, so the object is only loaded once. Also you can make it smart to look at the current stream to get information about the culture so you know which language to return in.
Then in your web.config file you can create a custom section and install restartOnExternalChanges="true"
. This way, your application will receive the changes when they are done.