Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise FailedToOpenFileError #7305

Merged
merged 4 commits into from
Sep 17, 2024

Conversation

kphoenix137
Copy link
Collaborator

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
Copy link
Member

AJenbo commented Jul 28, 2024

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
Copy link
Collaborator Author

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
Copy link
Member

AJenbo commented Jul 29, 2024

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));

@AJenbo AJenbo merged commit 0e1e873 into diasurgical:master Sep 17, 2024
22 checks passed
@kphoenix137 kphoenix137 deleted the error-msg-failed-to-open-file branch September 17, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants