Custom Action in C# with resx localization - Advanced Installer Community
pimboden40
Posts: 22
Joined: Wed Jun 04, 2014 3:42 pm

Custom Action in C# with resx localization

Hello.
I've build an Installer that uses custom Actions written in a C# project.
My need: I have some validation and error messages I want to sent to a Session Property called CA_RESPONSE_MESSAGE.
When This Property is filled (allong with an ERROR_CODE property) I show a custom error message.
These messages are actually stored in a .resx file in my custom action project.
The default language of my AIP is English, and I also have French and German in it.
I have .resx files in my c#-custon actions project for each of these languages, that contain the translations for these languages (again being fall-back English).
When I start my installer in English everything works perfect. As soon as I select an other language, all the Messages that come from the CustomAction dll are still in English.
I tried to set the Thread to the correct Language chosen in the installerwithout success..
I even tried loading the resources with the explicit option setting the cultureInfo class to the selected language...

Code: Select all

Strings.ResourceManager.GetString("MessageErrorPasswordMissing", Thread.CurrentThread.CurrentCulture);

but it seems that advanced Installer, never included de FR /DE Sub folders That .Net generates, when you have localization on a project.

Can someone help me out, on how I can get to it. Or an alternate solution.... I was thinking of sending an LocalizationId to an Advanced Installer property and then read the translations stored in AI..
But I have no Idea if this is even possible.
Thank you for your help
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Custom Action in C# with resx localization

Hello,

I think the most straightforward way to achieve what you need is by including the localized messages directly in your custom action code, check the value of "ProductLanguage" property and, then set the related error properties with the corresponding localized values. All these actions should be performed within your custom action code. Also, please take a look on the "Windows Locale Codes" article which should be useful for you.

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pimboden40
Posts: 22
Joined: Wed Jun 04, 2014 3:42 pm

Re: Custom Action in C# with resx localization

Hello.
Thank you for your reply, but this is not the answer I was expecting. That is exactly what I tried to do... send the localized error message to the AIP project. But this doesn't work
I have Localized my custom Action Code in c# with resx.files,when you do that in c# it generates a sub-folder for each Language and includes all resource dlls, the own ones and the ones from the referenced project.

Image

if these files are not found, it falls-back to the default language localization (which is compiled IN the "main" dll)
Now.. it seems that this files are not available when I call the Custom Action to localize a given string and send it to advanced Installer
(through

Code: Select all

session["My_LOCALIZED_STRING"]= Strings.ResourceManager.GetString("MessageErrorVerifyingUser", "DE-DE"); 
or Normaly in C#

Code: Select all

session["My_LOCALIZED_STRING"]= Strings.MessageErrorVerifyingUser;
-->this would be enough in normal c# if the thread was set to use DE-DE... which is being set by my code

)
I always get the EN-US string--..which for me means that the resource dll's are not present.How can I tell the AIP Project to include this files for usage during the setup, but not to install them.
BTW:I already stated, that I have the language of the setup in the custom action, and that I know ho to localize in c# can be inferred from the line of code I sent.
Thank you
Attachments
Localized1.PNG
Localized1.PNG (9.77 KiB) Viewed 6594 times
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Custom Action in C# with resx localization

Hello,

I apologize for my previous confusing reply. What I meant was that instead of using localized .resx files you can use in your C# custom action code some constant strings (e.g. EnString, DeString, FrString, etc.). Then all you will have to do is to check the value of the "ProductLanguage" property and set your installer properties with the corresponding constant based on the "ProductLanguage" property value.

Indeed, when using a custom action to launch your DLL you cannot specify additional files to be used (alongside your main DLL) by the custom action. Therefore, the related localized .resx files will be missing at install time. Only the main DLL added in our "Custom ACtions" page will be extracted and launched.

If you still want to use the .resx files, then you can add them as temporary files in "Files and Folders" page. At install time the temporary files are extracted during the "CostFinalize" standard action and their paths can be accessed through their property values. Each temporary file has assigned a property which you can see in the "Edit Temporary File" dialog. Now, at install time you should try to access from your custom action the paths of the .resx temporary files through their property values.

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pimboden40
Posts: 22
Joined: Wed Jun 04, 2014 3:42 pm

Re: Custom Action in C# with resx localization

OK..
I'll do the Workaround then. I think that the Temp-File solution is way too complicated for my 10 localized messages.

Thank you for your time.
Last edited by pimboden40 on Wed Mar 25, 2015 5:18 pm, edited 1 time in total.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Custom Action in C# with resx localization

You're welcome.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”