Custom fields translation using qTranslate X


Hey, I'm trying to translate my website to other languages by qTranslateX plugin.

While it's really easy to use with pages, posts and widgets, I don't have a clue how to designate translations to custom fields.

I also want to have statement in functions.php which checks selected language. Can I do it by checking url (when translated it should contain "en") - how? Or maybe other method?

Regards, Mariusz


Hey Mariusz,

I don't know this plugin but I made a quick Google search and it seems like you can set your languages as below in a textarea for example:

[:en]English Text[:]
[:de]German Text[:]

This isn't specific to Beans and you can perhaps make more research and find a cleaner way to do it (share if you do please). If other ways require some change in the way fields are rendered, Beans backend is as flexible as the frontend so you can modify the Fields HTML as you need.

Hope that helps,


I used that approach before, but I wanted to add tabs for custom fields, like qtranslate do with pages, post etc. It could be possible if every custom fields would have class or id. I tried with class (i added class name in qtranslate configuration), but it doesn't work.

I don't know yet how to change sometging in backend so I leave custom fields as they were, and fill them with language selectors like described above.

One thing I can share is how to check which language is currently selected in php file:

if (qtranxf_getLanguage() == 'en') {
    beans_add_attribute( 'beans_body', 'class', 'en');
}

Note that in older versions of qtranslate there was other function to get current language - qtrans_getLanguage() and this is what you find in many WP Support topics. If you are using new qtranslate X plugin, you have to use qtranxf_getLanguage() function instead.


Hey Mariusz,

It could be possible if every custom fields would have class or id.

I am not entirely sure what your mean by that. What HTML would you like to add attributes to?

Thanks,



Hey Mariusz,

Alright I see

However, you may enter “id” or “class” name attribute of those fields into “Custom Fields” section of “Languages” configuration page in “Settings”

Beans doesn't output id by default but it works like the front end so you can add it yourselt. When you register your field, you can add an attributes parameter which allows you to add any HTML attributes. Here is an example field:

$fields = array(
     array(
        'id' => 'example_field_id',
        'label' => __( 'Example Field Label', 'example-domain' ),
        'type' => 'text',
        'default' => __( 'Example Default', 'example-domain' ),
        'attributes' => array( 'id' => 'example-id' )
    ),
    // Other fields...
);

Take note of the attributes parameter to add an HTML id attribute.

Once you have added your id to your fields, then you can go and register it in the plugin as quoted above I guess. I do not know this plugin (and didn't test it) but this is my take on it according to what I read.

Happy coding,

Write a reply

Login or register to write a reply, it's free!