Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#42510 closed defect (bug) (fixed)

Error messages rendered by JS are not translated

Reported by: munyagu's profile munyagu Owned by: westonruter's profile westonruter
Milestone: 4.9 Priority: normal
Severity: major Version: 4.9
Component: I18N Keywords: has-patch dev-reviewed
Focuses: Cc:

Description

Attachments (11)

No.1.jpg (30.4 KB) - added by munyagu 6 years ago.
No.2.png (6.6 KB) - added by munyagu 6 years ago.
customizer-two-message.png (8.7 KB) - added by munyagu 6 years ago.
42510.png (7.1 KB) - added by Presskopp 6 years ago.
42510-2.png (1.1 MB) - added by odysseygate 6 years ago.
_n may have the same trouble.
42510.patch (1.3 KB) - added by ocean90 6 years ago.
42510.2.diff (5.0 KB) - added by westonruter 6 years ago.
invalid-html-on-widget.png (17.1 KB) - added by Mirucon 6 years ago.
czr-notice.png (23.9 KB) - added by Mirucon 6 years ago.
additional-css.png (74.3 KB) - added by Mirucon 6 years ago.
theme-editor.png (57.1 KB) - added by Mirucon 6 years ago.

Download all attachments as: .zip

Change History (36)

@munyagu
6 years ago

@munyagu
6 years ago

This ticket was mentioned in Slack in #polyglots by munyagu. View the logs.


6 years ago

#2 follow-up: @swissspidy
6 years ago

  • Keywords close added

There is %d error which must be fixed before you can save.

I can see this string in GlotPress, under the "4.9.x - Development" project.

This one is translated but not reflected online.

Make sure you're using updated translation files on your site

#3 @munyagu
6 years ago

There is %d error which must be fixed before you can save.

I can see this string in GlotPress, under the "4.9.x - Development" project.

It's in ja.po but not in admin-ja.po.

This one is translated but not reflected online.

Make sure you're using updated translation files on your site

I tried again and it was translated.
Sorry.

#4 in reply to: ↑ 2 @martian36
6 years ago

Hi, I updated to recent nightly build 4.9-RC2-42149 and also the translations, but the issue is the same.

#5 @swissspidy
6 years ago

It's in ja.po but not in admin-ja.po.

That's correct. Strings are in either ja.po OR admin-ja.po, not in both. https://github.com/WordPress/WordPress/blob/e8229a25d5f4c620ef5f021abe70224cc6c550de/wp-includes/widgets/class-wp-widget-custom-html.php#L180 is not in wp-admin, thus the string won't be in admin-ja.po anyway.

#6 @munyagu
6 years ago

Does it mean the messages for the administrative screens, which are arguments to the translation functions, are not translated on the administration screen?

These messages are included in decompiled my ja.mo.
These messages means "There is %d error which must be fixed before you can save." and "Unable to save due to %s invalid setting.".

Version 0, edited 6 years ago by munyagu (next)

#7 @Presskopp
6 years ago

Same issue with german - I even downloaded the full translation package and replaced the one I got on my HD, I've seen the translations are in the .po - but no. I wonder if it has to do with the usage of _n_noop in script-loader.php.

@Presskopp
6 years ago

#8 @Presskopp
6 years ago

  • Keywords close removed

#9 @Mirucon
6 years ago

I am getting the same issue.

I can confirm that the string is in the .po file and I tried to compile to .mo file from the po file (so the mo file must have the string), but still getting same.

Tested on WP 4.9-RC2, VCCW, with Japanese translation.

This ticket was mentioned in Slack in #core by presskopp. View the logs.


6 years ago

#11 @munyagu
6 years ago

@swissspidy
I did not recognize, not only admin-ja.mo but also ja.mo is load in administration screen.
I noticed that customizer preview would not be displayed unless aja.mo was loaded with @Presskopp comment.

Last edited 6 years ago by munyagu (previous) (diff)

@odysseygate
6 years ago

_n may have the same trouble.

#12 follow-up: @odysseygate
6 years ago

Im getting the same issue, too.
In addition of _n_noop, _n seems to be unable to reflect translation: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-customize-manager.php?marks=2702#L2702

Last edited 6 years ago by odysseygate (previous) (diff)

@ocean90
6 years ago

#13 @ocean90
6 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.9
  • Severity changed from normal to major

