Discussion:
Visual Studio - Set text of a label, pointing to a resource
(too old to reply)
lpinho
2008-06-24 16:10:24 UTC
Permalink
Hi there,

I'm building a windows application, and I want to enable localization
(I've got several user controls, forms, etc).

I'm building a resource file containing all the text and images that
can be localized.

Now, I want to set the set the text value of the labels to a string
inside the resource file in design mode.

Using code is simple:

labelX.Text = Properties.Resources.strName;

and the labels text will have the same value as the string defined as
"strName".

What I want to do, is be able to do this in design mode using Visual
Studio 2005, is this possible? Is there any sort of notation that
allows me to just set a Text property to use the resource?

Like {Properties.Resources.strName} or $Properties.Resources.strName

Thanks ahead for all the help,

L. Pinho
Garrett McGowan (MSFT)
2008-06-24 19:34:54 UTC
Permalink
Have you tried using the built-in localization support provided by
the WinForms Designer? If you set a form's 'Localizable' property
to 'True', the Designer will automatically serialize all localizable
elements to the form's RESX file.

Your code-level resource work could then be limited to runtime
error messages and the like (which can be stored in the default
project-level RESX file).

Cheers,
Garrett McGowan [MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Post by lpinho
Hi there,
I'm building a windows application, and I want to enable localization
(I've got several user controls, forms, etc).
I'm building a resource file containing all the text and images that
can be localized.
Now, I want to set the set the text value of the labels to a string
inside the resource file in design mode.
labelX.Text = Properties.Resources.strName;
and the labels text will have the same value as the string defined as
"strName".
What I want to do, is be able to do this in design mode using Visual
Studio 2005, is this possible? Is there any sort of notation that
allows me to just set a Text property to use the resource?
Like {Properties.Resources.strName} or $Properties.Resources.strName
Thanks ahead for all the help,
L. Pinho
lpinho
2008-06-26 08:31:25 UTC
Permalink
Hi Garrett,

somehow I missed that in UserControls, thanks.

On 24 Jun, 20:34, "Garrett McGowan \(MSFT\)"
Post by Garrett McGowan (MSFT)
Have you tried using the built-in localization support provided by
the WinForms Designer? If you set a form's 'Localizable' property
to 'True', the Designer will automatically serialize all localizable
elements to the form's RESX file.
Your code-level resource work could then be limited to runtime
error messages and the like (which can be stored in the default
project-level RESX file).
Cheers,
Garrett McGowan [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified athttp://www.microsoft.com/info/cpyright.htm
Post by lpinho
Hi there,
I'm building a windows application, and I want to enable localization
(I've got several user controls, forms, etc).
I'm building a resource file containing all the text and images that
can be localized.
Now, I want to set the set the text value of the labels to a string
inside the resource file in design mode.
labelX.Text = Properties.Resources.strName;
and the labels text will have the same value as the string defined as
"strName".
What I want to do, is be able to do this in design mode using Visual
Studio 2005, is this possible? Is there any sort of notation that
allows me to just set a Text property to use the resource?
Like {Properties.Resources.strName} or $Properties.Resources.strName
Thanks ahead for all the help,
L. Pinho
Ondrej Medek
2008-07-30 07:10:03 UTC
Permalink
Hi all,

the Visualk Studio built-in localization has some limitation. It is
suitable for small projects only. Becasue:

1. It is difficult for the traslator to go throuh all forms and do not
miss anything. It's better to have averything only in a few resx
files.
2. Sometimes you have some text repeated more times, like "New item",
"Delete item". It's better to have only one resource for one of them.
3. More languages you add, the slower is the compile time, if you have
many forms. (Search Google, some people have published real results
for this.)

So I would like to have exactly what "lpinho" said: a possibility to
write to designer something like {Properties.Resources.strName} or
$Properties.Resources.strName. Do you know about some plugin to VS
2005 which can do that? Or can you give me a hint how can I make it by
myself? Maybe how to hijack text box from Properties window?

It would be also usefult in a situation like setting a maximum for
NumericUpDown from a constant.

Thank you
Ondrej Medek
Post by lpinho
Hi Garrett,
 somehow I missed that in UserControls, thanks.
On 24 Jun, 20:34, "Garrett McGowan \(MSFT\)"
Post by Garrett McGowan (MSFT)
Have you tried using the built-in localization support provided by
the WinForms Designer? If you set a form's 'Localizable' property
to 'True', the Designer will automatically serialize all localizable
elements to the form's RESX file.
Your code-level resource work could then be limited to runtime
error messages and the like (which can be stored in the default
project-level RESX file).
Cheers,
Garrett McGowan [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified athttp://www.microsoft.com/info/cpyright.htm
Post by lpinho
Hi there,
I'm building a windows application, and I want to enable localization
(I've got several user controls, forms, etc).
I'm building a resource file containing all the text and images that
can be localized.
Now, I want to set the set the text value of the labels to a string
inside the resource file in design mode.
labelX.Text = Properties.Resources.strName;
and the labels text will have the same value as the string defined as
"strName".
What I want to do, is be able to do this in design mode using Visual
Studio 2005, is this possible? Is there any sort of notation that
allows me to just set a Text property to use the resource?
Like {Properties.Resources.strName} or $Properties.Resources.strName
Thanks ahead for all the help,
L. Pinho
Grant
2008-07-31 06:39:34 UTC
Permalink
Post by Ondrej Medek
Hi all,
the Visualk Studio built-in localization has some limitation. It is
1. It is difficult for the traslator to go throuh all forms and do not
miss anything. It's better to have averything only in a few resx
files.
2. Sometimes you have some text repeated more times, like "New item",
"Delete item". It's better to have only one resource for one of them.
3. More languages you add, the slower is the compile time, if you have
many forms. (Search Google, some people have published real results
for this.)
The are a number of good localization tools that will overcome the
limitations you mention above. Infralution sells a product,
Globalizer.NET (www.infralution.com/globalizer.html), that can
automatically scan your projects for localizable forms and resources
and compile all the resources into a single workspace that allows a
translator to work on one convenient file with automatic translation
of duplicate strings. Once the translator has completed their work
you can either generate localized resx files (so that you can build
them using Visual Studio and the normal process) or generate the
binary satellite assemblies directly. Unlike most other tools
Globalizer.NET also allows the translator to preview and even run the
translated application without having to use Visual Studio or have the
source code.

The single resource file approach has a number of disadvantages:

1. Translations often depend on the context. Just because the same
word is used in English in two different forms doesn't mean the same
word should be used in another Language. You can overcome this by
defining a separate resource entry in these cases, however you don't
know upfront (before localizing in every possible language) when this
may occur. So the only way to avoid code changes during the
localization phase is to define a separate resource for each form -
which brings you back to the standard .NET localization solution.

2. Strings are not the only things that need localization. The
standard .NET localization approach allows you to change the size and
layout of forms as required for specific languages. This means that
you can allow extra room as required for languages like German which
can be verbose without leaving large ugly spaces in other languages.
In addition right to left languages like Hebrew will require a
completely different layout. You can do all this in the Visual
Studio forms editor and check your layout at design time.

Regards
Grant Frisken
Infralution
www.infralution.com
Ondrej Medek
2008-07-31 11:06:50 UTC
Permalink
Post by Ondrej Medek
Hi all,
the Visualk Studio built-in localization has some limitation. It is
1. It is difficult for the traslator to go throuh all forms and do not
miss anything. It's better to have averything only in a few resx
1.  Translations often depend on the context.  Just because the same
word is used in English in two different forms doesn't mean the same
word should be used in another Language.   You can overcome this by
defining a separate resource entry in these cases, however you don't
know upfront (before localizing in every possible language) when this
may occur.   So the only way to avoid code changes during the
localization phase is to define a separate resource for each form -
which brings you back to the standard .NET localization solution.
2.  Strings are not the only things that need localization.  The
standard .NET localization approach allows you to change the size and
layout of forms as required for specific languages.   This means that
you can allow extra room as required for languages like German which
can be verbose without leaving large ugly spaces in other languages.
In addition right to left languages like Hebrew will require a
completely different layout.   You can do all this in the Visual
Studio forms editor and check your layout at design time.
Yes, I know about difficulties with translations, I am not a native
english speaker. My proposed solution is flexible enough. It does not
prevent from using VS 2005 the old way. I think it might be also
simple to implement.

Mihai N.
2008-07-31 07:02:25 UTC
Permalink
Post by Ondrej Medek
2. Sometimes you have some text repeated more times, like "New item",
"Delete item". It's better to have only one resource for one of them.
With the others you are right, but this one is risky.

The same English word is transalated in different ways depending on context.
For instance "Print" is translated onto French as "Imprimer" or "Impression",
depending if it is a commanding element (ie button) vs describing stuff
(label, title).

Same element type can also require different translations.
Examples: "Scan" can mean "scan a page of paper" or "scan the disk" and
have different translations.
"New" can be translated as "Nuovo" "Nuova" "Nuovi" "Nuove"
(masculin singular, feminin singular, masculin plural, feminin plural)

Uless you don't speak all target languages, you have no way to judge if
two elements require a different translation or not.
So you better leave that "saving" alone.
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Loading...