-
Notifications
You must be signed in to change notification settings - Fork 120
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
Integrate wporg custom warnings #1243
Integrate wporg custom warnings #1243
Conversation
This method allows for the scheme to change, and for some domains to change to a subdomain. This method integrates a warning from an existing plugin at https://translate.wordpress.org , available at https://github.com/WordPress/wordpress.org/blob/master/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-warnings/wporg-gp-custom-warnings.php#L37 , so that this validation is available to all GlotPress users.
This method integrates a warning from an existing plugin at https://translate.wordpress.org , available at https://github.com/WordPress/wordpress.org/blob/master/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-warnings/wporg-gp-custom-warnings.php#L131 , so that this validation is available to all GlotPress users. - URLs (href + src) are run through `self::warning_mismatching_urls()` - The domain may change for some safe domains - The protocol may change between https & http - The URL may include/remove a trailing slash - The value of translatable/URL attributes is excluded from the error message if it's not related to the issue at hand. - Tags are validated to be nested correctly, validating the ordering of the tags remained the same. - East Asian languages can remove emphasis/italic tags.
This only supports placeholders in the format of '###[A-Z_]+###'. This method integrates a warning from an existing plugin at https://translate.wordpress.org , available at https://github.com/WordPress/wordpress.org/blob/master/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-warnings/wporg-gp-custom-warnings.php#L238 , so that this validation is available to all GlotPress users.
…string. This is to catch translations for originals like this: - Original: `<a href="%s">100 percent</a>` - Submitted translation: `<a href="%s">100%</a>` - Proper translation: `<a href="%s">100%%</a>` This method integrates a warning from an existing plugin at https://translate.wordpress.org , available at https://github.com/WordPress/wordpress.org/blob/master/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-warnings/wporg-gp-custom-warnings.php#L276 , so that this validation is available to all GlotPress users.
This code comes from the PR #1237 and integrates an update in a filter from an existing plugin at https://translate.wordpress.org , available at https://github.com/WordPress/wordpress.org/blob/7c67af3e7b49333ce3c5d565e57fa439c9c52223/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-warnings/wporg-gp-custom-warnings.php#L312 , so that this check is available to all GlotPress users.
Adds a new test to increase the code coverage and other tests to check the output when the check has warnings
Adds two new tests to increase the code coverage
Adds a new test to an edge case, to increase the code coverage
This option value will be used to conditionally execute code related with the wporg installation
Create a new class (GP_Wporg_Translation_Warnings) for the wporg warnings and inject it using hooks in the GP_Builtin_Translation_Warnings class. Inject the specific wporg list of domains with allowed changes to their own subdomains and a specific wporg warning for changing placeholders in the format of '###[A-Z_]+###'.
- Remove the tag order validation, because this depends of the translation language - Remove the validation that checks if the links that are not URL are equal or not - Check if the translation tags are in correct order. This method warns about HTML tags translations in incorrect order. For example: - Original: <a></a> - Translation: </a><a>
… are equal or not
Include the assertContainsOutput() and the assertHasWarnings() methods in one new method with the same functionality that both methods. Refactor the GP_Test_Builtin_Translation_Warnings class to comply with the WordPress Coding Standards.
Thanks for working on this! What was your motivation to adopt the custom warnings? Before going into a deep review, everything related to |
Looking at the two specific warnings, I think they can be integrated too without the need to set a |
Remove the wporg parametrization Move and adapt the tests from the wporg parametrization to the warning core tests Add 4 allowed domains
I have removed all the wporg parametrization, including the CLI command, and I have integrated the domains and the specific warning in the builtin warnings. I have named the moved method as "warning_mismatching_placeholders", to maintain the same name that it has now in the wporg plugin. |
I still don't think that this is a good name when you compare it with |
I think we can change |
…lation_placeholders()
The GlotPress installed at WordPress.org has a plugin that implements some custom translation warnings. It adds some new warnings and makes changes to some core Glotpress warnings.
This PR migrates those warnings from the custom plugin to GlotPress.
The warnings are managed in GlotPress in two classes, both in the "gp-includes/warnings.php" file:
This PR:
Adds a new CLI command (GP_CLI_Wporg class, available at "gp-includes/cli/wporg.php") to be able to set the installation as the wporg installation. This CLI command sets or removes an option variable (gp_is_wporg) in the options table. The usage of this command is very simple:
wp glotpress wporg set
wp glotpress wporg unset
Adds or updates the methods from the wporg plugin that can fit in the generic solution in the GP_Builtin_Translation_Warnings class:
Adds the warning_mismatching_urls() method. This method adds a warning for changing plain-text URLs. This method allows:
This method has a hook to update the list of domains with allowed changes (empty by default). More info in the point 3.
Adds the warning_unexpected_sprintf_token() method. This method adds a warning for adding unexpected percent signs in a sprintf-like string. This is to catch translations for originals like this:
<a href="%s">100 percent</a>
<a href="%s">100%</a>
<a href="%s">100%%</a>
Updates the warning_tags() method with the wporg check rules:
<em>One</em> <strong>Two</strong>
can be translated as<strong>foo</strong> <em>bar</em>
without generating warning.Adds two new rules to the warning_tags() method, not present in the wporg plugin:
<a></a>
</a><a>
<a href="%s" title="Blimp!">Baba</a>
<a href="javascript:%s" title="Блимп!">Баба</a>
Adds a new class (GP_Wporg_Translation_Warnings, available at "gp-includes/wporg/warnings.php") to handle wporg installation specific elements that do not fit in the generic plugin. Currently, this class has two relevant methods:
Currently, this new class has only a new warning method, warning_wporg_mismatching_placeholders(), that adds a warning for changing placeholders. This method only supports placeholders in the format of '###[A-Z_]+###'. This warning method is so specific that only fits in the wporg installation.
The two new hooks present in the GP_Builtin_Translation_Warnings class (gp_allowed_domain_changes and gp_add_all_warnings) are only "hooked" if a variable (gp_is_wporg) is set in the options table, setting the installation as the wporg installation.
Note: This PR includes the changes of this other PR.
Architecture
This architecture, which separates the common warnings from the wporg warnings and injects them via hooks, is extensible, because:
Tests
I have added new tests for these new or updated methods. I have divided the tests in two files:
Test improvements