winresource icon indicating copy to clipboard operation
winresource copied to clipboard

Add support to generate multi-language resource files

Open Korne127 opened this issue 9 months ago • 0 comments

The VarFileInfo block in a ResourceFile looks roughly like this:

BLOCK "VarFileInfo"
{
    VALUE "Translation", 0x409, 0x04b0
}

However, according to the Microsoft documentation

[The block] typically contains a list of languages that the application or DLL supports.

The structure should list the supported languages. This is a list with variable length. For example, it could look like VALUE "Translation", 0x409, 0x04b0, 0x0407, 0x04b0 for English (US) and German.

The Microsoft documentation further states that

If you use the Var structure to list the languages that your application supports, the number of StringTable structures in the version resource is directly related to the number of language/code page identifier pairs in the Value member of the Var structure.

I'm not an expert with ResourceFiles but I think that you're supposed to add a StringTable (containing ProductName, ProductVersion, FileVersion, InternalName, etc.) for each language you support.

To create a multi-language resource file, the crate might need to become more modular, allowing one to set the StringTable strings for any language. I think the best way to do this would be to have a function like add_translation(&mut self, language: u16) -> &mut StringTable that creates a StringTable struct for that language and returns it. You could set any String in a StringTable with a set function (like you do now), but unless you overwrite a value specifically for a specific language, the values given from Cargo or the global (current) set method would be used (like they are now). This way, you wouldn't need to set the mostly same values over and over again but can use the crate like now and just call add_translation for each language that should be included, and you still have the possibility to overwrite specific values for each language. And all the added languages are included in the VarFileInfo block. This would replace set_language.

What do you think about this?

Korne127 avatar May 08 '24 21:05 Korne127