As mentioned in the DocBlock, _n_noop() does not translate strings. So the use of wp_array_slice_assoc() and _n_noop() doesn't really work.

For a possible workaround without string changes see 42510.patch (incomplete). Not perfect, ideally it should be two separate strings until we have a proper i18n API in JS.

#14 @ocean90
6 years ago

  • Version changed from trunk to 4.9

#15 in reply to: ↑ 12 ; follow-up: @westonruter
6 years ago

Replying to odysseygate:

Im getting the same issue, too.
In addition of _n_noop, _n seems to be unable to reflect translation: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-customize-manager.php?marks=2702#L2702

Maybe it's because that same string appears with _n_noop() in script-loader.php:

https://github.com/WordPress/wordpress-develop/blob/48980cd/src/wp-includes/script-loader.php#L589-L593

Whereas it appears with _n() in class-wp-customize-manager.php:

https://github.com/WordPress/wordpress-develop/blob/48980cd/src/wp-includes/class-wp-customize-manager.php#L2699-L2703

Maybe the _n_noop() is clobbering the _n(). I confess I don't understand the mechanics of i18n very well.

#16 in reply to: ↑ 15 @dd32
6 years ago

Replying to westonruter:

Maybe the _n_noop() is clobbering the _n(). I confess I don't understand the mechanics of i18n very well.

The issue is the _n_noop() doesn't perform translations - it's literally an array passthrough for use later by translate_nooped_plural() - it's not an issue of being clobbered.
https://developer.wordpress.org/reference/functions/_n_noop/ has an example of that usage (plus the source of the function there)

So instead, it should pass through a translated 'singular' and a translated 'plural' string to JS (be that two _n()'s using 1 & 2 as the count as in 42510.patch, or literally __() twice), both of those will be incorrect in some languages, but as @ocean90 said, until we have a JS translation API such as what Gutenberg is using, we have no other way to do it properly.

Maybe it's because that same string appears with _n_noop() in script-loader.php:

Just to note, if it's not clear - all of those _n_noop() calls there will need changing, as they're all not currently translated strings.

Last edited 6 years ago by dd32 (previous) (diff)

@westonruter
6 years ago

#17 @westonruter
6 years ago

  • Keywords has-patch dev-feedback added; needs-patch removed

42510.2.diff fixes the the remaining JS-targeted usages of _n_noop().

In all I count 4 instances:

  1. Error message when adding invalid HTML to the Custom HTML widget.
  2. Error message in Customizer's global notification area when there is an invalid setting.
  3. Error message in Customizer's Additional CSS when there is a syntax error.
  4. Error message in theme/plugin editor when there are linting errors.

@dd32 @ocean90 Would either of you dev-reviewed and commit to trunk and the 4.9 branch so translators can get to work prior to a planned RC3 in ~12 hours?

@Mirucon
6 years ago

@Mirucon
6 years ago

#18 @Mirucon
6 years ago

42510.2.diff looks good to me!

#19 @dd32
6 years ago

  • Keywords dev-reviewed added; dev-feedback removed

42510.2.diff Looks good to me, tested that a translated string appears in the custom CSS error message, would like someone who can read a non-en locale verify it too though :)

Tested using Japanese, and the original string in question appears translated (Tested using trunk) - https://cloudup.com/cxMxRfcHWZS

This ticket was mentioned in Slack in #core-i18n by westonruter. View the logs.


6 years ago

#21 @westonruter
6 years ago

  • Owner set to westonruter
  • Status changed from new to accepted

#22 @Mirucon
6 years ago

I can see the strings in the image (https://cloudup.com/cxMxRfcHWZS) are translated properly. Looks good to commit.

#23 @westonruter
6 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 42163:

I18N: Fix passing singular/plural strings to JS.

This is a temporary solution while waiting for full I18N support in JS.

Props ocean90, dd32, westonruter, Mirucon for testing.
Amends [41376], [41721], [41389],
See #20491.
Fixes #42510 for trunk.

#24 @westonruter
6 years ago

In 42164:

I18N: Fix passing singular/plural strings to JS.

This is a temporary solution while waiting for full I18N support in JS.

Props ocean90, dd32, westonruter, Mirucon for testing.
Amends [41376], [41721], [41389].
See #20491.
Fixes #42510 for 4.9.

#25 @westonruter
6 years ago

  • Summary changed from Can't reflect translation to Error messages rendered by JS are not translated
Note: See TracTickets for help on using tickets.