0

I have a web application, which I change the language of, but I can't change the language of the dropdownlist items. Can any one help me?

Slyvain
  • 1,732
  • 3
  • 23
  • 27
haneen
  • 3
  • 4
  • It's just a guess, but your application is probably localized with Resource files and your Dropdown is probably populated via a call to a database. If you want to change the language of the dropdown items, you probably need to put in place some kind a localization system (eg. extra tables in the DB)... – Slyvain Sep 18 '15 at 15:34
  • I didn't understand can u give me an example or refrance?! – haneen Sep 18 '15 at 15:38

1 Answers1

2

Static values

I assume your dropdown values are not received from a dynamic source like a database.

In that case, Visual Studio or .NET provides this feature with localized resource files. Each language has it's own resource file, e. g. Resources.us-US.resx and Resources.de-DE.resx. You will add these resource files to you project and the application choose the correct language based on the OS language.

This is the way how you would like to provide multilanguage in your .NET application.

MSDN Article

If you localize your project, you will want to create localized versions of the project resource file. For example, strings are the most common type of resource to be localized. The localized files are not displayed in the Resource Designer, but you can create and view them in Solution Explorer.

Have a look at this article and this walkthrough, they describe how to embedded the resource files into your project.

Additional information

The implementation with localized resource files also allows you to change the language manually and ignore the underlying OS language. For example this snippet (execute before your main ui thread) set the language always to German, whenever you start your application.

CultureInfo culture = new CultureInfo("de-DE");
Application.CurrentCulture = culture;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture.Name);
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culture.Name);

Dynamic values from database

If you receive your dropdown values from a database you will need extra tables and relationships. Have a look at this approach. My example is a very simple implementation, where you could reference from each value to a corresponding translation.

+---------------+---------------------+---------------------+
| DropdownValue |   DropdownEnglish   |    DropdownGerman   |
+---------------+---------------------+---------------------+
|  Id |  Basic  | Id |     English    | Id |     German     |
+-----+---------+----+----------------+----+----------------+
|  1  |  value1 |  1 | translation_e1 |  1 | translation_g1 |
+-----+---------+----+----------------+----+----------------+
|  2  |  value2 |  2 | translation_e2 |  2 | translation_g2 |
+-----+---------+----+----------------+----+----------------+
|  3  |  value3 |  3 | translation_e2 |  3 | translation_g3 |
+-----+---------+----+----------------+----+----------------+
Community
  • 1
  • 1
Andre Hofmeister
  • 3,185
  • 11
  • 51
  • 74
  • my dropdown recived values from SQL by entity framework and the application in english language and I could change the languages of all labels,ddls,gridviewcoloums,buttons to arabic by click the button to change the language by keys and values in .resx but I can't to do that for dropdown items – haneen Sep 18 '15 at 15:50
  • @haneen Describe your question or problem more exact and provide all necessary information. There are several ways to provide multilanguage. If you receive your dropdown values from a database you will need extra tables. – Andre Hofmeister Sep 18 '15 at 15:54
  • I Almost understand you ,Are u mean I must to make new table in sql and bind it when i change the language? – haneen Sep 18 '15 at 15:59
  • @haneen Have a look at my edit **Dynamic values from database**. I added a really simple example, please go with the suggested approach, it's much better. – Andre Hofmeister Sep 18 '15 at 16:10
  • thnx alot I have a look at it... and I think it is effective way but i think i need to edit the insert and update method isn't it?! – haneen Sep 18 '15 at 16:35