View previous topic :: View next topic |
Author |
Message |
hofingerandi
Joined: 29 Nov 2010 Posts: 19
|
Posted: Mon Mar 14, 2011 10:17 am Post subject: Overriding resources in shared library |
|
|
I have a library for "common dialogs" which I need to localize. The problem is, depending on the caller, the localization should be different.
How is this ideally done? Is there even a way, that shows the modified dialog to the translator?
To give some additional info, consider two (Winforms) projects Utils and Common. Utils.dll performs certain actions and displays dialogs from Common.dll. Now Utils.dll can be called from either Client1.exe or Client2.exe. Depending on the calller, the dialogs from Common should look slightly different (e.g. different icon, different title bar). Unfortunately, it is not an option to generate the modified dialog in Client1 and pass it through Utils, since too many layers/classes would be involved. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Mar 14, 2011 9:40 pm Post subject: |
|
|
At first reading I though you meant system common dialogs (like FileOpen, FileSave etc). These are normally localized by getting the title, file filter and other configurable text resources from a Resource file. Globalizer doesn't have a built in mechanism to preview these resource strings applied to the actual dialog (since it doesn't know what your code does with the strings). As per your suggestion with MessageBoxes we could potentially build something into Globalizer to do this.
I think now you mean common dialogs that you have built yourself? In either case you should either be passing the localized resources that may be different from the higher layers (eg icons, strings) etc. These would then be localized in the higher layers. Another alternative would be to pass down an enum value and have the common layer load the required resources dynamically based on the enum value.
This won't allow you to see the dynamically generated resources in the preview - but the preview is just a preview it can't show everything - just like in the Visual Studio designer you can't see changes that are done programmatically. To see dynamically generated code in action your translator would need to do a deployed build and run the application. _________________ Infralution Support |
|
Back to top |
|
|
hofingerandi
Joined: 29 Nov 2010 Posts: 19
|
Posted: Tue Mar 15, 2011 8:01 am Post subject: |
|
|
Indeed I was talking about dialogs I built myself.
So the strings are localized in the higher layer (clearly, since they have to differ for Client1.exe and Client2.exe) and then transferred to the common layer by either a push- or a poll-mechanism.
I would prefer a push-mechanism, for which I can think of the following possibilities:
* Each respective class has public static fields, I can set at startup
* Common.dll grants access to specific values returned by its ResourceManager
* Common.dll allows to replace its ResourceManager by an alternative implementation (one that looks up strings in Client1.exe first, with fall-back to Common.dll)
I think, I will go for the last one, since this would lead to a one-time-effort only. Overriding a resource in Common.dll would afterwards just mean, to create a resource with the same name in the appropriate Resources.resx of Client1.exe.
Or is there some standard/recommended implementation? Looking in the web I didn't find any, but maybe I was just looking for the wrong keywords... |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Mar 15, 2011 10:21 am Post subject: |
|
|
I don't know your application architecture so it is hard to say which option would be best. Another possibility is that you consider using inheritance. In other words derive a form from the base form class defined in Common. Then you can just set the properties which are different in the derived class. This would be the "standard" mechanism for this type of thing (and would also allow previewing of the base and derived forms) - however it may not suit your needs. _________________ Infralution Support |
|
Back to top |
|
|
|