Support » Plugin: Loco Translate » Retrieve translatable strings from Gutenberg blocks?

  • Resolved Chris

    (@camthor)


    Hi,

    Can this plugin collect strings from Gutenberg blocks where I define

    const { __ } = wp.i18n

    and then use

    __( 'Translate me!' ) ? Or is it planned?

    Thanks!

Viewing 5 replies - 16 through 20 (of 20 total)
  • Hi Tim –

    Any news on Gutenberg compatibility? We’re implementing some Gutenberg blocks right now and Loco Translate would be a big helper …

    best from Salzburg!

    – Johannes

    Plugin Author Tim W

    (@timwhitlock)

    @jarot

    I’m aware that Gutenberg in Core is imminent, but I’ve not had time to build a JSX parser as discussed on the first page of this topic.

    The last time I checked – the ludicrously complex process of building a Gutenberg plugin involved the generation of a PHP file containing translatable strings. This is (or was) how GlotPress were handling Gutenberg translations. If that’s changed, please let me know. Until then it’s up to plugin authors to produce compatible translation templates for their plugin.

    I will take another look at this soon, but I am somewhat busy with the main Loco website.

    Plugin Author Tim W

    (@timwhitlock)

    UPDATE: I’ve added JavaScript string extraction to the development version (2.1.6-dev)

    To use it, open Loco Translate settings and add “js” (or jsx or whatever) to the new text field where it says “Scan JavaScript files with extensions:”.

    This supports WordPress l10n functions in regular JavaScript. This means that any such function calls in JSX should also work. The theory being that only the syntax of the function call is scanned and from what I’ve seen so far, this is the same as vanilla JS.

    As I’m not a React/Gutenberg developer, I know little about what needs supporting here in terms of special syntax, so please let me know what’s missing.

    Notes:

    1. As with PHP – function calls require a domain literal like __(‘foo’,’mydomain’). When this is omitted it’s the same as doing __(‘foo’,’default’). The same workaround applies, which is to set “*” as the bundle’s text domain to force extraction of all strings into the bundle’s domain.

    2. Although Gettext PO files support a javascript-format tag, this is not currently checked I’m unsure what syntax should be supported.

    Thank you very much, I will try it later.

    Plugin Author Tim W

    (@timwhitlock)

    Thanks. This is now live in 2.2.0, so you don’t need to install the dev version.

    Also javascript-format is now supported using the syntax of sprintf-js

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Retrieve translatable strings from Gutenberg blocks?’ is closed to new replies.