diasurgical / devilutionX

Diablo build for modern operating systems
Other
8.01k stars 786 forks source link

Revise FailedToOpenFileError #7305

Closed kphoenix137 closed 1 week ago

kphoenix137 commented 2 months ago

image

Adds a bit of text for the end user to get a bit of context on what the problem is, so that they might be able to solve the problem on their own without additional support.

AJenbo commented 2 months ago

Good ide, but how about this phrasing instead: "The MPQ file(s) might be damaged. Please check the file integrity."

... oh and this text should for sure be translatable as well

kphoenix137 commented 2 months ago

The MPQ file(s) might be damaged. Please check the file integrity.

Got the first part. Can you help with the second part? The translation code always seems very confusing to me and I'm never sure how do do it right.

AJenbo commented 2 months ago

First step is to not use concatenation and instead have a single sensible text string that the translators can work with in a meaningful way. So instead of "Hello" + name + " and welcome to our town", it should be a single string so that the relevant context can be translated sensibly, imagine a language where the proper form would be "Welcome to our town {name}; and hello to you". They would possibly have to translate "Hello" in to "Welcome to our town", but that might not work in other contexts where "Hello" appears and isn't obvious to the translator without reading the code where it is being concatenated. So instead of concatenation we use fmt to replace templates in the string.

When that is taken care of you simply wrap any string that should be translated in a call to _().

If it's not a literal string and the actual string is defined statically elsewhere then the static definition needs to be wrapped in N_() for it to be presented to the translators so they can write a translation for it.

When the string has variables (like the file name in this case) you want to translate the raw string before combining it with the variables, since the translation data contains the one with the template and not the infinite many variations it could become given the variable.

Using fmt format instead of concat:

app_fatal(fmt::format(fmt::runtime("Failed to open file:\n{:s}\n\n{:s}\n\nThe MPQ file(s) might be damaged. Please check the file integrity."), path, error));

Make it translatable:

app_fatal(fmt::format(fmt::runtime(_("Failed to open file:\n{:s}\n\n{:s}\n\nThe MPQ file(s) might be damaged. Please check the file integrity.")), path, error));