QTranslate for Custom Post Type [closed]

Using tags is pretty straightforward. All data in qTranslate is stored between special <!--:lang-->content<!--:--> tags, wherein lang is the code for the language, like en, ru, de, etc.

The post edit UI is altered via qTranslate’s heavy JavaScript. The JavaScript parses the content for preset fields and creates new controls. Before saving the same JavaScript does the opposite, merges the UI fields and wraps them up into the tags above. This simple behavior can be replicated by injecting additional JavaScript from your custom post type code to split your custom field into as many languages as you need, then merge them together, using qtrans_integrate_*, qtrans_save and other existing odds and ends as a guide for your own code.

Again, this is very straightforward – split tags in your #portfolio_project_roles, for each language create #portfolio_project_roles_{lang} textareas and fill with split content, before saving merge back into one #portfolio_project_roles wrapping each content language payload into the tags.

When saved, your custom post type metadata in your database would look like this, for example: "portfolio_roles" => "<!--:en-->Vladimir - Project Lead<!--:--><!--:ru-->Владимир - куратор проекта<!--:-->". To display chunks of this data depending on the language, you have to use a couple of filters qTranslate provides, mainly: qtrans_useCurrentLanguageIfNotFoundShowAvailable and the like, or even qtrans_use directly.

<div id="content>
    <?php echo qtrans_useCurrentLanguageIfNotFoundShowAvailable(
                get_post_meta( get_the_ID(), 'portfolio_roles', true ) ) );
    ?>
</div>

This will output the correct language split payload (don’t forget to escape the output using esc_html).

A cleaner approach would be to use the meta filter and hook it over the qtrans_use* functions. I’m sure there are other interesting approaches that can be taken, but the above should provide you with the basic outline of how things work. Hope this helps.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)