R
Rolf Molini
Hello board,
I just started looking into C# - programming and find it quite applicable for very rapid development scenarios. But the handy
support that the IDE provides has now run me into problems with localization.
I started out very simple with a form called MainForm that is displayed but disabled. This form immediately starts a second form
called "LoginDialog" which contains the usual labels, textBoxes and buttons. It connects to a SQL-Server database to verify login
credentials and - if appliciable - after a couple of seconds closes itself and enables MainForm. The LoginDialog contains a label
which initially contains no text but - after successful login - displays a string like "Welcome" and some user-information fetched
from the database. If the login credentials cannot be verified against the database it shall display a failure message like e.g.
"Wrong username and/or password".
So far all this worked pretty fine and could be created within very short time with the IDE. Then, I started localizing the from and
that's where I encountered a dead-end.
To localize I first used the IDE by making the LoginDialog-form localizable, switching the Language-property of the form and setting
different values to the Text-properties of the elements. I could observe how the IDE created resource-files like e.g.
"MyApp.LoginDialog.resources", "MyApp.LoginDialog.fr.resources" in the project directory, created subdirectories like "fr" and in
there the "MyApp.resources.dll" satellite-assembly. Within the InitializeComponents()-method in the LoginDialog-class the IDE uses
the ResourceManager(type)-constructor to create a Resource Manager of type "LoginDialog". All this works out well.
But now I would need some extra localized variables (e.g. for the Welcome-string or the failure-message mentioned above) which do
not appear as elements within the form. First, I tried to be clever and to add some values to the .resources-files with WinRes.exe.
But every time I touch the form in the designer-view the .resources-file is built anew and my entries are gone. Next, I tried to
build my own .resources-files with the entries for the necessary variables, compile them with Al and place the satellite-assemblies
in the correct subdirectory. But since the names of the files have to follow a strict convention I suppose that my DLLs are
overwritten by the IDE upon building the project (the IDE of course follows this convention).
The question is now: How can I add localized variables to my form which are not elements (controls or components) of the form? Of
course throughout a localized application you need more variables (mostly strings) localized than just the controls or components
within the forms.
Is it the only possibility to set the form in the designer to not localizable (which removes all resp. code from
InitializeComponents), delete the auto-generated .resources and .dll-files, then create my own .resources-files and assemblies, use
my own Resource Manager within InitializeComponent() and manually set the properties of all elements in the form? In this case it
would be very tedious to incorporate all the localized information for the controls (like button-size, -position ...) in my own
assemblies manually. The IDE does a very good job here but it will be useless if I cannot add my own localized variables.
Maybe someone has a clue on how to solve this problem.
Best regards
Rolf
I just started looking into C# - programming and find it quite applicable for very rapid development scenarios. But the handy
support that the IDE provides has now run me into problems with localization.
I started out very simple with a form called MainForm that is displayed but disabled. This form immediately starts a second form
called "LoginDialog" which contains the usual labels, textBoxes and buttons. It connects to a SQL-Server database to verify login
credentials and - if appliciable - after a couple of seconds closes itself and enables MainForm. The LoginDialog contains a label
which initially contains no text but - after successful login - displays a string like "Welcome" and some user-information fetched
from the database. If the login credentials cannot be verified against the database it shall display a failure message like e.g.
"Wrong username and/or password".
So far all this worked pretty fine and could be created within very short time with the IDE. Then, I started localizing the from and
that's where I encountered a dead-end.
To localize I first used the IDE by making the LoginDialog-form localizable, switching the Language-property of the form and setting
different values to the Text-properties of the elements. I could observe how the IDE created resource-files like e.g.
"MyApp.LoginDialog.resources", "MyApp.LoginDialog.fr.resources" in the project directory, created subdirectories like "fr" and in
there the "MyApp.resources.dll" satellite-assembly. Within the InitializeComponents()-method in the LoginDialog-class the IDE uses
the ResourceManager(type)-constructor to create a Resource Manager of type "LoginDialog". All this works out well.
But now I would need some extra localized variables (e.g. for the Welcome-string or the failure-message mentioned above) which do
not appear as elements within the form. First, I tried to be clever and to add some values to the .resources-files with WinRes.exe.
But every time I touch the form in the designer-view the .resources-file is built anew and my entries are gone. Next, I tried to
build my own .resources-files with the entries for the necessary variables, compile them with Al and place the satellite-assemblies
in the correct subdirectory. But since the names of the files have to follow a strict convention I suppose that my DLLs are
overwritten by the IDE upon building the project (the IDE of course follows this convention).
The question is now: How can I add localized variables to my form which are not elements (controls or components) of the form? Of
course throughout a localized application you need more variables (mostly strings) localized than just the controls or components
within the forms.
Is it the only possibility to set the form in the designer to not localizable (which removes all resp. code from
InitializeComponents), delete the auto-generated .resources and .dll-files, then create my own .resources-files and assemblies, use
my own Resource Manager within InitializeComponent() and manually set the properties of all elements in the form? In this case it
would be very tedious to incorporate all the localized information for the controls (like button-size, -position ...) in my own
assemblies manually. The IDE does a very good job here but it will be useless if I cannot add my own localized variables.
Maybe someone has a clue on how to solve this problem.
Best regards
Rolf