Reputation: 31
I cannot find solution for my problem for a very long time, hope here somebody can help :)
I'm developing in Visual Studio 2008 (C#) application and I want to make it multilingual.
It's a main WinForm application (call it Main.exe), which load plugins at runtime.
"Plugin" is a UserControl compiled to .dll file, where I put all the plugin's logic and elements. When needed, Main.exe loads assembly from .dll file:
Assembly asm = Assembly.LoadFile(pluginFilePath);
and attach UserControl from it to the panel.
I translate projects following way:
in Solution Explorer I put Messages.resx file and add strings and messages in default language (i.e. Name = greetings, value = Good morning everyone).
Then, I make a copy of resx file and name it Messages.es-ES.resx to have translation in Spanish. Change all the Values into Spanish (Name = greetings, value = Hola a todos).
Same for other languages.
When using in code, I can simply use:
Messages.greetings
to get localized text (and IntelliSense is working with that solution, so I want to do it this way).
When I compile project, I've following structure:
C:\App_dir\
|---------------- Main.exe
|---------------- es-ES\Main.resources.dll <-- my main program localization file in es-ES dir.
|---------------- Plugins\ <-- directory where I keep plugins in separate dirs
Now, doing the same with plugin (myPlugin.dll) gives me following files:
C:\Plugin_dir\
|--------------- myPlugin.dll
|--------------- es-ES\myPlugin.resources.dll <-- my plugin localization file
Now, the problem is when I try to make it work together:
I want to deploy plugin WITH localization file and put them as follow:
C:\App_dir\
|---------------- Main.exe
|---------------- es-ES\Main.resources.dll
|---------------- Plugins\MyPlugin\myPlugin.dll
|---------------- Plugins\MyPlugin\es-ES\myPlugin.resources.dll
In main.exe I set both:
System.Threading.Thread.CurrentThread.CurrentUICulture.Name and System.Threading.Thread.CurrentThread.CurrentCulture.Name
to new CultureInfo("es-ES") and program Main.exe runs in Spanish as I wanted, but when I load plugin from .dll it's in default (English) language...
Both (Main and plugin) are in Spanish only, when the structure is following:
C:\App_dir\
|---------------- Main.exe
|---------------- es-ES\Main.resources.dll
|---------------- es-ES\myPlugin.resources.dll
|---------------- Plugins\MyPlugin\myPlugin.dll
but this is not how I want it to be - I don't want plugin's localization file to be in other directory than the plugin itself.
So, my question is: does anybody know how to solve this problem? Is there any way to "force" loading of localization file from specific path or set some settings to assembly where to look for it?
Best regards,
Marcin
Upvotes: 3
Views: 1992
Reputation: 21
I've had the same problems in a plugin scenario. After changing Assembly.LoadFile to Assembly.LoadFrom, everything worked as expected.
Upvotes: 2
Reputation: 3250
If I understand your problem correctly, you are not able to get the Spanish text if the Spanish resource dll is under Plugins\es-ES. However it works if you put the resource file directly in <\es-ES?
One easy way to fix it would be to tell .NET to include the MyPlugins folder when it searches for assemblies.
You could do that by the following code in your app.config.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="myPlugin"/>
</assemblyBinding>
</runtime>
</configuration>
http://msdn.microsoft.com/en-us/library/823z9h8w(v=VS.100).aspx
Upvotes: 0
Reputation: 292355
Is there any way to "force" loading of localization file from specific path or set some settings to assembly where to look for it?
No, there isn't. The satellite assemblies have to be either in the GAC, or in subdirectories of the app directory. See this page for details.
Upvotes: 0