Is it possible to localize the appSettings information in web.config file?

I have something like this in mind:

<appSettings>
 <add key="ConfigName" value="configuration" culture="1033" />
 <add key="ConfigName" value="konfiguracja" culture="1045" />
</appSettings>

but the add element has only 2 attributes – key and value, so I guess it’s not supported.

Next thing that comes to my mind is:

<appSettings>
 <add key="ConfigName-1033" value="configuration" />
 <add key="ConfigName-1045" value="konfiguracja" />
</appSettings>

Can anybody suggest a better solution?


UPDATE – solution I implemented:

The downside of moving this information to resource files (Oded’s answer) is the fact that it can no longer be easily modified on developers’ and testers’ machines.

However, here’s what I did – I left the settings in the web.config file (they cannot be localized, but they can be modified with no need to recompile the code) and added them to resource files (they can be localized; they are be used in production environment only, where the web.config settings are set to empty strings).

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You should not store localization data in config files.

Use satellite assemblies and resource files for localization.

If all you have is a small number of items, holding things in config could be OK, but experience suggests that the number of items will grow until this will end up being a maintenance nightmare.

See this guide (Globalization and localization demystified in ASP.NET 2.0) for more details.

Method 2

If it’s really only a few settings, your suggestion above would work just dandy. I don’t think there’s any inherent support in ASP.NET for localizing configuration settings.

Method 3

Why not have an appsettings.culture file and copy it to your application folder. Based on the culture of the application you can override the appconfig with the correct localized app settings file.

Method 4

Add this to the configSections section of your web.config:

<section name="ConfigNames" type="System.Configuration.NameValueSectionHandler" />

Add this to your web config outside of the <system.web>...</system.web> section:

<ConfigNames>
  <add key="configuration" value="1033"/>
  <add key="konfiguracja" value="1045"/>
</ConfigNames>

Then you can access you settings like this:

var configNames = (NameValueCollection)ConfigurationManager.GetSection("emailLists");
//and get at them however you like:
var culture = configNames["konfiguracja"];


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x