Localization of editor strings

I have followed the documentation and the localization works perfectly in the front but not in the editor.

For example, when declaring ACF:

->addRepeater('hero_slide', [
    'button_label' => __('Add slide', 'sage')

Even choosing the language of the site and the language of the user to match the translation, the strings are displayed untranslated.

Has anyone used localization in the editor with Sage 10?

You mean the translation in the Gutenberg editor?
The translation has to be provided as JSON, which can be built from the Gettext files:

Not in the block editor, just in the editor. For example, in the options page built with ACF builder I have some strings like this:

'button_label' => __('Añadir slide', 'sage')

Then, these strings are translated with the .po and .mo files in resources/lang directory.

Then, the option page remains untranslated to english:

The strange thing is that all strings in the front are succesfully translated with the same en_US.mo file, so, the file is working. The only strings that fail are in the editor.

:thinking: Maybe the translation domain is added too late?
after_setup_theme where the translation domain is added may run after acf/init where the builder is applied.

1 Like

I tried with mu_plugin_loaded that is previous to init and acf/init with no luck. :upside_down_face:

Anyway, after_setup_theme is before init and acf/init.

Some quick debugging here:

var_dump(__('Añadir slide', 'sage'));

(Where you are using it.)
Does this output the source string?

  • Are you using proper encoding of the text file (UTF-8)?
  • Does the translation file (also the compiled MO one) contain that source string?
  • Is the translation domain actually sage?
1 Like


var_dump(__('Añadir slide', 'sage'));  // render -> String(13)"Añadir slide"
echo __('Añadir slide', 'sage');       // render -> String(13)"Añadir slide"

in a page (blade) template

@dump(__('Añadir slide', 'sage'));    // render -> "Add slide"
{{ __('Añadir slide', 'sage') }}      // render -> "Add slide"

Is the same. It works in a blade template, it doesn’t work inside an app PHP file.

Translation domain is ‘sage’ and the .po and .mo files contains the string (otherwise it shouldn’t work in a blade template).

I have WPML installed, but it is deactivated for now to avoid interference.