GUI: BCP47: group warnings

Part of the implementation of #3307.
This commit is contained in:
Moritz Bunkus 2022-03-29 21:10:02 +02:00
parent d04ac487d1
commit 3c52a6d26d
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85

View File

@ -468,12 +468,28 @@ LanguageDialog::determineInfoAndWarningsFor(mtx::bcp47::language_c const &tag) {
lists.second << QY("The variant '%1' is deprecated.").arg(Q(variantStr));
}
if (!tag.get_grandfathered().empty())
lists.second << QY("This language tag is a grandfathered element only supported for historical reasons.");
auto const canonical_form = tag.clone().to_canonical_form();
auto const extlang_form = tag.clone().to_extlang_form();
auto const normalizationMode = Util::Settings::get().m_bcp47NormalizationMode;
auto const badVariantStr = tag.get_first_variant_not_matching_prefixes();
auto const badVariant = mtx::iana::language_subtag_registry::look_up_variant(badVariantStr);
if (badVariant && !badVariant->prefixes.empty()) {
QStringList sentences;
sentences << QY("The variant '%1' is used with prefixes that aren't suited for it. Suitable prefixes are: %2.")
.arg(Q(badVariantStr)).arg(Q(mtx::string::join(badVariant->prefixes, ", ")));
if ((canonical_form != tag) && canonical_form.get_first_variant_not_matching_prefixes().empty())
sentences << QY("The canonical form does use a suitable prefix.");
if ((extlang_form != tag) && extlang_form.get_first_variant_not_matching_prefixes().empty())
sentences << QY("The extended language subtags form does use a suitable prefix.");
lists.second << sentences.join(Q(" "));
if (!tag.get_grandfathered().empty())
lists.second << QY("This language tag is a grandfathered element only supported for historical reasons.");
}
if ( (tag != canonical_form)
&& (tag != extlang_form)
@ -492,26 +508,6 @@ LanguageDialog::determineInfoAndWarningsFor(mtx::bcp47::language_c const &tag) {
}
}
auto badVariantStr = tag.get_first_variant_not_matching_prefixes();
if (badVariantStr.empty())
return lists;
auto badVariant = mtx::iana::language_subtag_registry::look_up_variant(badVariantStr);
if (!badVariant || badVariant->prefixes.empty())
return lists;
QStringList sentences;
sentences << QY("The variant '%1' is used with prefixes that aren't suited for it. Suitable prefixes are: %2.")
.arg(Q(badVariantStr)).arg(Q(mtx::string::join(badVariant->prefixes, ", ")));
if ((canonical_form != tag) && canonical_form.get_first_variant_not_matching_prefixes().empty())
sentences << QY("The canonical form does use a suitable prefix.");
if ((extlang_form != tag) && extlang_form.get_first_variant_not_matching_prefixes().empty())
sentences << QY("The extended language subtags form does use a suitable prefix.");
lists.second << sentences.join(Q(" "));
return lists;
}