locked
Update Resx file at runtime RRS feed

  • Question

  • User-1725305 posted

    Hi all,

    I need  to create a setting configuration in my project so user can be able to update the language from my application (not directly from resx file). But the problem is, when i try to create a routine to update resx file at runtime, after that modification the application rescycled and the session is gone.

    Is it possible to update resx file at runtime without restart the session/application?

    Many thanks :)

    Friday, December 28, 2012 5:26 PM

Answers

  • User1779161005 posted

    I don't know of any, but you'd basically need to query the DB for each page request for all the translatable strings that need to be displayed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 29, 2012 7:36 PM
  • User1622957740 posted

    There are a number of ways this can be accomplished and yes you can even update resx files at runtime, although that's probably not such a good idea.

    1) Update Resx Files in App_GlobalResources, App_LocalResources

    If you use localization based on 'classic' localization using these folders for resources, it's possible to dynamically update these resx files dynamically at runtime. As others have mentioned these folders are monitored by ASP.NET and if there's a change the application is recylced which can be expensive in terms of performance, but it works.

    The real problem here is that if you make many changes there's a big performance impact on the site, but also if there's any sort of input error or XML encoding error in the .resx files ASP.NET will fail compilation and totally lock up your site.

    2) Use a custom ASP.NET Resource Provider

    ASP.NET supports creation of custom resource providers that can serve resources from alternate sources. Personally I think that if you need to modify resources dynamically at runtime a database is a better way to do this as it allows you to share the data among developers. It's also easier to update the localization data without forcing a restart of the app for every single change made.

    Some years ago I posted an article on how to create a database driven resource provider along with a sample and online editor.

    The article can be found here:
    http://www.west-wind.com/presentations/wwdbresourceprovider/ 

    A sample can be found here:
    http://west-wind.com/WestwindWebToolkit/Westwind.GlobalizationWeb/CustomerList.aspx
    (click on the little icons to jump to the resource edit form)

    Hope this helps,

    +++ Rick ---

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 7, 2013 7:41 PM

All replies

  • User1779161005 posted

    The resx is compiled into an assembly and an update to assemblies in ~/bin trigger an app domain recycle. So, in short, you don't want to do it this way.

    Can you explain in more detail what you're trying to do?

    Friday, December 28, 2012 5:41 PM
  • User-1725305 posted

    Hi,

    thanks for the answer. My goal is to implement multilingual web application and give the admin the ability to maintain the language through the portal. In order to do that, I need to be able to change resx file at the runtime, because all the language stored on the resx file. Or do you have maybe another idea in order to accomplish my goal?

    Thanks

    Saturday, December 29, 2012 4:23 AM
  • User1779161005 posted

    So you want the translation to be performed at runtime by an admin type person? Or you already have all the translations done and you just want to show the different languages?

    Saturday, December 29, 2012 9:38 AM
  • User-1725305 posted
    In my case I want the translation can be maintain later by an admin at runtime For example admin can add, edit or delete the entry for the language :)
    Saturday, December 29, 2012 10:22 AM
  • User1779161005 posted

    So in that case, I'd say that the .resx approach isn't the right approach. Keep your translated values in a database and render them dynamically. Then the admin can change them via your admin tool.

    Saturday, December 29, 2012 10:24 AM
  • User-1725305 posted

    Is there any example to create multilanguage website using database?

    Because I still don't have idea to render the translated value into webform. Thanks

    Saturday, December 29, 2012 5:54 PM
  • User1779161005 posted

    I don't know of any, but you'd basically need to query the DB for each page request for all the translatable strings that need to be displayed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 29, 2012 7:36 PM
  • User1622957740 posted

    There are a number of ways this can be accomplished and yes you can even update resx files at runtime, although that's probably not such a good idea.

    1) Update Resx Files in App_GlobalResources, App_LocalResources

    If you use localization based on 'classic' localization using these folders for resources, it's possible to dynamically update these resx files dynamically at runtime. As others have mentioned these folders are monitored by ASP.NET and if there's a change the application is recylced which can be expensive in terms of performance, but it works.

    The real problem here is that if you make many changes there's a big performance impact on the site, but also if there's any sort of input error or XML encoding error in the .resx files ASP.NET will fail compilation and totally lock up your site.

    2) Use a custom ASP.NET Resource Provider

    ASP.NET supports creation of custom resource providers that can serve resources from alternate sources. Personally I think that if you need to modify resources dynamically at runtime a database is a better way to do this as it allows you to share the data among developers. It's also easier to update the localization data without forcing a restart of the app for every single change made.

    Some years ago I posted an article on how to create a database driven resource provider along with a sample and online editor.

    The article can be found here:
    http://www.west-wind.com/presentations/wwdbresourceprovider/ 

    A sample can be found here:
    http://west-wind.com/WestwindWebToolkit/Westwind.GlobalizationWeb/CustomerList.aspx
    (click on the little icons to jump to the resource edit form)

    Hope this helps,

    +++ Rick ---

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 7, 2013 7:41 PM