Question

I think I have a solution to this, but is there a better way, or is this going to break on me?

I am constructing a localized web site using global/local resx files. It is a requirement that non-technical users can edit the strings and add new languages through the web app.

This seems easy enough -- I have a form to display strings and the 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);

Is this going to cause problems on a busy site? If it causes a momentary delay for recompilation, that's no big deal. And realistically, this form won't see constant, heavy use. What does the community think?

Was it helpful?

Solution

I've used a similar method before for a very basic "CMS". The site wasn't massively used but it didn't cause me any problems.

I don't think changing a resx will cause a recycle.

OTHER TIPS

We did something similar, but used a database to store the user modified values. We then provided a fallback mechanism to serve the overridden value of a localized key.

That said, I think your method should work fine.

Have you considered creating a Resource object? You would need to wrap your settings into a single object that all the client code would use. 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 could make it a singleton or a provider, that way the object is loaded only one time. Also you could make it smart to look at the current thread to get the culture info so you know what language to return.

Then in your web.config file you can create a custom section and set restartOnExternalChanges="true". That way, your app will get the changed when they are made.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top