Is it possible to pass variable to WIX localization file?
Asked Answered
K

4

14

I need to use variable in WIX localization file WIXUI_en-us.wxl. I tried use it like this:

<String Id="Message_SomeVersionAlreadyInstalled" Overridable="yes">A another version of product $(var.InstallationVersionForGUI) is already installed</String>

But it doesn't work. And when I declared property and used it this way:

<String Id="Message_SomeVersionAlreadyInstalled" Overridable="yes">A another version of product [InstallationVersionForGUI] is already installed</String>

doesn't work either.

Where was I wrong?

Thanks for help and your time.

Kurth answered 26/7, 2011 at 9:25 Comment(0)
C
19

Localization strings are processed at link time, so you can't use $(var) preprocessor variables. Using a [property] reference is supported, as long as the place where the localization string is used supports run-time formatting (e.g., using the Formatted field type).

Cyan answered 26/7, 2011 at 16:36 Comment(3)
See also joyofsetup.com/2013/02/06/l10nm10n-localization-minimization for information about reusing localization strings within other localization strings.Cyan
I'm using Wix3.10 and I can't use a Localization Strings within another Localization String.Aquilegia
WiX 3.11: still can't use a Localization Strings within another Localization String.Keel
L
16

Your second method should work just fine. This is the same method used by the default .wxl files.

For example, in your .wxl file you would declare your string:

<String Id="Message_Foo">Foo blah blah [Property1]</String>

And in your .wxs file, you declare the property. If you wish, you can declare the property to match a WiX variable (which it sounds like you're trying to do)

<Property Id="Property1">$(var.Property1)</Property>
Licht answered 27/7, 2011 at 1:24 Comment(6)
Strange, now this method works. I don't know what was wrong, but thank you anyway!Kurth
Does not work for me, Message_Foo as accessed with !(loc.Message_Foo) still returns the static unevaluated string for me, being literally "Foo blah blah [Property1]". Where exactly do you define the property?, it was in the main wxs file after the Package element in my case ...Sudduth
@Sudduth properties are case sensitive, thats about the only issue I can think of unless you're not referring to items in the String table.Licht
I found a somewhat disappointing answer on wix users mailing list: "That means you're trying to use properties in a string that isn't formatted." - seems like it is not possible to properly template Wix localization files at the moment as a lot of the targets are not formatted; and you need to take the use targets into account rather than the evaluations always working ...Sudduth
@cel that specific answer on the mailing list is a little vague, if you know the property at build time you can just combine wix variables and localizations... e.g. <Product Id="*" UpgradeCode="$(var.Property_UpgradeCode)" Name="!(loc.ApplicationName) $(var.versionmajor)" Language="!(loc.Property_ProductLanguage)" Version="$(var.version)" Manufacturer="!(loc.ManufacturerName)" >Licht
How do you set and use a property in bootstrapper project?Keel
T
1

Preprocessor variables $(var.VariableName) are are processed at link time, so ideally you would use [PropertyName] which would be defined on the main Product element.

The issue sometimes is that property is not yet defined, for instance using the product name on the localization file seems not posible.

This solution was done aiming to only type the product name once given "Super product" as product name:

  • In case of running through visual studio extension:
    • Project properties -> Build -> Define variables -> "MyProductName=Super product" (No quotes)
  • In case of runing from cmd or some other place:
    • On Light.exe, add -d"MyProductName=Super product"

Into the localization .wxl file:

<String Id="Description" Overridable="yes">Description of !(wix.MyProductName) 
 to make it more interesting</String>

I have an aditional config file .wxi I include on other files to have some vars, for instance, here i had hardcoded the value but now it's harcoded on the variable definition and I use the given value:

<?xml version="1.0" encoding="utf-8"?>
<Include>
    <!-- Define the product name preprocesor variable -->
    <?define ProductName="!(wix.ProductNameDefVar)" ?>
    <!-- From this point, can use the preprocesor var -->
    <?define ProductName_x64="$(var.ProductName) (64bit)" ?>
    <?define ProductName_x32="$(var.ProductName) (32bit)" ?>
    <?define CompanyDirName = "My company name" ?>
</Include>

Finally, the place where the localization value where the localization text was not interpolating, is like this:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

  <!-- Include the config file with the preprocesor var -->
  <?include $(sys.CURRENTDIR)\Config.wxi?>
 
  
  <!-- Main product definition -->
  <Product  Id="$(var.ProductCode)"
    Name="$(var.ProductName)"
    Language="!(loc.Language)"
    Version="$(var.BuildVersion)"
    Manufacturer="!(loc.Company)"
    UpgradeCode="$(var.UpgradeCode)">
    
    <!-- Package details -->
    <!-- Here, Description was not interpolating -->
    <Package InstallerVersion="200"
             Compressed="yes" 
             InstallScope="perMachine" 
             Platform="$(var.Platform)"
             Manufacturer="!(loc.Company)"
             Description="!(loc.Description)"
             Keywords="!(loc.Keywords)"
             Comments="!(loc.Comments)"
             Languages="!(loc.Language)"
             />
[...]
Taxiway answered 5/12, 2022 at 10:29 Comment(0)
L
0

I was trying to get localization file to use variables. Came across this post:

There are different layers of variables in WiX (candle's preprocessor variables, Light's WixVariables/localization variables/binder variables, and MSI's properties). Each have different syntax and are evaluated at different times:

Candle's preprocessor variables "$(var.VariableName)" are evaluated when candle runs, and can be set from candle's commandline and from "" statements. Buildtime environment properties as well as custom variables can also be accessed similarly (changing the "var." prefix with other values).

Light's variables accessible from the command-line are the WixVariables, and accessing them is via the "!(wix.VariableName)" syntax. To access your variable from your commandline, you would need to change your String to: This build was prepared on !(wix.BuildMachine)

If you instead need to have the BuildMachine value exist as an MSI property at installation time (which is the "[VariableName]" syntax) you would need to add the following to one of your wxs files in a fragment that is already linked in:

Now, the environment variable COMPUTERNAME always has held the name of my build machines in the past, and you can access that this way: $(env.COMPUTERNAME). So, you can get rid of the commandline addition to light.exe and change your wxs file like this:

<WixProperty Id="BuildMachine" Value="$(env.COMPUTERNAME)"/>

Laity answered 4/1, 2013 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.