Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am running the newest WordPress and qTranslate. I have made a page that enables some custom fields that are working ok.

qTranslate enables languages like tabs when editing a page. But this doesn't happens in my custom meta fields. Any way of making language control on these fields?

It would be great if there were some Javascript event listener that would tell me that the user changed the language tab or something.

I read about putting like

<!--:ca-->CA<!--:--><!--:es-->ES<!--:--><!--:en-->EN<!--:-->

inside the meta field but since this is going to be used by an end user, and I am sure they wouldn't understand what that means and how to use it. I need different meta field for different languages. Any ideas?

Secondly I am trying this:

<?php _e('Published ', 'iris'); ?>

But when I change the page language (qTranslate ?lang=dk / ?lang=en) it never translates the word. It always stays in English somehow. I tried this and this works:

<?php echo _e("<!--:dk-->Udgivet<!--:en-->Published"); ?>

But it doesn't really use the language library and I was hoping there was a way :)

share|improve this question
    
IMO, the second question about _e('Published', 'iris') should be a new Question... –  brasofilo Jul 21 '12 at 19:06
add comment

1 Answer

up vote 1 down vote accepted

Less complicated is to use the plugin's Quicktags and use the Gettext functions to print the content in the site.
[:en]English[:pt]Português Quicktags docs


Another option is to do just like qTranslate interface does with the post titles:
qtrans titles


Create one custom field for each language in your meta box:
custom meta box with custom fields


qTrans documentation is not consolidated, so analyzing the code can be handy:
http://plugins.svn.wordpress.org/qtranslate/trunk/qtranslate_utils.php
The function qtrans_getSortedLanguages returns an array with the site languages:

array(
  [0] => 'es'
  [1] => 'en'
  [2] => 'nl'
  [3] => 'fr'
  [4] => 'de'
)

This can be used to insert jQuery elements that will control the visibility of existing ones. The following is just a prof of concept and has to be adapted as desired.

The result is a checkbox inside the Page Attributes meta box that will show/hide the button Preview inside the Publish metabox.
jquery wp manipulation

Code for the previous snapshot:

/**
 * Inject jQuery Button to Control Some Element(s) Visibility
 */
add_action( 'admin_footer-post.php', 'wpse_59056_inject_visibility_checkbox' );

function wpse_59056_inject_visibility_checkbox() 
{
    global $current_screen;

    // If not a Page, do nothing
    if ( 
        'page' != $current_screen->id 
        ) 
        return; 

    ?>
    <script type="text/javascript">
    jQuery(document).ready( function($) 
    {
            // Define the Checkbox
            var radioBtn = $('<input type="checkbox" name="rbtnCount" id="rbtnCount" /><label for="rbtnCount"> My Box Visibility</label>');

            // Append to the Page Attributes meta box
            radioBtn.appendTo('#pageparentdiv .inside');

            // Mark it as checked
            $('#rbtnCount').attr('checked', true);

            // Watch its behavior
            $('#rbtnCount').change( function () 
            {       
                // Show/Hide the "Preview" button inside the Publish meta box   
                if( $(this).is(':checked') )
                {
                    $('#preview-action').show();
                }
                else
                {
                    $('#preview-action').hide();
                }
            });
        });
    </script>
    <?php
}

* With the help of StackOverflow Create dynamically radio button in jquery

share|improve this answer
    
Yes I thought about that... but again from a users perspective its confusing that the main content box have tabs for language selection and the meta boxes below are duplicated pr. language enabled. –  Ronnie Jespersen Jul 19 '12 at 19:19
    
Ain't the Title duplicated as well?? Or QinQian changed that? –  brasofilo Jul 19 '12 at 19:24
    
Say what? What title? –  Ronnie Jespersen Jul 20 '12 at 22:55
    
Are your Custom Fields built within a Meta Box? Or are they regular ones? This is a snapshot of a post editing (titles and content). And this one of a custom MB holding CF's. –  brasofilo Jul 20 '12 at 23:05
    
Oh ye they are custom... but I see your point... the default titles are duplicates as well.. I guess the way to go is simply to make the meta boxes for each language... is there any way to get all the languages that are activated in qTrans? So I could loop them... –  Ronnie Jespersen Jul 20 '12 at 23:17
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.