Language resource for component

S

Sonnich Jensen

Hi all

I have a component, for which there is a Language property - it is a
chart, which holds certain labels for different charts. I have made
this component myself.

For forms etc one can activate Localization, add a language, and the
resource file is created automatically.
But how do I attach or create such a file for my MyChartComponent.cs,
which does not hold any components, it is not a form etc.

On the file I cannot add a resource - so how do I overcome this?

Sonnich

Here is a part of the example I found:

private void ChangeLanguage(string lang)
{
ComponentResourceManager resources = new
ComponentResourceManager(typeof(Form1)); // class name
//iterate through all the controls and their sub-controls
and replace their strings:
foreach (Control c in this.Controls)
{
//we only replace the Name property
resources.ApplyResources(c, c.Name, new
CultureInfo(lang));
foreach (Control d in c.Controls)
{
resources.ApplyResources(d, d.Name, new
CultureInfo(lang));
}
}
//fetch a custom string from the resource file:
label2.Text = resources.GetString("string1", new
CultureInfo(lang));
}


which works for forms.
 
S

Sonnich Jensen

I have a component, for which there is a Language property - it is a
chart, which holds certain labels for different charts. I have made
this component myself.
For forms etc one can activate Localization, add a language, and the
resource file is created automatically.
But how do I attach or create such a file for my MyChartComponent.cs,
which does not hold any components, it is not a form etc. [...]

You would have to ask the publisher of the chart object you're using.
There's no charting control in .NET per se, so obviously you're using
some third-party library.

Nope, my own creation

In general, I think you will find that you have to store your own
localized strings (which the VS Resource Designer does support), and
then update the strings at run-time accordingly (i.e. have some code to
initialize the strings for a given control, where that code always draws
the string values from a localized resource).  A Form enjoys special
support from the VS IDE that is not practical to offer for
non-Form-based objects.

That is possible, but how do I create the file (unless I alter the
csproj file manually)?
(Note that if your third-party chart control is in fact derived from
System.Windows.Forms.Control, then it ought to "play nice" with the
existing Forms Designer localization support).

That is the one
Not knowing the third-party chart control you're using, of course I have
no idea what role the "Language" property might play.  It's possible
they do have some localization support built in and you would not have
to explicitly initialize strings from a localized resource.

But you'd have to read the documentation for that control, or ask the
publisher.

Pete


Basically, create a Control based component

add a language property or something

make it draw say text1 and text2 (on paint)

now, on the language you can read the resource for the language
then update the text

Sonnich
 

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