qTranslate-Team / qtranslate-x

Wordpress plugin: Adds user-friendly and database-friendly multilingual content management and translation support.
http://qtranslatexteam.wordpress.com/about/
GNU General Public License v3.0
206 stars 149 forks source link

Some fields should not be translated by the JS #61

Open soft79 opened 9 years ago

soft79 commented 9 years ago

Creating a filter to exclude certain fields from the JS translation buttons would be very useful.

Please see https://github.com/josk79/qtranslate-x/pull/1

This adds an option to the admin page that allows for CSS-selectors for DOM-elements that should not be translated.

This branch also applies a filter before passing the config to JavaScript. This way plugins can add certain filters. For example: "WooCommerce qTranslate X" should add body.post-type-shop_coupon #title because coupon titles shouldn't be translated as it breaks functionality.

soft79 commented 9 years ago

Example of the filter hook:

//Don't translate WooCommerce coupon title
add_filter('qtranxf_get_js_config', function($config) { 
    $config['excluded_field_selectors'][] = "body.post-type-shop_coupon #title";
    return $config;
} );
johnclause commented 9 years ago

Hi @josk79, Why do we need to exclude something if we can not to include it to begin with? Which page/field this exclusion applies to?

soft79 commented 9 years ago

In this case the title field of a post with type shop_coupon .

If a user enters a coupon code in WooCommerce, the coupon is looked up by a SELECT * FROM $wp->db->posts WHERE title = %s query

There is a filter to alter this query, but the title is not passed as an argument, so it would be hard to fix it this way, that's way I came up with the exclude filter. might be useful for other custom post types as well..

johnclause commented 9 years ago

If there was no a problem, would you want to make coupon translatable?

johnclause commented 9 years ago

BTW, @josk79, if you set the same value for all languages, then language tags should be removed. This trick should enable you to keep going until we figure out the best way to solve this problem.

soft79 commented 9 years ago

For me a coupon title doesn't need to be translatable, only it's excerpt. I'll try the workaround tonight.

soft79 commented 9 years ago

Workaround seems to work. Sometimes the solutions can be so simple... :)

mweimerskirch commented 9 years ago

I like the idea of being able to add exceptions. We use lots of custom post types for all sorts of data. Some of them do not require the title field to be translatable. Being able to add exceptions via hooks would be really helpful in these cases.

realtebo commented 7 years ago

I've the same need, in our specific situation we need to avoid to make translatable the post title for a custom post type.

I need a workaround

lmartins commented 7 years ago

Also looking for a solution to this, any progress on this since last year?

jbvidex commented 6 years ago

+1 I have a custom post type for which I do not want the title field (part numbers, in our case) to be translated. The language tags are messing up my Next/Previous post navigation links. :(