Support

Account

Home Forums Backend Issues (wp-admin) Multilingual field labels

Solved

Multilingual field labels

  • I develop multilingual sites for multilingual editors: primarily German and French speakers. I love the ACF plugin and its add-ons, but there is one slight issue: how to create multilingual labels for the backend.

    An example. I create a field called “Project title” in the backend which receives the field key “project_title”. The key is used for saving the data and for showing it on the website. All good there.

    On my website, I can use POEdit to ensure that the field labels are displayed in the language appropriate to the user’s browser.

    What I need to be able to do, though, is have the field label in the backend show “Projekttitel” for (e.g.) German-speaking editors. For English-speaking editors, the label must remain “Project title”.

    Is this possible? Can I achieve this directly? Do I need to work with PoEdit files? (I’m already handling the multilingual environment, no issue there.)

  • Hi @Mark Howells-Mead | mhm.li

    Currently, ACF deos not translate the label value in the wp-admin area.

    You could get around this by hooking into the load_field filter (please see docs for more info) and set the $field’s label to itself using the WP translate function like so:

    
    $field['label'] = __($field['label']);
    

    I’ll add this to the to-do as it should be part of the core.

    Thanks
    E

  • Thanks Elliott; that works a treat for the top-level fields. There doesn’t appear to be a filter hook for all elements; e.g. sub_fields. Have I overseen something?

    Do you foresee an ongoing requirement to handle multilingual issues like this via gettext functions and external .po / .mo files?

  • Hi @Mark Howells-Mead | mhm.li

    your right, hmmm. Perhaps instead of the load_field filter, you can use the ‘acf/load_field_defaults’ filter instead.

    Looking at the repeater add-on, this filter is used on all sub fields so it should fix the issue for you.

    Thanks
    E

  • Thanks for the suggestion. I’ll give it a try and respond with feedback in a few days’ time.

  • Working well, thanks for the tip. Thanks Elliot. I could do with exactly the same filter on $field[‘layouts’], placeholders and so on too, so that I can translate all of the text which can be defined by the BE user.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Multilingual field labels’ is closed to new replies.