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

I have something like this:

<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 think it is not supported.

The following that comes to my mind:

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

Can anyone suggest a better solution?


UPDATE is the solution I implemented:

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

However, here's what I did - I left the settings in the web.config (they cannot be localized, but they can be changed without having to recompile the code) and added them to (they can be localized, they will only be used in the working environment, where blank strings are set for web.config parameters).

+4
source share
4 answers

You cannot store localization data in config files.

Use satellite assemblies and resource files for localization.

If you have a small number of items, keeping things in the config may be okay, but experience shows that the number of items will increase until it becomes a maintenance nightmare.

See this guide for more information (Globalization and Localization Demystified in ASP.NET 2.0).

+5
source

If this is really just a few tweaks, your suggestion above will only work dandy. I do not think that ASP.NET has built-in support for localizing configuration settings.

+2
source

Why not create an appsettings.culture file and copy it to the application folder. Based on the application culture, you can override appconfig with the correct local application settings file.

0
source

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

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

Add this to your web configuration outside the <system.web>...</system.web> :

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

Then you can access the following settings:

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

Source: https://habr.com/ru/post/1306127/


All Articles