1

C# Hello there,

I am building a Dll where all my CustomControls are located in(Buttons, a Custom MessageBox etc.). I want to use these controls in multiple Applications. The Applications are multilingual. The problem is that each application has a different way to translate the text. For example i have a custom button, the button has a property called KeywordText: that means i give him a keyword for example "First.Run" and the button translates it in "This is the first time you run this Application". In one software the text gets translated by calling Config.Translation["First.Run"];. In the other applications its handled differently.

My question is, can i create a method in my dll that is called 'TranslateText(string text)'. And then define it in each program and not in the dll itself. For example in the 1. Application i would define it public string TranslateText(string text){ return Config.Translation[text]; }

And in my CustomButton i would set the text like: this.Text=TranslateText(keyword);. The button should then call the method TranslateText() from the application the button is used in.

I hope you understand what i mean :)

1 Answers1

0

Simplest change you can do is change your method with virtual keyword

public virtual string TranslateText(string text){
   return Config.Translation[text];
}

And then in applications where translation logic is different, derive a control from your dll's control, and override the method with different logic.

Or in another approach, you can pass the function as parameter from your calling assembly to your controls dll using the delegate. If you don't know what is function callback see What is a callback?

Community
  • 1
  • 1
Mukesh Modhvadiya
  • 2,178
  • 2
  • 27
  • 32