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

Fix localization irregularities. #553

Merged
merged 14 commits into from
May 24, 2022

Conversation

BillyONeal
Copy link
Member

@BillyONeal BillyONeal commented May 22, 2022

It fixes all violations of localization guidelines:

  • Repeating "error:", "Error:", "warning:", or "Warning:" at the start of a message in localized blocks.
  • Indenting in localized blocks.
  • Ending localized blocks with newlines.

and adds enforcement to make sure we don't regress these.

I believe appendnl hails from a time when we thought we were going to be much more rigid about manipulation of LocalizedStrings as tokens. There are localized strings which themselves contain newlines. There are also formatted data strings, such as error message blocks join'd with \n, that we need to insert into localized messages. We also aren't likely to ever want to change our newlines to \r\n or something like that :)

To that end, I think both original reasons for this to exist are gone, and it should go away.

I think we should go all the way to removal rather than only removing the guidelines about it, because I think we, and contributors, will be confused if it exists and is relatively meaningless in the same way that people are confused (and use) std::endl today. The fact is that newlines aren't special in our LocalizedString structures, and we should be honest about that in our design.

Contrast/note: append_indent must stay, and we must add a plain std::string version of that, to ensure consistency in how we handle indenting, as this is likely to be actually ambiguous (as opposed to newlines which are always and forever \n in vcpkg).
… println or similar components that already insert newlines.
…ocalized messages, and fix remaining edge case occurrences. Also removes allow-incorrect-comments from generate-message-map considering that we control all inputs here and extending this to block these other lints seemed unnecessary.
# Conflicts:
#	include/vcpkg/base/messages.h
#	src/vcpkg/base/parse.cpp
#	src/vcpkg/build.cpp
@@ -250,6 +250,28 @@ namespace vcpkg::msg

::size_t detail::number_of_messages() { return messages().names.size(); }

std::string detail::format_examples_for_args(StringView extra_comment,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole thing is just to fix trailing whitespace in the comments of localization messages. It was sucked out into a .cpp (after being flattened from template args to a struct in the header) so that it could use Strings::join without creating header circularity or making messages.h (which is included in everything now) huge.

LocalizedString format_string_parsing_error;
Json::Object obj;
for (Message& msg : messages)
{
if (msg.name != "ErrorMessage" && Strings::case_insensitive_ascii_starts_with(msg.value, "error:"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the new lints. Note that I removed the switch to turn the lints off; we control all these inputs.

@@ -860,36 +860,30 @@ namespace vcpkg::Install
return ret;
}

DECLARE_AND_REGISTER_MESSAGE(ErrorRequirePackagesToInstall,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message was deleted as it is unreferenced.

@@ -76,7 +73,7 @@ namespace vcpkg
{
if (platform)
{
return {msg::format(msgIllegalPlatformSpec).data(), expected_right_tag};
return {msg::format(msg::msgErrorMessage).append(msgIllegalPlatformSpec).data(), expected_right_tag};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to mess with it in this change, but I think we need a shorter way to get to msg::format(msg::msgErrorMessage)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format_error() has my vote.

VersionSpecMismatch,
(msg::path, msg::expected_version, msg::actual_version),
"",
"Failed to load port because versions are inconsistent. The file \"{path}\" contains the version "
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote this error to make sense without the indent formatting. I could resolve it differently by breaking it up in to separate messages to preserve the indenting if people want.

include/vcpkg/base/messages.h Show resolved Hide resolved
include/vcpkg/base/messages.h Outdated Show resolved Hide resolved
include/vcpkg/base/messages.h Outdated Show resolved Hide resolved
src/vcpkg/commands.generate-message-map.cpp Show resolved Hide resolved
@@ -76,7 +73,7 @@ namespace vcpkg
{
if (platform)
{
return {msg::format(msgIllegalPlatformSpec).data(), expected_right_tag};
return {msg::format(msg::msgErrorMessage).append(msgIllegalPlatformSpec).data(), expected_right_tag};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format_error() has my vote.

@@ -597,10 +597,10 @@ namespace vcpkg

DECLARE_AND_REGISTER_MESSAGE(
ErrorMissingVcpkgRoot,
(msg::url),
(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had extracted out the url since it isn't localizable content.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK to for messages to have some content which isn't localizable; for example we talk about command line flags and stuff that aren't localized either. The comment needs to describe this. (Putting it back though)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, not putting it back because I changed these instructions to ask people to file GitHub issues.

@@ -268,7 +268,7 @@ namespace vcpkg::Build
LocalizedString errorMsg = msg::format(msg::msgErrorMessage).append(msgBuildDependenciesMissing);
for (const auto& p : result.unmet_dependencies)
{
errorMsg.append_indent().append_raw(p.to_string()).append_raw('\n');
errorMsg.append_raw('\n').append_indent().append_raw(p.to_string());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that this changes behavior (one newline instead of two)

"architecture was {arch}\n "
"The selected Visual Studio instance is at {path}\n The available toolchain combinations are {list}\n");
"in triplet {triplet}: Unable to find a valid toolchain for requested target architecture {arch}.\n"
"The selected Visual Studio instance is at: {path}\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that this change drops indentation.

@BillyONeal
Copy link
Member Author

Those behavior changes seem reasonable to me.

@BillyONeal BillyONeal merged commit 4ba70e9 into microsoft:main May 24, 2022
@BillyONeal BillyONeal deleted the fix-localized-newlines branch May 24, 2022 23:02
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