Home Forums General Issues Checkboxes with qTranslate-X Reply To: Checkboxes with qTranslate-X

  • 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