GlotPress / GlotPress

:earth_africa: :earth_americas: :earth_asia: GlotPress is a WordPress plugin to let you set up your own collaborative, web-based software translation tool.
https://wordpress.org/plugins/glotpress/
GNU General Public License v2.0
339 stars 123 forks source link

Fatal Error in GP_Builtin_Translation_Warnings::warning_named_placeholders() #1530

Closed dd32 closed 1 year ago

dd32 commented 1 year ago

The following fatal error has happened on translate.wordpress.org a few times since #1450

Uncaught TypeError: Argument 2 passed to GP_Builtin_Translation_Warnings::warning_named_placeholders() must be of the type string, array given, called in wp-content/plugins/glotpress/gp-includes/warnings.php on line 101 and defined in wp-content/plugins/glotpress/gp-includes/warnings.php:671

Stack trace:
#0 wp-content/plugins/glotpress/gp-includes/warnings.php(101): GP_Builtin_Translation_Warnings->warning_named_placeholders('locale_data', Array, Object(GP_Locale))
#1 wp-content/plugins/glotpress/gp-includes/things/translation-set.php(304): GP_Translation_Warnings->check('locale_data', NULL, Array, Object(GP_Locale))
#2 wp-content/plugins/glotpress/gp-includes/routes/translation.php(102): GP_Translation_Set->import(Object(Translations), 'waiting')
#3 wp-content/plugins/glotpress/gp-includes/router.php(218): GP_Route_Translation->import_translations_post('wp-plugins/...', 'hu', 'default')
#4 wp-content/plugins/glotpress/gp-includes/rewrite.php(79): GP_Router->route()
#5 wp-includes/class-wp-hook.php(308): gp_run_route('')
#6 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#7 wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#8 wp-includes/template-loader.php(13): do_action('template_redire...')
#9 wp-blog-header.php(19): require_once('...')
#10 index.php(18): require('..')
#11 {main}
 thrown
Source: POST https://translate.wordpress.org/projects/wp-plugins/{$plugin_name}/stable/hu/default/import-translations/

It's caused by this:

#1 wp-content/plugins/glotpress/gp-includes/things/translation-set.php(304): GP_Translation_Warnings->check('locale_data', NULL, Array, Object(GP_Locale))

So.. I suspect the issue is that a singular string has been translated into a plural in the source file, as plural is NULL in that but an array of translations is being passed.. Not sure how/what/why.

Looks like they're all JSON imports, so it might just be that the JSON parser isn't rejecting a badly formed file.

dd32 commented 1 year ago

Related Warnings:

E_WARNING: array_unique() expects parameter 1 to be array, null given in wp-content/plugins/glotpress/gp-includes/warnings.php:521
E_WARNING: preg_match_all() expects parameter 2 to be string, array given in wp-content/plugins/glotpress/gp-includes/warnings.php:520
E_WARNING: strpos() expects parameter 1 to be string, array given in wp-content/plugins/glotpress/gp-includes/strings.php:7
E_WARNING: substr() expects parameter 1 to be string, array given in wp-content/plugins/glotpress/gp-includes/strings.php:11
E_WARNING: Invalid argument supplied for foreach() in wp-content/plugins/glotpress/gp-includes/warnings.php:417
E_WARNING: preg_match_all() expects parameter 2 to be string, array given in wp-content/plugins/glotpress/gp-includes/warnings.php:252
E_WARNING: mb_strlen() expects parameter 1 to be string, array given in wp-content/plugins/glotpress/gp-includes/warnings.php:214
E_WARNING: array_diff(): Expected parameter 2 to be an array, null given in wp-content/plugins/glotpress/gp-includes/warnings.php:523

All seem to be the same root-cause, so going back up the stack and validating the JSON file being imported seems the sanest choice.

amieiro commented 1 year ago

I close this issue, as the PR that resolves this problem has been merged and released.