oleg-shilo / wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
MIT License
1.07k stars 169 forks source link

How to localization for Embedded WPF UI MSI #1505

Open bh-ubunye opened 2 months ago

bh-ubunye commented 2 months ago

Hi Teams,

We are developing an MSI installer using an embedded WPF UI. We would like to localize the string display inside the controls of the installer's WPF.

We are using the resources file specific for the language. Our resources files generated during pipeline creation.

During the MSI installer's run time, how can I get to the localized resources?

oleg-shilo commented 2 months ago

Your resource file should be embedded in the assembly at compile time. Then you can access it at runtime as in any WPF application.

Have a look at this thread, it seems to be related: https://github.com/oleg-shilo/wixsharp/issues/1499

bh-ubunye commented 2 months ago

Ya, we thought the same, but our MSI installer is unable to access other language resource files (ex., German translation) other than English during runtime. 

Whether we needed to include all other language resource files in MSI code?

oleg-shilo commented 2 months ago

As I mentioned in that issue I referenced, you have two options:

bh-ubunye commented 2 months ago

Hi Oleg,

Do you have any samples of load binary table into res manager?

oleg-shilo commented 2 months ago

All the required bits are sprinkled around the sample projects (e.g. MultiLanguageUI project, ProgressDialog.cs ) but since it is a generic .NET technique, I will summarize it:

And if you want to dynamically substitute WPF resource dictionaries at runtime it is also possible (I did it long time ago 😄) but you will nee you will search for the solution from WPF sources.

bh-ubunye commented 2 months ago

Hi Oleg,

We created our installer UI from the WPF project and embedded it in the MSI project; therefore, we were unable to access the session binary to extract the other language resources, and EmbeddedUI msi was unable to execute the UIInitialized. 

Does it have any ways to let us access the binary file we bind to MSI in the WPF project?

oleg-shilo commented 2 months ago

I am not sure I follow.

Any embedded UI that is packed with msi is loaded at runtime by msi and an active session object is passed to it. Always.

If you are using WixSharp-provided UI then the session is channeled through WixSharp events like UIInitialized.

If you are using your own raw UI then it has to implement:

 bool Initialize(Session session, string resourcePath, ref InstallUIOptions internalUILevel);

Meaning that you always have access to the session. And then you can always read binary.

So I do not really understand we were unable to access the session binary.

bh-ubunye commented 2 months ago

I believe I misrepresented our problem, we were able to acccess the session in our raw UI project. Our problem was that we couldn't read the binary file that was associated to the session in our own raw user interface, even though we could access the session.

Do we need to add the "Wixsharp" reference to our UI project in order to utilize the reading function, or is there another way we may be able to access the binary file?

oleg-shilo commented 2 months ago

Great. We are now progressing.

If you have access to the session then it should be no problem reading the msi tables.

Our problem was that we couldn't read the binary file that was associated to the session...

The description above is not explicit but it makes me think that you are talking about a runtime exception.

However Do we need to add the "Wixsharp" reference? makes me think that you do not reference WixSharp currently, what makes this code break the compilation:

byte[] de_data = e.Session.ReadBinary("de_dll"); // ReadBinary is implemented in WixSharp.dll

And yet you did not indicate what type of problem it is (e.g. compile time vs runtime).

I am guessing that it is in fact compile time so I suggest you add the reference and use the code snippet I provided earlier.