Instead of manually setting the text for controls, OSE should dynamically set the Text property of controls. For example, I could have a translation file with the following text:
buttonDoSomething: Do Something
labelSomethingElse: Something Else
The code would do something like this (in C#):
foreach (var line in File.ReadAllText(fileName))
{
string[] splitLine = line.Split(new char[] { ':' }, 2);
string controlName = splitLine[0];
string controlText = splitLine[1];
FieldInfo controlField = this.GetType().GetField(controlName);
PropertyInfo textProperty = controlField.GetType().GetProperty("Text");
textProperty.SetValue(controlField.GetValue(this), controlText, null);
}
I'm trying to implement the method you're saying like this:
langFileReader = My.Computer.FileSystem.OpenTextFileReader(My.Computer.Registry.GetValue(AppRegKey, "LanguageFile", Nothing))
While Not langFileReader.EndOfStream
Dim line As String = langFileReader.ReadLine
If Not (line = "" Or Microsoft.VisualBasic.Left(line, 1) = ("!"c)) Then
Dim splitLine As String() = line.Split(New Char() {","c}, 2)
Dim controlName As String = splitLine(0)
Dim controlText As String = LTrim(splitLine(1))
Dim controlField As FieldInfo = Me.GetType.GetField(controlName)
Dim textProperty As PropertyInfo = controlField.GetType.GetProperty("Text")
textProperty.SetValue(controlField.GetValue(Me), controlText, Nothing)
End If
End While
However, the controlFiels is returned as nothing even though the control name is correct in the Language file I'm tesing. The line is as follows:
SubtitleToolStripMenuItem, Subtitle
Replace GetField(controlName) with GetField(controlName, BindingFlags.NonPublic)
I've tried it quite a lot of ways, trying other examples (of not the same use though) from the Internet, but I can't get anything to return to controlField. It's always Nothing, no matter what way I've tried. If you have the time to play with it on your own and find a way that works, I'd be grateful.