Support » Plugin: qTranslate extension » [Plugin: qTranslate extension] Translation with Advanced Custom Fields

  • I have found a problem when trying to get this to work with Advanced Custom Fields, both the 2.* and 3.* versions.

    The problem is that qTranslate extension doesn’t escape things correctly so when it tries to find stuff with rel=[] it bugs out on the id’s from Advanced Custom Fields that uses [].

    I used a function like this:

    function jq(myid) {
    	return myid.replace(/(\[|\]|:|\.)/g,'\\$1');
    }

    added to qtranslate-extended.php and then changed some “e.attr(‘id’)” to “jq(e.attr(‘id’))” on lines about 149 and on to make it recognize them and work as intended.

    So far i managed to get it to show and to work with languages but not to save, as i think it doesn’t update the correct fields and field ID’s to enable wordpress to save them the right way.

    I’ll keep working on it and see if i can figure out the last parts but f anybody else manages to get this to work 100% i would greatly appreciate it.

    Hope my work so far helps somebody else out and thanks in advance

    http://wordpress.org/extend/plugins/qtranslate-extended/

Viewing 15 replies - 1 through 15 (of 20 total)
  • yashiharu

    (@yashiharu)

    hi strop.
    it seems you are familiar with this plugin.

    I have added the class “multilanguage-input” to all the elements & the flags appeared on the back-end.

    But the system won’t selected the suitable language on the front-end, just show both.

    Do not forget to apply the filters [apply_filters(key, content)] before show teh content.

    I don’t understand what it means, could you please kindly give me some help on it?

    Plugin Author Fractalia

    (@786pe)

    Hi strop:

    Thanks for use this plugin. We are working to fux this bug soon. If you have some other information please tell us.

    strop

    (@strop)

    Yeah i managed to get it to save aswell. Had to change the prepareMultilanguageData function to something like this:

    function prepareMultilanguageData(form){
    	form.find('.multilanguage-input').each(function(i, e){
    		content = '';
    		for(i=0; i < languages.length; i++){
    			var tmpId = jQuery(e).attr('id');
    			val = jQuery('div[rel='+jq(tmpId)+']').find('#'+languages[i]+'_'+jq(tmpId)).val();
    			if(jQuery.trim(val) != ''){
    				content += '<!--:'+languages[i]+'-->'+val+'<!--:-->';
    			}
    		}
    		jQuery(e).val(content);
    	});
    }

    Hi strop, your solution looks promising, can you tell me exactly where you replaced the e.attr(‘id’) with jq(e.attr(‘id’)) in the qtranslate-extended.php ?, I have tried your indications but I cant seem to make it work in the media edit section of wordpress.

    Thanks in advance…

    The latest version (0.1.1) adds all the changes i made to the core of the plugin so it should no longer be needed.

    What kind of problems are you having?

    Thanks, I think I had some older version of the plugin, I’m trying to add the class multilanguage-input to the image attachment edit screen via a jquery selector.

    Right now I managed to make the post title and post excerpt (Title and Legend in the media editor) but with the Alt field it’s not working, it just takes the text from the multiple language input and when I save it all the translations merge into the same field.

    ┬┐Could you give me a hand with this problem?

    I think I have a similar question. Did any of you solve this problem?

    Is it possible to change <?php echo get_post_meta($post->ID, 'Description', true); ?> to make it conditional, given that WP doesn’t recognise any shortcode?

    I could happily make two custom fieds for each language (Description_en and Description_de for example, but how can I make the get_post_meta only show the right one (for the language that is currently selected by the user)?

    Any help greatly appreciated. It would rescue me and put an end to days of searching and trying things out.

    Hey Kaspar, I’m hard at work with Qtranslate and a website I’m making so I created some functions for custom alt and title in all of the media fields, I also managed to hack the image output so I can retrieve the alt and title when I call post thumbnail and stufff.

    You can see my code that adds extra fields for different things in the media upload window and also in the media edition section. I have tried it and it works nice. You can put the language tags you want.

    Maybe if I have the time I can change it later and turn it into a plugin, but since you are in a hurry you can put this stuff in functions.php and see what happens.

    here is the code, hope it’s some use to you.

    http://pastebin.com/YXqCk7KA

    thanks, I hope I can understand it! Where would I paste it in functions (I guess it doesn’t matter), and would it help me call post meta/custom fields in the loop (or elswhere), or is it more for media? Or do you mean custom fields for media fields?
    Speak soon and thanks again for the quick reply,
    K

    you can put it at the end of functions.php or in an included file, notice that this thing is made for 4 languages so you can add/remove the fields for each language…

    Seen that thanks. But it seems to be mainly about media and adding alt info in different languages – which is also good – but no so much for custom fields and the <?php echo get_post_meta($post->ID, 'Description', true); ?> function
    K

    good work though!

    oh, if you use the plugin qtranslate extension and you need to output the correct language you just have to echo the field with _e instead of echo like this

    _e(get_post_meta($post->ID, 'Description', true);

    If you want to create different fields for different languages then you can combine the variable of the current language with the name of the field like this:

    $currlang = qtrans_getLanguage();
    echo get_post_meta($post->ID, 'Description_'.$currlang, true);

    Given that you have custom fields called like ‘Description_en’, or ‘Description_de’

    I tried this but got an error message. Maybe I did it wrong.

    <?php _e(get_post_meta($post->ID, 'Description', true); ?> function

    or just

    <?php _e(get_post_meta($post->ID, 'Description', true); ?>

    or something else?

    and do I need to do anything else or is it enough to have the plugin installed?

    [Moderator Note: Please post code or markup snippets between backticks or use the code button.]

    my bad, I forgot to put an extra parenthesis

    it’s like this:

    <?php _e(get_post_meta($post->ID, 'Description', true)); ?>

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Plugin: qTranslate extension] Translation with Advanced Custom Fields’ is closed to new replies.