qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
553 stars 104 forks source link

Language switcher not available on ACF Option Page #1386

Open fintinc opened 11 months ago

fintinc commented 11 months ago

Since the ACF extra qTranslate fields are deprecated the ACF Option Page would need language switch buttons to see other languages than the standard language:

image

I fixed it quickly by adding a ACF Message field with the language switch buttons html code:

image image
herrvigg commented 11 months ago

I don't manage to reproduce and I don't understand what you mean with "ACF Message field", what is that? Please give a very concise example to reproduce, by explaining very precisely which fields you select and how you create the option page.

fintinc commented 11 months ago

Hello and thanks for looking into this. I try to explain more precisely:

  1. I created an Option Page in PHP like this: if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( 'page_title' => 'Beiträge Einstellungen', 'menu_title' => 'Beiträge Einstellungen', 'menu_slug' => 'posts-settings', )); }
  2. I set up a ACF "repeater field" to appear on this Option Page. The repeater field has simple text fields and an URL field.
  3. Now on this Option Page it is not possible to switch the text fields to other languages to see and use them. Only the main language is visible even if I switch to another language using the main switch in the black admin bar on top of the browser window.
  4. By inspecting the code, I see that the input fields of the other languages are there but they are always hidden.
  5. So I thought this page would just need language switch buttons like there are when editing posts or pages .
  6. I went to a normal WordPress Page and copied the code of the qtranslate language switch buttons.
  7. On the Option Page I added a new ACF field with the the type of "Message". This field allows to add a message or html code to be visible in the UI of the backend.
  8. I just use this field to paste the code of the language switch buttons I copied from the normal WP page to be rendered as buttons on the Option Page.
  9. Now I can use these buttons to switch the text fields to other languages.

I guess the solution would be, if you could integrate the language switch buttons on the option page. In earlier versions (link 3.13.x) there was also no language switch buttons on the ACF Option Page, but the visibility of the different language fields changed according to the main language of the backend. e.g. if I changed to french using the main language switcher in the wp admin bar, the french input fields would be visible. This is not the case anymore in version 3.15.x.

lloydud commented 10 months ago

Hello there,

Id thought id share my solution, just put the code in your theme functions.php.

Find your acf field id replacing field_60d9a9a5def77 in the below code. Then find the options page name in the url /wp-admin/admin.php?page=your_options_page_name and update the conditional:

add_action( 'admin_head', 'enable_qt_language_switcher_for_acf');
function enable_qt_language_switcher_for_acf(){
    if (isset($_GET['page']) && 'your_options_page_name' == $_GET['page']) { ?>
        <script>
            acf.getField('field_60d9a9a5def77').addAction('ready', function(){
                qTranslateConfig.js.get_qtx().setupLanguageSwitch();
            });
        </script>
   <?php }
}

Regards