-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot translate the values of "Custom Product Attributes" of "Variable Product" in Woocommerce #277
Comments
I have not tried to reproduce, but my guess would be that the problem is in '|' character. Do you have the problem if you remove it? I remember some fields in Woocommerce may have multiple values separated by '|', so it may interfere. You would have to escape it if needed. Please, let me know if my guess is correct. |
BTW, why do you need to do raw translation? Do you use integrating plugin: https://wordpress.org/plugins/woocommerce-qtranslate-x/ |
@johnclause You are right. The problem is the "|" character. The vertical line that used for the select values. I am not sure how I can escape it. As for the woocommerce-qtranslate-x: When I first installed it, I had the two flags about the section, but changing the language kept the same content for the attributes. Didn't use it for the translation. I tried to update the qtranslate-x from the Github directly from the source code, by uploading the new files from the FTP and since then, the woocommerce-qtranslate-x doesn't work. I cannot see the flags any more. |
Find the HTML code like &#xxxx; for | and try it. Otherwise ask Woo how they designed it.
You probably need to resave all attributes after installing integrating plugin on a developed site, I recall something like this.
Just install everything nicely, properly and freshly. People report that it all actually works well enough. It does a few things that unachievable with simple raw translations, sending emails in the language of order, for example. I am closing this issue for now, we can still write into a closed issue, or we can re-open it, if needed. |
I removed them all and installed from the start. Now, the flags are back there, but even if I save the attributes and update the page, the content changed for both the languages. :( Edit: Plus, when I use the escaped code, after the update, they turned to "|" again. |
Cannot you use different characters instead of '|'? Or then you have to dig out the place in the code and see how easy it would be to adjust it. Ask Woo what do they suggest? This problem is unrelated to qtx. |
I think that that problem of the character "|" is a side issue and not the main one. The main issue that it is related with qtx is that the flags on Product Data table don't work. You change flags, make changes on product data, save both attributes and page and it changes it for both languages. There was also another issue about it, so I am not alone on this. And just show that the same happened on the Yoast SEO table. Even if I have enabled the Yoast & qtranslate X plugin. I can move between the two flags, but the content doesn't change at all. |
Maybe those fields are not multilingual and need integration? Do they have a color bar on the left side like other multilingual fields do? Please provide step-by-step instructions how to reproduce the problem, preferably under a publicly available theme like "Storefront" and the minimum number of active plugins. For example, you mentioned "value of attributes", but I do not know which admin or front page do you refer to, etc. If there is a similar issue, please, cite it here with a link. Do you have any errors in Java Console, which can be opened with Ctrl+Shift+J? Errors in error_log? Have you done the initial troubleshooting: https://qtranslatexteam.wordpress.com/troubleshooting/? What did you find out? |
Install the qTranslate-X either from Wordpress directly or from Github. Download Yoast and Woocommerce support from Github is the Wordpress has an older version. Install them on admin. The latest version of Yoast SEO & qTranslate add the colors on the inputs and makes them translatable. The one from Wordpress admin, doesn't. But as you can see on the product data table, there isn't a flag and the inputs that I am referring as attributes with labels and values don't have a translatable color. Nothing weird on the Dev Console. |
Indeed, there is a bug in the latest qtx, otherwise front end should work well. Custom Variable products were never integrated yet, but raw values like yours should work. Maybe it is more logical to have it like "[:en]Renting[:de]Anmietung[:] | [:en]Return[:de]Ruckgabe[:]", or it may not be important, I am not sure. The latter should work by design, the original version might work by accident. Anyway, I will update plugin "Woo&qtx" shortly to fix the problems. |
That's great! Please, let me know so I can test any side effects and possible fixes or bugs. Thank you :) |
I updated plugin https://github.com/qTranslate-Team/woocommerce-qtranslate-x at GitHub. Could you please test it? Update qTranslate-X to the latest 3.4.6.1 too. Please, read section "Known Issues" before testing, in order not to report what is already known. "Custom Product Variations", which was your original trouble, has never been finished. Woocommerce has done it in an unexpected way, so it is unclear how to integrate that piece, but raw format should work. Although, most people use "Product Attributes" instead, which work more stable. |
It seems that it works like a charm. I did almost a few general tests. I will do more in the week. If you want, we can close the issue and in case I find a related bug, I can open it again :) |
I will probably release it now shortly for everyone. Thank you, @ventouris, very much for all your help. |
@johnclause Hi John, I've implemented the solution you've explained here some months ago, but it doesn't work for me I've put this on custom product value filed: |
@AleCss81: I think your message is not finished, is it? |
@johnclause hi John, the message were been truncated, I don't know why. Maybe, my code was deleted automatically by editor bacause I haven't used the correct tool to insert code. Now, I was saying that I've put this code on custom product value: but it doesn't work. The selection element not show any variations. You can see the result here: http://hugsfactory.com/product/nursery-sack/ Can you help me? Thank you very much |
@AleCss81: I cannot reproduce what you describe. It works for me. Try to delete the attributes and re-create them? Contact us if you wish to give us admin access. |
@johnclause Hi John, is it working on this page http://hugsfactory.com/product/nursery-sack/? As you can see in the screenshot, it doesn't work! At least for me, in all browsers. Apart from that, I have used the "contact us" form providing the admin access as you have suggested. Thank you very much, I wait for a response. |
Hi, I had the same problem as AleCss81. It took me crazy for days and the solution above didn't work for me neither. I found out that some translations __() were not correct in class WC_Product_Variable method get_variation_attributes(), so that the result variation array was always empty. I derived an own class My_WC_Product_Variable and changed the code in get_variation_attributes(). Maybe it was not the cleanest way but it worked for me. Regards, |
@johnclause yes, it could be useful! @dieSuse effectively, I don't understand what you have implemented, can you explain what to do? Many thanks |
Hi all, I confess I do not remember in detail but here is my class: has_child() ) { return $variation_attributes; } $attributes = $this->get_attributes(); foreach ( $attributes as $attribute ) { if ( ! $attribute['is_variation'] ) { continue; } $values = array(); $attribute_field_name = 'attribute_' . sanitize_title( $attribute['name'] ); // Get used values from children variations foreach ( $this->get_children() as $child_id ) { $variation = $this->get_child( $child_id ); if ( ! empty( $variation->variation_id ) ) { if ( ! $variation->variation_is_visible() ) { continue; // Disabled or hidden } $child_variation_attributes = $variation->get_variation_attributes(); if ( isset( $child_variation_attributes[ $attribute_field_name ] ) ) { $values[] = __($child_variation_attributes[ $attribute_field_name ]); } } } // empty value indicates that all options for given attribute are available if ( in_array( '', $values ) ) { $values = $attribute['is_taxonomy'] ? wp_get_post_terms( $this->id, $attribute['name'], array( 'fields' => 'slugs' ) ) : wc_get_text_attributes( $attribute['value'] ); // Get custom attributes (non taxonomy) as defined } elseif ( ! $attribute['is_taxonomy'] ) { $text_attributes = wc_get_text_attributes( $attribute['value'] ); $assigned_text_attributes = $values; $values = array(); // translation $i=0; foreach ($text_attributes as $attr) { $text_attributes[$i] = __($attr); $i++; } // Pre 2.4 handling where 'slugs' were saved instead of the full text attribute if ( version_compare( get_post_meta( $this->id, '_product_version', true ), '2.4.0', '<' ) ) { $assigned_text_attributes = array_map( 'sanitize_title', $assigned_text_attributes ); foreach ( $text_attributes as $text_attribute ) { if ( in_array( sanitize_title( $text_attribute ), $assigned_text_attributes ) ) { $values[] = $text_attribute; } } } else { foreach ( $text_attributes as $text_attribute ) { if ( in_array( $text_attribute, $assigned_text_attributes ) ) { $values[] = $text_attribute; } } } } $variation_attributes[ $attribute['name'] ] = array_unique( $values ); } return $variation_attributes; } ``` } If I remember correctly I found out, that the comparison in line 73/74 has no compliances, so I started at this point. I'm not sure if there was one element translated and the other not or if it was just a thing of upper and lower case... In line 39 I added the translation for the attributes of array $values. And I inserted lines 56-60 and did the translation for each element of array $text_attributes. I think that were the 2 places, where I changed the code. I'm using WooCommerce 2.5.5 and WooCommerce & qTranslate-X 1.3. Regards, Suse |
So, to be precise, one can modify file /wp-content/plugins/woocommerce/includes/class-wc-product-variable.php to achieve the same result. Line 406
should be replaced with
which adds translation of the Then, at line 419, after lines
inserted a translation of
@AleCss81, could you try that and see if your problem goes away? This would give your temporary fix until we find a permanent solution. |
@AleCss81: I simply followed my own instructions and it worked. I am not sure what step did you miss. I removed an attribute, saved product, added attribute with only two languages enabled, saved product, then re-save variations (do not need to delete them), and the drop down appeared. The problem is that you cannot edit attribute name after it is created once. You may edit values and variations as you pleased, but not the attribute name. If you need to change attribute name, then do as above, delete attribute, save product, add attribute again, save product, re-save variations. Also, do not forget to put [:] at the end, and use [:] consistently, do not mix it with {:}, as you had it. I hope you will be fine from now on. |
Hi @johnclause it works, but if I change the variations to achieve the result expected (i.e White - Grey roses) the dropdown no works anymore. I can't leave "Any" - "Any". Now, it doesn't work anymore also if I leave Any - Any. Don't know why. Do I have to implement the customization on file /class-wc-product-variable.php you have exlpained above? Thanks |
Wow, I did not try that. I did not try @dieSuse 's fix either. Yes, please, try their fix, and I meanwhile will try to work on the issue with complex variations. |
Yeah, it works like a charm. Thanks @dieSuse and @johnclause for this excellent support. |
BTW, @AleCss81, do you wish to update the wp and all plugins to the latest versions? |
@dieSuse: where do you put your customized class, so that it does not get overwritten by the next Woo update? I am meanwhile looking into a simpler solution and thinking about using filter 'trim', applied inside of wc_get_text_attributes to achieve translation at line 419. BTW, at line 406, in my testing, $values come already translated. Is it a case in your setup with the latest of all? |
Hi, yes, you are right: $values is already translated. I don't know anymore, why I used the translation method again. Maybe it was not in an earlier version? I did the stuff in January. In my case, I wanted to have the variations on product overview already, because I don't have a single product page. Therefore I had to insert some code snippets in my functions.php where I get the variations from the product. This is where I use my class My_WC_Product_Variable directly by creating a new product with $product as parameter in the constructor.
If you have a fix, I'd like to use it as well. So just let me know. Regards, |
I don't know why, but the code is only displayed in a line when using ``. |
Use ``` or press "<>" in the toolbar above the message ;) |
Hi, Could you both test the new version of the plugin: https://github.com/qTranslate-Team/woocommerce-qtranslate-x/archive/master.zip The changes can be seen at qTranslate-Team/woocommerce-qtranslate-x@55429ca Please, test the whole process including checkout and e-mails. Can you find something wrong? Do not switch language at front end during one testing session: https://qtranslatexteam.wordpress.com/woocommerce-qtranslate-x-faq/#MiniCartCached |
@johnclause this afternoon I will backup site and update wp and your plugin. I will not update some other plugins because I have made some customization on my own, but it's possible that the vendor changes classes names (it's already happened) and then I have to reproduce all my cutomization. |
Yes, in such case I keep a list of all my customizations and keep re-applying them on each update until the authors put them permanently in the code. It does not take too long, since it usually not too many. How many do you have? I never customize WP code, not worth of messing up with it. There is a child theme framework where I can usually do all I want. |
Yes, I use a child theme. The problem is with some plugins that changes their IDs and classes on every update. Even I keep a list of my customizations, I have to recollocate the new elements with different classes and IDs and re-apply the modifications. It's not a good job nor so quick. With WP core no customzation at all ;) |
@dieSuse: I hope you would be able to test too? If all ok, I would release it then. |
@johnclause: I just tried. It works fine. (Regarding displaying the code: pressing "<>" inserts only ``. I didn't know, that I have to use it three times. Is that intend?) |
Are we ready to release this version? Any problems? |
Tried the version but still variations doesn't show if they are surrounded by [:en]Blue[:fr]Blu[:] for example :( |
I made it work to change few lines for Version 2.6.4 |
I made all changes described on this page, but none of them works for me except ajitbhandari's solution, besides it doesn't works on 1.3 only on 1.4. what am I interesting is that will not be the class-wc-product-variable.php overwritten after woocommerce updates? as I know it will be. so is there maybe any other solution? |
Hi John, awesome plugin! I have the following setup: Everything works fine except for "component short product description" which cannot translate even through manual integration. There is a blue line displaying on the left though, and this field translates fine for variable and simple products but not when the product is used as a component in WC composite products. There, the field "short description" remains under this format: [eng]...[:], [fr]....[:] I have spent hours trying to figure out a way, either by adding new classes, ids or filters to manual integration but none of it has worked so far...this field just won't translate Do you have any idea how to fix it? Many thanks for your help! Best regards |
@KVNHNF contact me on skype ajit.bhandari4 and show your problem ill try to guide you thanks |
I have a hack done with javascript that works pretty good. if you guys want it, send me an email: louismonteiro@gmail.com |
Hello guys , any update for this issue with for the last woocommerce version ?! or you did not update woocommerce yet !? |
For WooCommerce 3.x you still need to change the class-wc-product-variable.php but on line 207 for function get_variation_attributes() to return __($this->variation_attributes);. I will try to submit this to github. This is my first time doing a bug report submission fix. |
Got this as a reply: Seems like it could be still be fix on another class then where the array is assembled to translate each value there. See if anyone else wants to pitch in to find it. |
Found another safer/more working solution and have suggested another fix: |
Another thing to note is that when you load a product page and click the select drop down, the variations are actually listed for a split second, then it disappears. I'm assuming some form of ajax call is the culprit. If you view the source code for the select drop down, it's showing as well. |
Still existing in latest build even with woocommerce modules. Using the woocommerce module yields this other error:
Disabling it allows for single language attribute values to work again. Note that it also breaks WooCommerce REST API. With the modules activated, attribute names can be updated but not values |
I installed the latest version of both qtranslate-x and Woocommerce for qtranslate-x. However, I cannot translate the values of the attributes in Woocommerce. I use the following for the label:
[:en]Action[:de]Vorgang[:]
and this one for the values:
[:en]Renting | Return[:de]Anmietung | Rückgabe[:]
The label works like a charm :) The values doesn't work. I don't have any error on the console.
The HTML result is this one:
<select id="vorgang" class="" name="attribute_vorgang" data-attribute_name="attribute_vorgang"><option value="">Choose an option</option><option value="[:en]Renting" class="attached enabled">Renting</option><option value="Return[:de]Anmietung" class="attached enabled">(DE) ReturnAnmietung</option><option value="Rückgabe[:]" class="attached enabled"></option></select>
The text was updated successfully, but these errors were encountered: