Home Forums General Issues Checkboxes with qTranslate-X


Checkboxes with qTranslate-X

  • Hi,

    I have a bilingual website that lists vehicles for sale. I am using ACF on a custom post type (Cars) for this.

    All fields are great and can be translated (with qTranslate), but I am struggling with adding translated options to Checkboxes.

    An example of list current list of options in my checkbox field include:

    Air Conditioning : Air Conditioning
    Climate Control : Climate Control
    Auto Park Assist : Parking Assist

    I’m wondering if the following would be possible?

    [:en]Air Conditioning : Air Conditioning[:cy]Other Language : Other Language

    Or is there something I could do like (excuse the pseudocode)…

    if get_field('checkboxCarFeatures' == 'Air Conditioning') show this...

    That last way I could wrap between language tags in the code, which I know is messy.

    Many thanks in advance.

  • Not easy but not imposible, i´m familiar with QTranslateX, i can provide you with just the basics and then you need to find they way to make it work better, for example, you must use the same key and different values (translated), not the way you tryied, so, this:

    Air Conditioning : Air Conditioning

    It´s wrong, because, first, key should be something like “air-coditioning”, this is the key you will later use on front-end to get the value.

    In order to make it traslateable, then write this:

    air-coditioning : [:en]Air Conditioning[:es]Aire Acondicionado

    At that point you will see, on admin side, this on the select option value:

    [:en]Air Conditioning[:es]Aire Acondicionado

    So, let´s make qTranslate available for that, this way, in your functions.php add something like (if your field name is “checkboxCarFeatures”):

    function acf_custom_select_qtrans_fx( $field ) { 
    	global $q_config; 
    	$field = qtranxf_use($q_config['language'], $field, false, false); 
    	return $field;	 

    Little explanation.

    The global $q_config var is a qtranslate global var already defined with plugin, the qtranxf_use function is also a plugin function. So, you should code this with some conditionals to see if qtranslate is installed, in your hands that part 🙂

    The acf load field filter just use in this case the name (checkboxCarFeatures), once that field is loaded it will execute the function acf_custom_select_qtrans_fx that only takes the $field and apply the qtranxf_use functions that makes those [lang:] tags to work.

    Ok, that´s easy right? But, take in consideration this will only works once you load a page in some lang, not when switching with the lang switcher buttons, qtranslate has the option to not load admin page once you switch, if using this, option select will not change the lang, for that you will need more code using some js to make that to happen, that´s is, triggering the lang switch some way to apply the filter on those select options, by default it will not change. Try it and you will notice what i mean. I didn´t get deep into that, but qtranslate has js hooks and functions that can do that, i guess; like: qTranslateConfig.qtx.addContentHookC(field, form); Make a resear and sure you will find how to make switch buttons to change translated texts on those selects.

    On the front-end, once you take the value, if it´s not translated and you see the [lang:] tags, is just to apply same filter logic using qtranxf_use() function for example.

    Good luck

  • This has just stopped working on our multilingual directory.
    Does anyone have any idea how to get this going again?

    WP 4.8.5
    ACF 5.6.3

    Any help would be much appreciated.

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

The topic ‘Checkboxes with qTranslate-X’ is closed to new replies.