Open soft79 opened 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;
} );
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?
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..
If there was no a problem, would you want to make coupon translatable?
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.
For me a coupon title doesn't need to be translatable, only it's excerpt. I'll try the workaround tonight.
Workaround seems to work. Sometimes the solutions can be so simple... :)
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.
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
Also looking for a solution to this, any progress on this since last year?
+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. :(
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.