Home Forums Backend Issues (wp-admin) Localizing texts when adding fields via theme


Localizing texts when adding fields via theme

  • Hi,

    Thank you very much for this great plugin! This is my first experience with it and I have a question regardless localization of the fields set up via WordPress theme.

    I’m using a PHP code generated by the Advanced Custom Fields (ACF) plugin’s export feature in my theme’s functions.php file. Surely the code does not include the WordPress localization functions.

    So I’ve added esc_html__() to all the texts where required (I’ve used theme-slug as text domain, which is set up in theme’s style.css file and I am using it throghout the whole theme). I than used Poedit to translate the theme’s text into Slovak language.

    But once I switch the language of my WordPress, the fields created with ACF and the code I’ve putted into my theme, are still in English.

    Is this a known issue? Can I fix it? Or do I need to use a WPML to translate that? If so, do you support Polylang plugin too?



  • The only thing I can think of is, did you load the text domain?

  • Hi,

    I’m actually using load_theme_textdomain() in the theme.

    I’ve tried to copy the code into TwentyFifteen’s functions.php file and adapted the text domain and translated the POT file (created PO and MO files). The TwentyFifteen also uses load_theme_textdomain().

    Can you try yourself please?



  • No, I can’t really try it. I’d need to set up a WP site using your theme and all of the custom fields from your theme. I was just trying to point out something that you may have missed. This forum is really meant for questions about ACF and while you’re using ACF to create your fields this is not really an ACF question, it’s more of a WP translation question. You’d probably get better help from somewhere from users that have experience with setting up translations.

    Here are some pages I found on this:

  • Hi,

    Believe me, I have A LOT of experience setting WordPress translation as I am not English native speaker myself.

    The issue seems to be related to how your plugin processes the array as I have never had similar issue before.

    I will set a file for you to try with TwentyFifteen. (I think I’ve explained the issue well, anyway).

    I will also give you better link for WP translations:



  • I’ve only done translations on a limited basis and always followed examples of what others do. It might be better to see the array that you’re using for creating the field group and how you’ve added the translation function.

    For example, this is part of fields of one field group that I’ve added translations for in the past. The main difference is that I’m not using esc_html__() and instead I’m just using __()

    $field_group = array(
    'key' => 'acf_options-page-details',
    'title' => __('Options Page Details', $this->text_domain),
    'fields' => array(
        'key' => 'field_acf_key_acfop_message',
        'label' => __('Options Page Message', $this->text_domain),
        'name' => '',
        'prefix' => '',
        'type' => 'message',
        'instructions' => '',
        'required' => 0,
        'conditional_logic' => 0,
        'message' => __('Title above is the title that will appear on the page. Enter other details as needed.<br />For more information see the ACF documentation for <a href="" target="_blank">acf_add_options_page()</a> and <a href="" target="_blank">acf_add_options_sub_page()</a>.', $this->text_domain)
        'key' => 'field_acf_key_acfop_menu',
        'label' => __('Menu Text', $this->text_domain),
        'name' => '_acfop_menu',
        'prefix' => '',
        'type' => 'text',
        'instructions' => __('Will default to title if left blank.', $this->text_domain),
        'required' => 0,
        'conditional_logic' => 0,
        'default_value' => '',
        'placeholder' => '',
        'prepend' => '',
        'append' => '',
        'maxlength' => '',
        'readonly' => 0,
        'disabled' => 0
      // field group continues .......
  • Hi,

    It doesn’t really matter if you are using esc_html__() or __() in this case.

    I’ve created a new theme from TwentyFifteen for you (the only things I’ve changed is the theme folder name, theme name in stylesheet and I’ve added the code at the end of the functions.php file – have a look). Download the theme from

    How to test:

    1. Download the theme and install it. Activate it. It’s named “Twenty Fifteen FOR ACF LOCALIZATION TESTING”.
    2. Install the plugin and activate it.
    3. Add a new post/page or edit existing one to see how it looks now (I presume you are using WordPress in US English, which is default).
    4. Go to Settings > General and at the bottom set the “Site Language” to “English (UK)”.
    5. Check the post/page edit page in admin again. You will see the reference text has been translated but the metabox hasn’t ( ).

    Hope this will help you to trace the issue (could it be in the hook priority you are using in the plugin maybe?).



  • I discovered the problem.

    Rather than what you have in functions php to this.

    add_action('init', 'load_my_acf_field_group');
    function load_my_acf_field_group() {
      if (function_exists('register_field_group')) {
        // register your field group

    The problem is that loading of the text domain does not happen until after function.php is loaded so the translation does not exist when the field group is being created.

  • Thank you John! This solved my problem indeed.

    I suggest adding this into the export code the plugin produces.



  • I’m not a developer for this plugin, just another user that helps by answering questions here. The reason that I realized what was needed was basically because I create plugins using ACF and you need to do all of the adding of fields onthe init hook because ACF may not be loaded yet when another plugin is loaded.

    I assume that the export is for what most people will be doing and what will work for them most of the time.

  • Sorry, I thought you were related to ACF in more internal way.

    What is the best way to suggest this being included in the plugins export then?

  • I’m only related to it as far as the forum goes. I’m just slightly more than most of the people that visit here. I will mark this thread for the developer’s attention, that’s about the best that can be done.

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

The topic ‘Localizing texts when adding fields via theme’ is closed to new replies.