Making WordPress.org

Opened 3 years ago

Closed 3 years ago

#6270 closed defect (bug) (worksforme)

Translated text specified in JavaScript is not translated

Reported by: shimotomoki's profile shimotomoki Owned by:
Milestone: Priority: normal
Component: Translate Site & Plugins Keywords:
Cc:

Description

The following plugins are hosted on WordPress.org.

Plugin Directory
https://wordpress.org/plugins/vk-block-patterns/
Source Code
https://github.com/vektor-inc/vk-block-patterns

I am having trouble getting my JavaScript translated text to translate.

Translating WordPress contains the text translated by JavaScript.
(This is an example of Japanese)
https://translate.wordpress.org/projects/wp-plugins/vk-block-patterns/dev/ja/default/

However, when I install the plugin and set the language to Japanese, the translation is not done.

Is this a problem with the plugin code?
Or is there a problem with the WordPress.org translation (GlotPress) ?

Change History (4)

#1 @kittmedia
3 years ago

According to the Block Editor Handbook (https://developer.wordpress.org/block-editor/how-to-guides/internationalization/) you need to use wp_set_script_translations() (https://developer.wordpress.org/reference/functions/wp_set_script_translations/) so that the translations are loaded.

Edit: Sorry, the GitHub search is sometimes a little bit buggy … I couldn’t find your wp_set_script_translations in the first try.

Last edited 3 years ago by kittmedia (previous) (diff)

#2 @ocean90
3 years ago

I think it will work if you move this line directly below your wp_enqueue_script() line here.

#3 @shimotomoki
3 years ago

@kittmedia
@ocean90
Thanks for the comment.

I took @ocean90's advice and fixed where wp_set_script_translations runs and the translations worked!
Thanks!

#4 @ocean90
3 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Glad to hear it's working now.

Note: See TracTickets for help on using tickets.