JavaScript strings are never translated, as `wp_set_script_translations` is never called

Aperta
#4,547 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php, typescript, wordpress

Direzione di ricerca

Inizia ispezionando i percorsi di enqueue in class-editor-sidebar.php, class-dashboard-widget.php, class-post-list-stats.php, class-recommended-widget.php e nel codice della dashboard e della telemetria. Controlla ogni script handle inserito manualmente e verifica la riproduzione in Post Editor con una locale del sito tradotta. Il lavoro è completato quando le stringhe JavaScript in queste aree sono tradotte e il blocco Recommendations esistente e le traduzioni PHP continuano a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug wp-parsely

Describe the bug

The plugin marks its JavaScript strings as translatable and declares Text Domain: wp-parsely, but never calls wp_set_script_translations() for any script it enqueues itself. That call is what loads the .json translation files WordPress delivers for JavaScript, so without it every one of those strings renders in English regardless of the site's language.

There are 359 __() and 7 _n() calls across 74 TypeScript files. By surface:

Location Calls Translated?
src/content-helper 333 No
src/js 4 No
src/blocks 22 Yes

The Recommendations block is fine because it is registered through register_block_type() with a block.json carrying "textdomain": "wp-parsely", and WordPress wires up script translations automatically in that case. Every other surface is enqueued by hand:

  • class-editor-sidebar.php — the Content Intelligence Editor Sidebar
  • class-dashboard-widget.php
  • class-post-list-stats.php
  • class-recommended-widget.php
  • the dashboard page and telemetry scripts

None of them follow their wp_enqueue_script() with a wp_set_script_translations().

PHP strings are unaffected — those load normally.

To Reproduce

  1. Set the site language to any locale with a wp-parsely translation.
  2. Open the Post Editor and expand the Parse.ly sidebar.
  3. Every label, button and message is in English, while the surrounding WordPress UI is translated.

Expected behavior

Strings marked translatable are translated. For a wp.org-distributed plugin this needs no build step and no .pot in the repository — WordPress downloads the JSON from translate.wordpress.org, and each enqueued handle needs:

wp_set_script_translations( static::get_script_id(), 'wp-parsely' );

If translating the JavaScript UI is deliberately not a goal, the opposite is worth doing: the __() wrappers are misleading as they stand, since they imply a translation path that does not exist.

Environment

  • wp-parsely 3.23.7 and earlier

Additional context

This is the mechanism behind #4546. The tone and persona labels were always marked translatable, but lived in JavaScript where translation is inert, so they were always English in practice. #4492 makes PHP the source of that vocabulary, where translation does work — which is what turned Formal into Formell and made a long-dormant inconsistency suddenly depend on the site's locale.

Lingua principale
PHP
Stelle
67
Fork
38
Merge medio
1g 5h
PR unite (30g)
79

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Parsely/wp-parsely

Tutte le issue di Parsely/wp-parsely

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.