WordPress.org

Ready to get started?Download WordPress

Forums

qTranslate extension
Translation with Advanced Custom Fields (21 posts)

  1. strop
    Member
    Posted 2 years ago #

    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/

  2. yashiharu
    Member
    Posted 2 years ago #

    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?

  3. Fractalia
    Member
    Plugin Author

    Posted 2 years ago #

    Hi strop:

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

  4. strop
    Member
    Posted 2 years ago #

    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);
    	});
    }
  5. pabloselin
    Member
    Posted 2 years ago #

    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...

  6. strop
    Member
    Posted 2 years ago #

    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?

  7. pabloselin
    Member
    Posted 2 years ago #

    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?

  8. kaspar wimberley
    Member
    Posted 2 years ago #

    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.

  9. pabloselin
    Member
    Posted 2 years ago #

    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

  10. kaspar wimberley
    Member
    Posted 2 years ago #

    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

  11. pabloselin
    Member
    Posted 2 years ago #

    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...

  12. kaspar wimberley
    Member
    Posted 2 years ago #

    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

  13. kaspar wimberley
    Member
    Posted 2 years ago #

    good work though!

  14. pabloselin
    Member
    Posted 2 years ago #

    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'

  15. kaspar wimberley
    Member
    Posted 2 years ago #

    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.]

  16. pabloselin
    Member
    Posted 2 years ago #

    my bad, I forgot to put an extra parenthesis

    it's like this:

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

  17. kaspar wimberley
    Member
    Posted 2 years ago #


  18. kaspar wimberley
    Member
    Posted 2 years ago #

    On first glance it works! You are a star. Thanks!
    K

  19. grumo64
    Member
    Posted 2 years ago #

    Hey jhonqwerty,

    your function works like a charm except if you click on "insert into post" button :(

    Can you help me please ?

  20. pabloselin
    Member
    Posted 2 years ago #

    @grumo64, sadly I haven't been able to fix that problem yet, I know that I have to filter somehow the tinyMCE insertion but I haven't researched too much yet. Probably I will have to deal with that problem later so if I manage to find a solution I will post it here... but don't expect it too soon.

  21. Mr. Spiderman
    Member
    Posted 2 years ago #

    Hey,

    I'm trying to convert some advanced custom fields to multilanguage and I don't know how to do it. I added the class multilanguage-input and the field disappears. What I'm doing wrong? Thank you in advance.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic