Reputation: 75
I am trying to allow my program to be used in different language. I have a resource file named language_en.
During runtime, I would like to change the value of each strings in language_en.
I've created .ini file that holds all the strings in language_en, as well as the controls on the form. Using that file during load, I am easily able to change the text of controls. Such as: Text of Button1 from "Yes" to "Ja".
I am not able to do the same for resource file since it is read-only. I know one way I could do is to create multiple resource file for each language. However, I'de like to be able to do it all within the .ini file.
I was trying something like this:
ResourceSet RSet = English.ResourceManager.GetResourceSet(
CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry Entry in RSet)
{
Entry.Value = ?
}
but obviously it wont work, not only because I am trying to modify a collection during iteration, but since the value is readonly.
Anyone have idea what approach I could take?
P.S. Where should I define my Application.CultureInfo? Before InitializeComponent()?
Upvotes: 2
Views: 9235
Reputation:
Correct way to do this in .NET is creating multiple resource files as follows:
Say you have resource file Resource.resx, it will serve as default English words for your UI, Now if you wish to add support for Spanish language, then just add a resource file named Resource.es.resx(this file will contains exact same keys as the original file but values will be Spanish translations) in the same directory. Whenever user change system language to Spanish .NET will automatically utilize correct resource file. Similarly you can add support for as many languages as you want just by adding resource file with correct extension.
Upvotes: 4