I don't exactly see why you are trying to reinvent the wheel :)
Localization framework already has got all what you need.
The first wrong thing to do, IMHO, is to handle localizations directly by comparing to a ComboBox' text property. Ideally, you should handle the
SelectedIndexChanged
event of the ComboBox to set the current UI culture:
Private Sub LangCB_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles LangCB_SelectedIndexChanged
Thread.CurrentThread.CurrentCulture = new CultureInfo(LangCB.Text)
Thread.CurrentThread.CurrentUICulture = new CultureInfo(LangCB.Text)
End Sub
And then you just call the resource from its name, you do not have to specify the culture, as the
ResourceManager
will handle that for you, observing the current culture value to determine which resource file to search for matching entry:
MsgBox(My.Resources.FirstMsg)
MsgBox(My.Resources.SecondMsg)
If a value for a given culture is not provided, the resource manager will default to the default culture (the .resx file without culture specification).
Or, there is something in your issue I'm totally missing.
[Edit] Added example of a localized resource
-
Res.resx
file (default language = english)
Resource name: InvalidValue
Resource value: Invalid value
-
Res.de.resx
file (for German culture)
Resource name: InvalidValue
Resource value: Ungültiger Wert (sorry for translation, eventually ;) )
-
Res.fr.resx
file (for french culture)
Resource name: InvalidValue
Resource value: Valeur invalide
- etc.
You can see that:
- Every localization file is named with the default culture file name plus the culture identifier
- In each localization file, resource names must be the same
Please let me know if it is still unclear.
[Edit]