Translating WinForm menu items dynamically

A

Andrus

I have database containing translations.
I'm creating VS 2005 WinForms application which should use this database to
translate menu items to user language.

I replaced lines in myform.designer.cs like

Text = "File";

to call my translating routine

Text = Translator.GetMessage("File");

Now designer cannot open my Winform anymore.
How to design such forms ?

I tried also to generate localized code but this does not allow to translate
at runtime.

Andrus.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Andrus said:
I have database containing translations.
I'm creating VS 2005 WinForms application which should use this database
to
translate menu items to user language.

I replaced lines in myform.designer.cs like

Text = "File";

to call my translating routine

Text = Translator.GetMessage("File");

Now designer cannot open my Winform anymore.
How to design such forms ?

You should do this dynamically. At runtime. When the form is opening you can
read the text and change the menu as desired.

Additionally you should take a look at the localization features provided by
the framework.
 
A

Andrus

You should do this dynamically. At runtime. When the form is opening you
can read the text and change the menu as desired.

Additionally you should take a look at the localization features provided
by the framework.

Thank you.
So I think I have two possibilities:

1. In form constructor, loop over menu and label controls in form and change
their Text properies to current UI language.
Where to find sample code for this ?

2. At application startup, check if dictionary table in database is changed.
If table is changed, generate satellite assemblies dynamically from
database.
Should I distribute resgen.exe and al.exe with my application and invoke
them from application to create new resources ?
How to force application to use same resource file in all forms ? Or should
I distribute separate resource file for every form and for every language
with my application ?
Where to find sample code to dynamic resource file generation ?

Which is better solution ?

Andrus.
 
N

Nicholas Paldino [.NET/C# MVP]

Andrus,

I am curious why you need to access the database to do this. Are the
items being changed that often that you need to do this? If anything, I
would think that the translations would be done once, and then never again
(except for new items) in which case, you would just distribute a new
satellite assembly.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Nicholas Paldino said:
Andrus,

I am curious why you need to access the database to do this. Are the
items being changed that often that you need to do this? If anything, I
would think that the translations would be done once, and then never again
(except for new items) in which case, you would just distribute a new
satellite assembly.

It might be the case that depending of the user running the app the language
change. I'm working in a project where we had such a requirement (it was
discarded at the end).
 
A

Andrus

My translations are all in database.
I must use them to translate reports (rdlc files) at runtime. Reports can be
customize by end user and every report should be automatically translated to
various languages.
So this translation remains to be done in runtime and i use database for
this.
I have most translations already done in database.

I need to push those translations to my application form controls Text and
ToolTip properties.

Using satellite assemblies requires to edit every assembly in every form
manually using resource
editor and using copy base from translation database.
This is huge work.
So I'm looking for a way to automate it.

Andrus.
I am curious why you need to access the database to do this. Are the
items being changed that often that you need to do this? If anything, I
would think that the translations would be done once, and then never again
(except for new items) in which case, you would just distribute a new
satellite assembly.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andrus said:
Thank you.
So I think I have two possibilities:

1. In form constructor, loop over menu and label controls in form and
change their Text properies to current UI language.
Where to find sample code for this ?

2. At application startup, check if dictionary table in database is
changed.
If table is changed, generate satellite assemblies dynamically from
database.
Should I distribute resgen.exe and al.exe with my application and invoke
them from application to create new resources ?
How to force application to use same resource file in all forms ? Or
should I distribute separate resource file for every form and for every
language with my application ?
Where to find sample code to dynamic resource file generation ?

Which is better solution ?

Andrus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top