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?

+1


source to share


3 answers


I've used a similar method before for a very simple "CMS". The site was not massively used, but it did not give me any problems.



I don't think changing resx will cause rework.

+3


source


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



However, I think your method should work fine.

+1


source


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.

0


source







All Articles